Imagine you're writing a bit of computer
code and you have tell pause for a
second.
Now, is it pause(1) or pause(1000) --
should
the the parameter be in seconds or
milliseconds?

What if you could put a unit in there so
pause(1s) and pause(1000ms) are
equivalent.
Not a big idea, and
not that exciting, but
maybe something that
would stop the odd bug from creeping
into
your code.

I can see where this is useful for time, but
what other variables would it apply to?
Obviously, you may want to distinguish
volts and millivolts, or atmospheres and
pascals, but these aren't really the same in
programming terms as
milliseconds/seconds. However, [+] for
the idea.

I think this would lead to less errors as you would be forced to define your quantities. Even if there was only one unit (eg milliseconds) - being forced to suffix your time variable with ms would remind you what you were working with.

If you have a variable 'q' in a strongly typed language then 'q' already has a type - either seconds or milliseconds or something else, but its unit is not ambiguous. So I don't think pause(q) is a problem, and pause(qs) is nonsensical whether you interpret it as the nonexistent variable 'qs' or as q seconds.

A problem can potentially occur when you use a literal value directly without checking what the function requires, and when that value could be ambiguous as to the units it's in.

As such, appending a type specifier to a literal number would help avoid problems. You could consider pause(1000ms) shorthand for pause( (time_milliseconds) 1000).

So as long as it only applies to literal values, I think it's a good idea. [+].

Google Calculator does this. By coincidence we were talking about the same thing just last week in the yahoo 'compilers101' group. Shouldn't be hard to do, probably more useful for a calculator than a compiler though.

Dimensional analysis can catch a lot of calculation mistakes, but it's hardly perfect. Learning to rely upon it can be a recipe for disaster since many equations require dimensionless scaling factors (the most common being 0.5, as in s=0.5*g*t*t).

Some time back I sketched out some ideas in this vein in more detail - then I found someone had already implemented something almost identical to what I had designed, which I think means that rather than feeling bad that someone had done it before, I should feel good that someone reinforced my gut feeling that this is the obvious way to go :-) See my link above and please follow it through to Mark Austin's "Alladin" system at umd.edu

Apart from that, it's quite a nice idea to have an interface to the computer that is based on real-world units. Maybe on startup, it could determine the size of your monitor and figure out exactly how long a centimetre is for you - this must be on the cards for future touch displays.

The same goes for seconds (assuming the user and the machine are occupying the same relativistic frame of reference of course)

Several years ago, I wanted to do some programming that dealt with real-world units of measurement, but I didn't want to learn and switch to Frink. I thought of doing something like Hungarian notation [link] where, instead of prefixing a variable's name with an abbreviation for its type or intended usage, you suffix it with the unit symbol. For example: time_s, length_m. Like Hungarian notation, it would be just a naming scheme and communicate nothing to the compiler/interpreter. But (I have just realized) you'd quickly run into an issue with compound units where you need a way to represent exponents and division within the variable name (e.g. acceleration_m/s^2), which would be difficult because most languages don't allow slashes or carets in identifiers.

Anyway, I never got around to doing said programming, so I still haven't tried this system out. But it wouldn't directly solve the problem of what unit to use when passing a numeric value to a function, beyond that the function's parameter could be named in this scheme, and your IDE could then give you a hint of the parameter name when you type the call.

You could implement this sort of thing by defining a type for each unit, and how to automatically cast from one unit to another where they're in the same dimension. I feel like that could be the best simple way to implement it in many popular strongly typed general-purpose languages. But then how do you do something like GramsPerMeterSquared arealDensity = mass / (length * width) where mass is of type Grams and length and width are of type Meters? You could overload the math operators (if the language allows you to), but that would be cumbersome to do for every combination of units you could do math with, not to mention you have to make a type for every possible resulting compound unit. So maybe that's worse than my first idea.

Meh. I program quite a lot (in a very enthusiastic but amateur
way), and I'd sooner just have a clear understanding of the
numbers, rather than assigning units.

What I _would_ like, though, is better handling of 1-starting
and 0-starting numbering. I do a lot of DNA-related software,
and DNA sequences conventionally start from 1. This means
that, for instance, if I want to use a modulo function to split a
sequence into 100-base lines, I have to go from 1-starting to
0-starting, do the moduloing, then convert back to 1-starting.

True, are irrational, transcendental or even imaginary numbers of unit count?

I suppose it comes down to what it fundamentally means to count and the dimension it is done on. The imaginary having a complex of counting dimensions and the irrational and transcendental having such blurry plots that they need indexing labels on the ordinary counting dimension.

All three are counted on and with so yes but with the dimension of counting either viewed with pin-pointer names or split into partial components.

Nearly all numbers are a count (some are just labels) so must rest on some sort of counting dimension line.

As the tagline says, I can read that, but I'm not following too closely.

"Count" does make sense to me, though, for things like frequency (where 1 hertz = 1 occurrence/second, but more commonly considered "1 /second") and wavenumber (in waves/millimeter, but again more commonly just "/millimeter").

At some level, I think NOIR classification would be
a good addition to programming
language type definitions. We think Integers are
for counting, and Floats are for
continuous measures, but this isn't always good
enough. NOIR stands for Nominal,
Ordinal,
Immnngng..somthething, and Ratio - and describes
the different uses a number might have
-
Nominal, for group-naming, Ordinal for placing into
some kind of rank/order,
Interval(just remembered!) is usage for your
traditional counting situation, and Ratio
is
for continuous ranges of data. You can do different
kinds of stats on Ratios, Intervals
and Ordinals depending, and normally you can only
label things with Nominal data. So
this
is less a data-typing based on the internal digital
representation (which is what float,
integer, byte etc give you) and more a data-typing
based on how you intend on using the
information.

Once you've NOIRed your information, it's a trivial
exercise* to assign/map appropriate
units - or even to auto-translate across unit types
- allowing someone to calculate fuel
efficiency in litres per furlong, by supplying fuel
consumed in metric ounces and distance in
terms of light-picoseconds.

*by which I mean, bloody difficult in practice - but Wolfram Alpha/Mathematica does
pretty good job - see link.

I mostly just name functions and variables to include critical units, but a third opportunity for world type safety comes to mind - reflection. Languages like C# have the ability to figure out what the ASCII name of variables and functions are, so when running in a debug mode, a program could kludge a safety check my making sure the function name and parameter variables match e.g. minutes = GetMilliseconds() is a runtime error under aggressive kludge debug.

You could write a library to do that. But would it know to not throw an error on, e.g., minutes = getMilliseconds() / 60000? My first thought was to go full dimensional analysis and somehow give the divisor a unit of milliseconds/minute, but how do you do that with a literal in your reflection-based scheme, because it doesn't have a name?