[Python-3000] symbols?
Kendall Clark
kendall at monkeyfist.com
Mon Apr 10 18:16:24 CEST 2006
Folks,
One thing I'd really like to see in Python 3000 is support for first-
class symbols, with literal syntax. Stealing syntax from Ruby would
work for me:
def web_dispatch("/bank-account", :GET, retrieve_account): pass
The lack thereof in Python is a wart I tend to run into in Python. I
end up having to use strings, but not really using them for their
stringiness (never using any of their methods, for example). Which
works, but is sorta ugly. So I end up making classes and instances,
but these are really just wrappers around strings, when all I really
want is a symbol.
(For example, in my SemWeb lab @ UMD, we built a Rete rule engine in
Python that's being used in some SemWeb projects. We gave a talk
about it at the last PyCon in DC. Symbols in that project would have
made life a lot easier, instead of making up a bunch of classes that
were just wrappers around strings. Which is: (1) really boring, (2)
error-prone (because of (1)), and (3) generally not fun.)
I also think, though I'm not really gonna argue the point, that
having symbols would clean up lots of different sorts of APIs that
use strings or class instances where symbols would work perfectly
nicely. Some people claim the point of symbols is to save memory over
repeated string usage, but I don't care about that, and I make claims
about any kind of performance enhancement. I think symbols in Python
would just make the language more fun.
I don't know if the Ruby syntax for symbols, :foo, will work in
Python (though I think visually it's a good thing), but it would be
really nice to have symbols with *some* syntax in Python 3000.
Again, this design request is based on aesthetics and fun: having
symbols would make Python more fun.
Cheers,
Kendall Clark
PS--I'd also like "?", "!", and "-" to be legal characters in
function, method, and variable names, but I won't push my luck -- and
I seem to remember Guido saying that would never happen, at some
point back in the day. Fair enough. ;>
More information about the Python-3000
mailing list