Strictly typed values?



  •  Is there a framework/language that (can) enforce the 'type' of simple numbers? Ideally at compile time to not affect runtime permormance excessively.

     For example, to calculate the size of a simple room... instead of:

    float x = 7;

    float y = 5;

    float area = x * y;

     

    you would have:


    length x = length.fromfeet(7);

    length y = length.fromfeet(5);

    area result = x * y;

     

    or:

     

    length x = length.fromfeet(7);

    timespan y = timespan.fromseconds(5);

    velocity result = x * y;

     

    Both would compile to basically the same code, but strict type-checking would be applied at compile time (or like with intellisense while you are editing code...) to eliminate any unit-type errors.



  • Is there one? No doubt.

    Is there one suitable for general application development? ... probably not.



  • C++ and Scala spring to mind...



  • From your example code there, it looks as though you're creating your own objects with a specific numerical data type (or precision).

    I'm guessing there's probably some framework you could drop into an OO language that provides classes and methods with measurements to suit engineering or scientific environments.

    I'm sure Java or .NET people could hack a set of libraries together but without further research you could be pursuing a circular rotating movement solution redesign.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.