Cam*_*une 7 c c++ physics coding-style units-of-measurement
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:
最终,重要的是选择一种风格并坚持下去。
如果我要实现这个,我可能会从 SI 缩写开始:
int distance_m; // meters
Run Code Online (Sandbox Code Playgroud)
对于指数,将指数附加到单位:
int area_m2; // square meters
Run Code Online (Sandbox Code Playgroud)
对于产品,用下划线分隔:
int torque_N_m; // Newton-meters
Run Code Online (Sandbox Code Playgroud)
(此处资本的使用N可能是好主意,也可能不是好主意;保持一致)
对于商,写per:
int velocity_m_per_s; // meters per second
Run Code Online (Sandbox Code Playgroud)
每个变量应该只需要一个per。假设它的优先级低于乘法。
当然,以上只是一个建议;您应该修改它以满足您的需要。只要确保整个开发团队都同意这些规则即可。
| 归档时间: |
|
| 查看次数: |
1930 次 |
| 最近记录: |