Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Distance in meters, Distance in feet

That brings up an interesting issue -- is the "right way" to do that to have different types for these, or one type for distance with different factory function/methods for different units. E.g.: should "meters" and "feet" be different types, or should the "measurement" module have both a "meters" and "feet" method that return the same ("distance") type.

It seems to me the latter is more conceptually clean.

OTOH, math might be easier to express with the former (particularly in a language that allows you to define implicit type conversions, so that if you pass an "inch" value to a function expecting a "cm" parameter, it gets automatically converted to the appropriate "cm" value.)



Well, there are really three different kinds of information involved. For example, the variable "target_resist" might have: Computational type (float), Dimension (resistance), and Unit (milliohms).

Most built-in type-systems (sensibly!) only try to tackle the broadly-applicable computational-type, since the rest is context-specific.

However, in a contractual sense, all of those are important, if any are not as expected, you'll get bugs.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: