[Python-ideas] Improve readability of long numeric literals

Nick Coghlan ncoghlan at gmail.com
Wed Feb 10 07:38:57 EST 2016


On 10 February 2016 at 21:57, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Guido van Rossum wrote:
>>
>> (Not sure
>> about "12_34_56" but there are probably use cases for that too.)
>
> I think the Chinese group by 10,000s rather than 1000s,
> so they might want to write 1234_5678.

As others have suggested, I like the idea of keeping the grammar
simple (i.e. numeric literals must start with a base appropriate
digit, but may subsequently contain digits or underscores). I'd even
apply that to float literals, with the avoidance of putting an
underscore just before the floating point being a style issue, rather
than a syntactic one.

What kind of numeric grouping to use is also a style question - if
it's an English-language project or an international project using
metric values, then it would make sense to group by thousands. If it's
a project written assuming maintainers can follow Chinese or Japanese,
then it would make sense to group according to the conventions of
those language communities, just as folks may already decide to do
with variable names and comments.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list