Re: Underscores in Python numbers



Steven D'Aprano <steve@xxxxxxxxxxxxxxxxxxxxxx> writes:
> 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?)

I've seen at least one language (forget which one) that allowed such
separators, but only for groups of three. So 123_456 would be valid,
but 9_1 would be a syntax error. This kind of thing might help with
the detecting typos issue, and probably won't be noticed by most
users.

<mike
--
Mike Meyer <mwm@xxxxxxxxx> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
.



Relevant Pages

  • Re: Function to compares two arrays and returns indices where they are equivalent
    ... Running the code is like compiling the ... But if you have syntax error, ... in any language, even Fortran. ... language, if all things being equal, but they are not, for me. ...
    (comp.lang.fortran)
  • Re: Renaissance of Forth
    ... desire to treat C as a portable assembly language. ... Nobody needs to have an actual interpreter or compiler for this ... a special type for strings, or add an extension to C's grammar. ... But that's a syntax error to C. So maybe we ugly it up a bit: ...
    (comp.lang.forth)
  • Re: need help..
    ... >>> It should be a syntax error. ... an assignment is an expression ... in the context of a new language. ... CLC FAQ ...
    (comp.lang.c)
  • Re: Extentions to BASIC
    ... There's a blast from the past. ... This language, developed at the Hanover College for Technical ... Misfits, was designed to make it impossible to write code with errors in it. ... you can't make a syntax error. ...
    (sci.electronics.design)
  • Re: Function to compares two arrays and returns indices where they are equivalent
    ... Matlab searches for a file called "foo.m". ... But if you have syntax error, ... in any language, even Fortran. ... I don't care if the problem is that the language syntax is too loose to catch errors, ...
    (comp.lang.fortran)