[Python-ideas] Improve readability of long numeric literals
Andrew Barnert
abarnert at yahoo.com
Tue Feb 9 20:35:42 EST 2016
One possible objection that nobody's raised:
Separating groups of three is all well and good; to my western eyes, 10_000_000_000 is obviously 10 billion.*
But someone from China is likely to use groups of four, and 100_0000_0000 is not obviously anything--my first thought is around 100 billion, but that can't be right, so I have to count up the digits.
I still think this is a good suggestion, because 100000000000 is even more useless to me as 100_0000_0000, and far more likely to be concealing a typo. I just wanted to make sure everyone knew the issue.
* If you're going to say "no, it's a milliard, you stupid American", go back to the early 70s, and bring your non-decimal currency with you. It's billion in English, and has been for 40+ years. Leave the fighting to the languages where it's ambiguous, like Portuguese or Finnish.
Sent from my iPhone
> On Feb 9, 2016, at 13:40, Manuel CerĂ³n <ceronman at gmail.com> wrote:
>
> Hi everyone!
>
> 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
>
> Which helps to quickly identify that this is around 67 million.
>
> Another option is to use spaces instead of underscores:
>
> >>> opts.write_buffer_size = 67 108 864
>
> This has two advantages: 1. is analog to the way string literals work, which are concatenated if put next to each other. 2. spaces are already used as thousands separator in many european languages [1].
>
> The disadvantage is that, as far as I known, no other languages do this.
>
> 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.
>
> Thoughts?
>
> Manuel.
>
> [1] https://docs.oracle.com/cd/E19455-01/806-0169/overview-9/index.html
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160209/e17a8046/attachment.html>
More information about the Python-ideas
mailing list