[Python-ideas] Keyword/Symbol literals

Andrew Barnert abarnert at yahoo.com
Wed Jan 21 10:13:10 CET 2015


On Jan 20, 2015, at 23:48, Stephen Hansen <me+python at ixokai.io> wrote:

>> What do people do now?
>> or strings
>> 
>> df.sort('name')
> 
> ...
>  
>> strings work but feel unpleasant
> 
> Why?
> 
> What does :foo get you that 'foo' doesn't?
> 
> One character being saved doesn't seem like a good reason to add syntax.

Mainly they're used to fill in gaps where a language isn't dynamic enough to just use strings, which Python doesn't need.

(Sometimes this is claimed to be a strength rather than a weakness. Arguably, using auto-interned symbols instead of strings for things like attribute or global lookup could be more efficient, but I don't think languages like Ruby have shown any demonstrable gain. And we just had a thread from someone who considered it a "bug" that Python allows setattr(spam, '3', 3) when 3 isn't a valid identifier, which symbols "fix" automatically. But even if these were real advantages, Python obviously isn't going to make such a radical change as banning strings for dynamic access.)

A language can also add things on top of the symbol/string distinction (besides auto-interning)--e.g., you can add syntactic sugar for dynamic lookup ("foo.:bar" means "getattr(foo, bar)"), or make undefined variables have the value of their symbol so you can LBYL test them, or all kinds of other things--but again, they're all things I don't think Python wants or needs.

And without a vague idea for why Python would want to do any of the things that other languages do with their symbol-vs.-string distinctions, this really does seem to come down to just saving one character.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150121/f041c849/attachment.html>


More information about the Python-ideas mailing list