[Python-ideas] float('∞')=float('inf')
Steven D'Aprano
steve at pearwood.info
Sun Jul 14 11:17:18 CEST 2013
On 14/07/13 16:40, Joshua Landau wrote:
> Personally, code in which copy-paste is the best way to
> write single-character identifiers is a hassle. I know because I
> wrote:
Copy-pasting is never the best way to write single-character identifiers, however it may be the least-worst way when dealing with unfamiliar characters or those not supported by your input system. It works, even in Notepad. But nobody suggests Notepad is the best way to edit code. Professionals use a more powerful editor with lots of powerful shortcuts. Professionals who need to support non-ASCII characters should likewise choose an editor that provides them with powerful character entry methods that are faster than copy-and-pasting.
Looking at the example you give below:
> from itertools import count as æ, permutations as Æ, starmap as ð
> [globals().setdefault("%c"%sum(ø.encode()),ß)for ø,ß in
> vars(__builtins__).items()if ø!="vars"]
> sorted = lambda ħ:ƿ(ƞ for ı in
> φ(ƴ(lambda:ħ,æ),ń(0,ń(ħ)**(len(ħ)*2-1)*len(ħ)))for ƞ in Æ(ħ)if
> ǂ(()).__eq__((ŕ(ð(ǂ(Ƽ(ƞ).pop()).__rpow__,φ(ŕ(œ(ƞ,ƴ(lambda:0,ħ)),()),1))),ħ),ı))[::-1]
>
> And that was a *nightmare* to edit.
Of course it is, because you have just arbitrarily chosen identifiers that don't mean anything, and obfuscated your algorithm as well. I could generate obfuscated ASCII-only code just as horrible to edit using equally awful identifiers like O00OOllII1, O0O0OlIlIl and so forth. But to a mathematician, identifiers like μ σ and ß are no more obfuscated than len, encode or count.
Back in the 1980s, I used a Mac which made entering non-ASCII characters a dream, at least for the limited 8-bit charset that Macs supported. Making allowances for that, the above could be simple, if you know key sequence to get the symbols you want, or if your editor provides an input interface that you are happy to use.
We have developers here who have seemingly memorized seemingly vast numbers of Emacs and Vim key sequences to perform the most obscure functions, and yet are apparently utterly terrified of the idea that some time in the future they may have to memorize a key sequence like option-p to get π, or option-u o to get ö. (See, I still remember them, 15+ years since I last used a Mac extensively. Well-thought out mnemonic key sequences for the win.)
Editor support for non-ASCII characters ranges from mediocre to absolutely atrocious, depending on the characters and the editor. I don't deny this. A softly, softly approach to non-ASCII identifiers is still wise. I'm still unconvinced that Python 3.4 should accept ∞ in the language, and I am probably one of the minority who would actually made use of such a feature. But let's please put aside the concept that writing code in anything other than a subset of American English characters is by definition an insane thing to do.
--
Steven
More information about the Python-ideas
mailing list