Numeric literal syntax

Ben Finney bignose+hates-spam at benfinney.id.au
Tue Sep 2 05:51:16 CEST 2008


bearophileHUGS at lycos.com writes:

> Ben Finney:
> > I don't see any good reason (other than your familiarity with the
> > D language) to use underscores for this purpose, and much more
> > reason (readability, consistency, fewer arbitrary differences in
> > syntax, perhaps simpler implementation) to use whitespace just as
> > with string literals.
> 
> It's not just my familiarity, Ada language too uses underscore for
> that purpose, I think, so there's a precedent, and Ada is a language
> designed to always minimize programming errors, simple code mistakes
> too.

I would argue that the precedent, already within Python, for using a
space to separate pieces of a string literal, is more important than
precedents from other programming languages.

> Consider:
> 
> a = 125 125 125
> 
> a = 125, 125, 125
> 
> a = 125_125_125
> 
> For me the gestalt of the first line looks too much like the second
> one, that is three separated things

This is no more the case than for literal strings:

a = "spam" "eggs" "ham"

a = "spam", "eggs", "ham"

Yet this is already a valid way in Python to specify, respectively, a
single literal string and a literal tuple of strings.

> While in the third case the _ helps glue the parts, creating a
> single gestalt to my eyes.

To my eyes, it's needlessly hard to read, and looks too similar to an
identifier, not a literal. On the other hand, the spaces version is
easy to see as analogous to the same syntax rules that already exist
for strings.

> Note that it's not just a matter of font and familiarity, it's also a
> matter of brains. Your brain may be different from mine, so it may be
> possible that what's better for you isn't better for me. So in such
> situation a popular voting may be the only way to choose. But for me
> having spaces to split number literals in parts is _worse_ than not
> having any way at all to split them. So I'm strong opposed to your
> suggestion, so I may not even propose the PEP if lot of people agrees
> with your tastes.

Thanks for making your position clear.

-- 
 \          “The WWW is exciting because Microsoft doesn't own it, and |
  `\              therefore, there's a tremendous amount of innovation |
_o__)                                          happening.” —Steve Jobs |
Ben Finney



More information about the Python-list mailing list