ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

What Every Computer Scientist Should Know About Units of Measurement

(1/1)

rkarman:
While developing some code at work i decided to write a class called Unit that would handle all translations between units of measurement. from seconds to minutes, meters to kilometers, bytes to bits, etc. a nobel task to ease the burdon of other developers in the team and to reduce errors in their code. so i started and made my class, and after finishing it i debugged it of course :)

now, end of story right ...    nope!!!


after writing a pricing engine for a new satallite system i found out it was impossible to use my class and get correct results! i kept debugging and debugging, and after having debugged the unit class several times i decided to take a real close look at it and super debug it once more.

so now we have the end of the story right?   ... nope...

yet again the super debugged unit class was giving trouble and it took me a whole night of stepping and debugging to realize something trivial. units word really odd! there are units that translate as follows:

1 minute = 60 seconds (this makes the factor 60 and we need to multiply to get from minutes to seconds)

then we also have:
60 calls per minute = 1 call per second (this makes again the factor 60, but instead of multiplying to get from minutes to seconds we need to divide this time!)

it turned out that all my troubles came from forgetting that unit per unit translates diffrent then a unit by itself!


the moral: you can make a reusable class for "Units of Measurement" and to translate them into eachother, but don't forget that there are 2 types of translations!

housetier:
My physics teacher tought me to do these types of translations seperately: First figure out the units, and totally disregard the numbers. Then "do the math" without any units.  :huh:

After you have the result, triple checked you used the correct units, and moreover the correct magnitudes of the units. It seems like more work, but I found it very easy. It's variation of the principle of KISS (keep it simple, stupid), conveniently also called KISS (keep it seperate, student).  :D :P

Navigation

[0] Message Index

Go to full version