jack: (Default)
[personal profile] jack
Poll #1872 Variables with units
Open to: Registered Users, detailed results viewable to: All, participants: 11


Which do you prefer:

View Answers

quantity width = 2.0*meters;
0 (0.0%)

int width_m = 2;
4 (36.4%)

int width=2; // meters
9 (81.8%)

int width=2;
3 (27.3%)


Date: 2009-12-10 06:52 pm (UTC)
andrewducker: (Default)
From: [personal profile] andrewducker
Comments are pointless, because (a) nobody reads them and (b) they only exist in one place, not everywhere in the system.

If _all_ measurements are in m through the whole system then you don't need to signpost it at all. If some are in m and some are in ft then you need some kind of notation (hungarian or otherwise) so that someone can instantly tell that:
area_m = height_ft * width_m; is wrong.

You could go for a measurement class that includes the unit, and have the checks happen internally, but that seems awfully heavyweight and potentially slow. On the other hand, unless you're doing an awful lot of computation of your measurements that might not matter.

If you were doing a CAD package then I'd say the first was the best option, for general usage the second one.