[Python-ideas] Allow additional separator character in variables
ncoghlan at gmail.com
Sat Nov 18 21:42:59 EST 2017
On 19 November 2017 at 12:32, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On 19 November 2017 at 12:01, Mikhail V <mikhailwas at gmail.com> wrote:
>> Python allows underscore character as a separator in variables.
>> This is better than nothing, still it does not make the look much better.
>> **Proposal**: allow additional separator, namely hyphen character.
> Regardless of any potential readability merits, backwards
> compatibility requirements combined with the use of the hyphen
> character as a binary operator prohibit such a change:
> >>> my = variable = 1
> >>> my-variable
Ah, sorry - I now see you addressed the basic version of that.
The alternative of "Use a character that computers can distinguish,
but humans can't" isn't an improvement, since it means introducing the
exact kind of ambiguity that Python seeks to avoid by using
indentation for block delimeters (rather than having the computer read
braces, and humans read indentation). The difficulty of reliably
distinguishing backticks from regular single quotes is also the main
reason they're generally discounted from reintroduction for any other
use case after their usage as an alternative to the repr builtin was
dropped in Python 3.0, and it's why Python 3 prohibits mixing tabs and
spaces for indentation by default.
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:
Would hyphens in variable names improve readability sometimes?
Potentially, but not enough to live with make binary subtraction
expressions ambiguous (hence the consistency amongst almost all
current text based programming languages on this point).
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas