Are there any Hungarian-in-spirit style guides for appending (SI or Imperial) units to variable names for physics-intensive C/C++? I'd expected that this wheel had already been invented, but online I found only simple examples like duration_sec
and length_ft
. (No boost, please.) (Roughly related: naming of physical quantities in python .)
Typeset prose has a good style guide, but its superscripts, slashes and italics fail in programming languages.
I'd even be happy with arguments resolving particular issues that arise with compound units like spectral radiance, moment, torque, or energy:
Ultimately, what's important is picking a style and sticking with it.
If I were implementing this, I'd probably start with SI abbreviations:
int distance_m; // meters
For exponents, append the exponent to the unit:
int area_m2; // square meters
For products, split with an underscore:
int torque_N_m; // Newton-meters
(the use of capital N
here may or may not be a good idea; be consistent)
For quotients, write per
:
int velocity_m_per_s; // meters per second
You should only need one per
per variable. Assume it has a lower precedence than multiplication.
The above is just a suggestion, of course; you should modify it to suit your needs. Just make sure the whole development team agrees on the rules.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With