What should I name a variable that has units with a fixed point?
int herpLimitLo_psig2 = 6000; // 60.00 psig int derpLimitLoPsigwithtwodigits; int herpLimitHiPsigfixedtwo; int herpLimitHi_psig_timesOneHundred;
Apparently I suck at naming things.
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.
Variable names are expensive; you can't make them too long or your code will be unreadable (after all, excessive repetition of excessively redundant information excessively causes excessive exceeding of the human brain's excessiveness processing systems if used excessively), but you do want them to be as descriptive as possible. This means that you should name them after their meaning; things like expected value range or value semantics can be expressed through other language features in almost every programming language.
For example, in C, you can use
Some languages will even refuse to compile your code if you do stupid things like trying to directly assign a
what about naming the variable according to its meaning in the current context? You should avoid naming variables after their type.
The only important information you should be able to retrieve easily is the interpretation factor. In most cases, there will be only one, so you can define a constant and use it everywhere you need it (and avoid putting it in the variable names).
If you are using a lot of different precisions in your computations, you should use a specific type for fixed point computations.
At least in debug mode, this type should be able to give you the precision of a given variable, and prevent you to do stuff like adding two numbers with different precisions (at least in debug mode). And so you are also free to give your variable a short meaningful name.
example in python: