harriyott.com

Wednesday, February 27, 2008

Tip - using units of measure

When naming a variable or database column that is used to store a measure, include the units of measure in the name. For example, instead of calling a column Height, call it HeightInInches. This prevents misunderstandings in future maintenance.

2 Comments:

Blogger David Arno said...

There is no correct answer as to how to name unit variables.

If you use the name height, then confusion over units can indeed occur.

If however you use heightInInches, then maintenance becomes tough if future requirements mean switching to cm or furlongs, as the name must be changed, or conversion routines must be wrapped around all reads and writes to the value.

March 27, 2008 12:24 PM  
Anonymous Simon said...

True, although these concerns would still occur if the column was named "height". This way, at least the maintenance coder knows what their dealing with.

I don't think conversion is a big deal though. I'm sure we all do it regularly with storing and retrieving dates and times. I can't think of a better way of doing it than putting the unit in the name.

March 27, 2008 12:40 PM  

Post a Comment

Links to this post:

Create a Link

<< Home