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:
- plural or not (lbs, lb)
- capital or not (Lb, lb)
- reciprocals (PerSec, pSec, SecInv)
- superscripts like cubed or inverse squared
Ultimately, what's important is picking a style and sticking with it.
If I were implementing this, I'd probably start with SI abbreviations:
For exponents, append the exponent to the unit:
For products, split with an underscore:
(the use of capital
N
here may or may not be a good idea; be consistent)For quotients, write
per
: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.