Re: Underscores in Python numbers



On Sat, 19 Nov 2005 13:08:57 -0500, Peter Hansen wrote:

> Umm... in other words, "the underscore is under-used so let's assign
> some arbitrary meaning to it" (to make the language more like Perl
> perhaps?).

+1

I *really* don't like the idea of allowing underscores in numeric
literals. Firstly, for aesthetic reasons: I think 123_456 is seriously
ugly. Secondly, for pragmatic reasons, I think it is too easy to mistype
as 123-456. I know that Python can't protect you from typing 9-1 instead
of 901, but why add special syntax that makes that sort of error MORE
common?)

> Or maybe one should instead interpret this as "numeric literals need
> more bells and whistles, and I don't care which of these two we add, but
> we have to do *something*!". :-)

-1

That's a tad unfair. Dealing with numeric literals with lots of digits is
a real (if not earth-shattering) human interface problem: it is hard for
people to parse long numeric strings. In the wider world outside of IT,
people deal with long numeric digits by grouping. This is *exceedingly*
common: mathematicians do it, economists do it, everybody who handles long
numeric literals does it *except* computer language designers.

Depending on personal preference and context, we use any of comma, period,
dash or space as a separator. Underscore is never used. Of these, the
comma clashes with tuples, the period opens a rather large can of worms
vis-a-vis internationalisation, and the dash clashes with the minus sign.
Allowing spaces to group digits is subtle but effective, doesn't clash
with other syntax, and is analogous to string concatenation.

I don't believe it is either practical or desirable for a computer
language to accept every conceivable digit separator in literals. If you
need full support for internationalised numbers, that should go into a
function. But the question of including a digit separator for numeric
literals does solve a real problem, it isn't just meaningless bells and
whistles.

Likewise, base conversion into arbitrary bases is not, in my opinion,
common enough a task that support for it needs to be built into the syntax
for literals. If somebody cares enough about it, write a module to handle
it and try to get it included with the Python standard modules.


--
Steven.

.



Relevant Pages

  • Re: Hidden One Instance
    ... sometimes in assembly language. ... are located in the file scope, but they are acting to be old-fashioned ... All global variables and global functions are located in the ... with just one underscore are reserved. ...
    (comp.lang.c)
  • When floating point result intervals span the boundary - what value is selected?
    ... type Sine_Type is digits 6 range -1.0..1.0; ... but it seems the language allows it. ... the smallest possible float can be reduced even more. ... -- I was expecting this to report a model number close to 1.0, ...
    (comp.lang.ada)
  • Re: how do I get more numbers past the decimal?
    ... expansions, print it with 40 digits ... of precision, and see how many digits you get accurately. ... is that PHP is as good as any other language I might use ... versus some other computer language. ...
    (comp.lang.php)
  • Re: Moving text
    ... but what are you searching for? ... followed by 1 or more digits in the range from 0 til 9, ... If you would search for an underscore, ... in the range from 0 til 9, ...
    (microsoft.public.word.vba.beginners)
  • Re: More than 15 digits of precision?
    ... Rexx supports calculations of arbitrary precision. ... If you want 100 digits of accuracy, ... Rexx is the main scripting language for IBM mainframes. ...
    (microsoft.public.excel)

Loading