3 ms·
UnitInterval is the type. The name of the value should reflect its specific use.
by infradig 6y ago
UnitInterval is the type. The name of the value should reflect its specific use.
- kelnos 6y agoExactly. The best usage for this would be something like: typedef float UnitInterval; void do_something_accurately(UnitInterval accuracy);
- Tainnor 6y agoThis is the correct answer IMHO. (The variable name could also be "proportion" or "probability" depending on context, and the type name could more precisely be ClosedUnitInterval, but the idea of putting it in the type is IMHO correct.) I don't know much about C (? I assume that's what this is), but in other languages you can even build a wrapper type and enforce invariants in construction if really necessary. Of course, all that ceremony only makes sense if this is really a type you use multiple times. Otherwise I wouldn't bother.
- nicky0 6y agoClosedUnitInterval surely describes the interval itself, not a member of that interval. The member would be ClosedUnitIntervalValue or something. This is the thing it would be nice to have a short name for. Just as we say an integer is a member of the set called the integers. We say our "X" (the word we are looking for) is a member of the set called the closed unit interval.
- throwaway287391 6y agoIt's still not really "correct" IMO, I think it needs to be "UnitIntervalValue" as someone said above. I'd expect that things of type "UnitInterval" would be intervals, not values. "UnitInterval" would be like calling the type "Int32Range" instead of "Int32". (NB: "In real life" I would never "correct" someone for calling it "UnitInterval", it's good enough -- but given this is a pure discussion of semantics...)
- kelnos 6y agoSure, that's fair. I was more talking about it being better to name the type a particular thing, rather than encoding the type in the variable name.
- nicky0 6y agotypedef float UnitIntervalValue; void do_something_accurately(UnitIntervalValue accuracy); FTFY
- nicky0 6y agoUnitInterval isn't a type, it's a value of type Range, specifically the range [0,1]. UnitIntervalValue would be the type name for the thing we are interested in. Values of that type should of course have descriptive names.