On lots of today's generic programming languages, we have a really simplified concept of 'units':
double foo = 10.5d
float bar = 10.5f
long fubar = 10L
These were added to these languages to disambiguate typing when defining constants, but Boo also added a very interesting type directly to the syntax, TimeSpans:
Thread.Sleep(50ms)
This wish is for a more generic way of defining these 'units'. Today, Boo has miliseconds, seconds, minutes, hours, days, weeks
, months
and years
, but that is only the beginning. Things start to get really interesting if it's possible to do this directly at the programming level:
distance = 100m * 3in // meters and inches
position = (142px, 183px) // pixels
amount = 100.0USD + 1.50GBP // dollars and pounds
capacity = 2cm3 + 4l + 2g // cubic centimeters, liters, gallons
binary = 01010101110b // binary
This could be implemented by generalizing the rules in the Antlr grammar so that every number constant is defined with an optional unit. Operators should take units into account, and be able to convert them (or throw something like an IncompatibleUnitException).
It should be possible to define new units, and, to avoid name clashes (m for meters and minutes, for example), there should be a way to import them.
myChar = "a"c
and even unicode stuff (don't know if this applies to the CLR):
myUnicodeChar = "a"u
anotherUnicodeChar = 0x0009u