Atlas · Details
The Numbers Mini-Language
Author’s note
This one of my very oldest posts: a fun walk through a bunch of stuff you just don't need to know anymore. It turns out representing numbers in programs is quite complicated and fiddly, and different programming languages give you varying levels of expressiveness and risk. But it's mostly a curiosity at this point, unless you are doing high-performance systems programming.
AI Notes
Steve picks the smallest possible corner of language design — how do
you write a number? — and lays six languages side by side on scientific
notation, underscores, hex, binary, complex numbers, and
arbitrary-precision integers. The variation is wider than working
programmers tend to realise. Perl's underscore-evaporation rules are
deliberately perverse (2_____.____0___5__________ equals
2.05). C, C++ and Java have no binary literals at all and no
grouping separator. Python, Ruby, Common Lisp and Scheme auto-promote
through a numeric tower so overflow is a non-issue. Java's BigInteger
is so hostile its constructor takes a signum and a big-endian byte
array. Then the survey becomes an argument: a
language that ships with easy fixnums and painful bignums has, whether
or not anyone notices, shipped a default the working programmer will
follow — and that default is where the integer-overflow bugs come from,
and where a class of security vulnerabilities comes from. The fix is
syntactic: make correctness the easy thing to type,
and let optimisation be opt-in.
Related listings
-
2004
Language Trickery and EJB
Three months earlier. Language Trickery asks 'what deserves its own syntax?'; The Numbers Mini-Language is one answer worked out in detail — numbers do, and the choice is consequential.
-
2004
Tour de Babel
The pan-language tour the numbers essay sits inside. Tour de Babel is the survey of how the major languages compare overall; this is the same survey scoped to one tiny corner.
-
2005
Duck Season
Three months later — the same trade-off-engine view of language design, scaled back up from one corner to the whole equalizer.