Another disadvantage to using spaces is that it could mask an
inadvertently omitted operator that previously would have been a
SyntaxError.
_______________________________________________
Python-ideas mailing list
Python...@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
> Sometimes it's hard to read long numbers. For example:
>
> >>> opts.write_buffer_size = 67108864
>
> Some languages (Ruby, Perl, Swift) allow the use of underscores in
> numeric literals, which are ignored. They are typically used as
> thousands separators. The example above would look like this:
>
> >>> opts.write_buffer_size = 67_108_864
As I recall, a number of years ago we had this discussion and Guido
approved the idea. The only email I could locate at the moment, though,
shows his support of the idea, but not outright approval. [1]
I dare say if somebody submitted a patch it would fare well. (As in: be
accepted, not gone forever.)
--
~Ethan~
[1] https://mail.python.org/pipermail/python-ideas/2011-May/010157.html
--
--Guido van Rossum (python.org/~guido)
On 9 Feb 2016 23:18, "Guido van Rossum" <gu...@python.org> wrote:
>
> Indeed, "123 456" is a no-no, but "123_456" sound good. (Not sure
> about "12_34_56" but there are probably use cases for that too.)
>
It would be useful for hex literals. There are other more confusing possibilities such as 1_._0_e_-_1_0.
--
Oscar
> On Tue, Feb 9, 2016 at 2:40 PM, Manuel Cerón <cero...@gmail.com> wrote:
> > Another option is to use spaces instead of underscores:
> >
> >>>> opts.write_buffer_size = 67 108 864
> >
> > […]
> > The disadvantage is that, as far as I known, no other languages do
> > this.
>
> Another disadvantage to using spaces is that it could mask an
> inadvertently omitted operator that previously would have been a
> SyntaxError.
The exact same fact – that a proposed new syntax was previously a syntax
error – is commonly presented as a positive. We know there are no valid
Python programs already using the construct to mean something else.
So I don't think it's reasonable to present that now as though it were
negative.
(good sigmonster, have a cookie)
--
\ “… correct code is great, code that crashes could use |
`\ improvement, but incorrect code that doesn’t crash is a |
_o__) horrible nightmare.” —Chris Smith, 2008-08-22 |
Ben Finney
I think you misunderstand. The argument (which I agree with) is that
the syntax error was considered beneficial, since it would catch
common typos -- so that we're loath to make that valid code.
--
--Guido van Rossum (python.org/~guido)
I don't know what a bank sort code is (maybe a UK thing?)
FWIW there are some edge cases to be decided: is _123 valid? or 123_?
or 123__456?
>> Another disadvantage to using spaces is that it could mask an
>> inadvertently omitted operator that previously would have been a
>> SyntaxError.
>
> The exact same fact – that a proposed new syntax was previously a
> syntax error – is commonly presented as a positive. We know there are
> no valid Python programs already using the construct to mean
> something else.
>
> So I don't think it's reasonable to present that now as though it were
> negative.
If the SyntaxError is also a common mistake, then suddenly having it be
working, but wrong, code is a bad thing.
> (good sigmonster, have a cookie)
“… correct code is great, code that crashes could use |
improvement, but incorrect code that doesn’t crash is a |
horrible nightmare.” —Chris Smith, 2008-08-22 |
Yes, good sigmonster - "incorrect code that doesn't crash is a horrible
nightmare" -- which is what could happen when a SyntaxError suddenly
becomes syntacticly correct.
--
~Ethan~
_______________________________________________
Yeah, I saw this (in Perl) and I think that it's a good idea.
> Another option is to use spaces instead of underscores:
>
>>>> opts.write_buffer_size = 67 108 864
It sounds error-prone to me. It's common that I forget a comma in a tuple like :
x = (1,
2
3)
I expect a SyntaxError, not x = (1, 23).
It can also occur on a single line: x = (1, 2 3)
> I have seen some old discussions around this, but nothing on this list or a
> PEP. With Python being use more and more for scientific and numeric
> computation, this is a small change that will help with readability a lot.
> And, as far as I can tell, it doesn't break compatibility in any way.
I'm not sure that a PEP is required. We just have to clarify where
underscore are allowed exactly. See the discussion above they are
corner cases on float and complex numbers.
Victor
>> will just print the number 123456. Hence for me as a FORTRAN this
>> would seem a natural thing to do. Better than the underscores ... I
>> would associate the with the LaTeX maths mode index operator, and then
>> I would read 100_002 as the number 4.
>
> No, 100_{002} is the number 4.
Well, as you know, even more strictly speaking, in a LaTeX text you'd have to write $100_{002}$. But in more colloquial use of LaTeX syntax, e.g., in plain text abstracts, the braces are often dropped for the sake of readability. Beside, base 0 or base 1 make little sense.
-Alexander
Sent from my Pixel C.