[Python-Dev] PEP 515: Underscores in Numeric Literals (original) (raw)

Steven D'Aprano steve at pearwood.info
Thu Feb 11 18:01:03 EST 2016


On Thu, Feb 11, 2016 at 08:50:09PM +0200, Serhiy Storchaka wrote:

I have strong preference for more strict and simpler rule, used by most other languages -- "only between two digits". Main arguments:

1. Simple rule is easier to understand, remember and recognize. I care not about the complexity of the implementation (there is no large difference), but about cognitive complexity. 2. Most languages use this rule. It is better to follow non-formal standard that invent the rule that differs from rules in every other language. This will help programmers that use multiple languages. I have provided an alternative patch and can provide an alternative PEP if it is needed.

I don't think an alternative PEP is needed, but I hope that your alternative gets a fair treatment in the PEP.

>The production list for integer literals would therefore look like this:: > > integer: decimalinteger | octinteger | hexinteger | bininteger > decimalinteger: nonzerodigit (digit | "")* | "0" ("0" | "")* > nonzerodigit: "1"..."9" > digit: "0"..."9" > octinteger: "0" ("o" | "O") ""* octdigit (octdigit | "")*

octinteger: "0" ("o" | "O") octdigit ([""] octdigit)* > hexinteger: "0" ("x" | "X") ""* hexdigit (hexdigit | "")* hexinteger: "0" ("x" | "X") hexdigit ([""] hexdigit)* > bininteger: "0" ("b" | "B") ""* bindigit (bindigit | "")* bininteger: "0" ("b" | "B") bindigit ([""] bindigit)*

To me, Serhiy's versions (starting with single > symbols) are not only simpler to learn, but have a simpler (or at least shorter) implementation too.

[...]

>Group 3: only between digits, only one underscore > >* Ada [8] >* Julia (but not in the exponent part of floats) [9] >* Ruby (docs say "anywhere", in reality only between digits) [10]

This classification is misleading. The difference between groups 2 and 3 is less then between different languages in group 1. To be fair, groups 2 and 3 should be united in one group. C++ should be included in this group. Perl 5 and Swift should be either included in both groups or excluded from any group, because they have inconsistencies between the documentation and the implementation or between different parts of the documentation. With correct classification it is obvious what variant is the most popular.

It is not obvious to me what you think the correct classification is.

If you disagree with Georg's classification, would you reclassify the languages, and if there is agreement that you are correct, he can update the PEP?

-- Steve



More information about the Python-Dev mailing list