It is not about "modern" languages at all. Non-decimal integer literals are
a convenience that have been around in many forms for 50+ years.
The heritage of pre-C computers had one (PDP-8) where use of octal made
special sense so the developers of C were comfortable with that and added
special "leading zero means octal" code. When PCC/UNIX moved to the
Interdata 8/32 they wanted hexadecimal and thus "0x" (they may have had hex
before, but big octal constants were popular on the PDP-11 even though it
hex would have been more natural). They never met any other big needs so
BTL stopped there.
In other realms, unifying the idea of flexible radix was a popular topic.
There are a few schools of thought, the prefix camp and the postfix camps
and the radix in decimal and radix coded as a symbol approaches. Manlio
listed a prefix-symbol approach. Another way that I'm fond of is the
'radix' coding scheme:
123 => 123
10r123 => "123" in radix 10 == 123 decimal
16r123 => "123" in radix 16 == 291 decimal
16rFACE => "FACE" in radix 16 == 64206 decimal
I like this because it is regular, does not give leading zeroes magic
meaning, and because it is general for bases 2 through 36.
The language Ada had a nice addition for integer literals, the "don't care"
underscore. The rule is that "_" within numbers is ignored. This means you
can write the literal 16_777_216 for the value of 2**24, using the
underscore for [,.]. I like it much better than a long string of digits. It
did not catch on outside Ada though. Pitty!
Michael
On Wed, Dec 10, 2014 at 5:55 AM, Volker Dobler wrote:Am Mittwoch, 10. Dezember 2014 14:19:27 UTC+1 schrieb Manlio Perillo:
[...]
1) Hex floating point literal.
I have started to use hex float literals in C99 (for unit testing),
and they
seems to be very useful. AFAIK they are only available in very few
languages.
Given that Go literals are of very high precision I am not
convinced this is really helpful.
2) Uniform syntax for integer literals.
Some new programming languages have an uniform and very readable
syntax for integer literals, as an example,
- a decimal number has no prefix
- a binary number has a 0b prefix
- an octal number has an 0o prefix
- an hexadecimal number has a 0x prefix
All except binary literals are already supported and some line has
to be drawn; otherwise someone will demand support for vigesimal
literals because it would be convenient during transcription of
Mayaen calendars.
V.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout. --
*Michael T. Jones | Chief Technology Advocate |
mtj@google.com<
mtj@google.com> | +1 650-335-5765*
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.