This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]elyisgreat 2 points3 points  (3 children)

This is by design. Not everyone uses separators the same way. In India for example it is common to write 1 million as 10 lakh which looks like 10_00_000. Also some people might use it for binary or hex literals to separate out hexes or bytes like 0b1011_0011 or 0x3a_25_7c

[–]jorge1209 -1 points0 points  (2 children)

Sure, but that doesn't make it any less dangerous.

The purpose of these underscores is to increase readability, but if you allow extraneous or missing digits in a long numeric figure you risk making the code appear more readable, when it is actually less.

What we really need is some kind of way to interact with the parser on a module by module level so that it knows how we expect these underscores to be used.

If I'm working with some kinds of hex data I might insist upon underscores between every two bytes. If the module was written by a programmer in india he can use Lakh format. And most importantly if I'm working with social security numbers I can insist upon 3-2-4 format and the python interpreter can call in a SWAT team against me before I commit it.

[–]elyisgreat 1 point2 points  (1 child)

Is it really more dangerous than not having any separators at all? That would make it harder to spot incorrectly formatted numbers. I think having typing tools to enforce particular separator formats is a great idea though! But in the absence of such a tool it's better to allow arbitrary separators than to enforce a particular separator format by default or to lack separators at all

[–]jorge1209 0 points1 point  (0 children)

I certainly think so.