[Python-ideas] Allow additional separator character in variables

Mikhail V mikhailwas at gmail.com
Sat Nov 18 23:44:18 EST 2017


On Sun, Nov 19, 2017 at 3:42 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> For anyone tempted to suggest "What about multiple underscores
> indicating continuation of the variable name?", that's still a
> compatibility problem due to the unary minus operator:
>
>     >>> my--variable
>     2
>     >>> my---variable
>     0

That seems to be another showcase of misfotune that Python
uses hyphen for minus operator. I know it is not language designer's
fault, because basic ASCII simply did not not include minus character.
But do you realise that the **current** problem you are adressing is that
font designers forgot to make the minus character (in monospaced font)
distinctive from the hyphen character?

Well, what can I say, I just think it should be a reason to make a
collective complain to font providers, but not that you should silently
accept this and adopt the language design to someone's sloppy font design.

As an aid for monospace die-hards, to minimise the confusion one could
publish a style-guide that recommends to disclose the minus operator (currently
hyphen char)  in spaces, like a - b, and probably disallow the new proposed
hyphen character in the beginning of the identifiers.
That would still leave potential for confusion because you cant' force everyone
to follow style-guides, but one should struggle to break from this cycle anyway.

>
> Would hyphens in variable names improve readability sometimes?

For reading code, indeed, always and very much. Of course not in case
I would be forced
to use monospaced font with a similar minus and hyphen. But
in that case I am already accepting the level of readability of
12th century, so this would not make things much worse, and I
would simply put spaces around the minus operator and try to highlight
it with some strong color.



Mikhail


More information about the Python-ideas mailing list