Tracy R Reed wrote:
> Gabriel Sechan wrote:
>> Seriously, though.  A variable *always* has a type, wether the
>> language does or not.  The type of a variable is the kind of data it
>> holds.  This is separate from its languae type.  For example, lets
>> say we have to store today's temperature.  Its type is temperature in
>> degree's celsius.  Its language type may be scalar in perl, int in
>> C++, etc.  But its true type is still temperature in degrees
>> celsius.  Having a language that supports typedefs and declarations
>> merely documents that for you, rather than forcing you to read the
>> code to figure it out.
>
> Can you somehow encapsulate units in a type so that when we program a
> completely hypothetical Mars lander it doesn't allow us to
> accidentally mix meters and feet without doing a type conversion?
Yes, actually you can. Sadly Martin Fowler wrote up exactly how to do
this in Analysis Patterns long before the mission, haskell folks do this
kind of stuff in their sleep, and the boost folks have encoded it in
their "units" library. With a statically typed language you can even get
it to produce compile time errors for this kind of fuck up.

--Chris

-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to