__brace__ (PEP?)

Terry Hancock hancock at anansispaceworks.com
Wed May 11 11:30:12 EDT 2005


On Sunday 08 May 2005 06:29 pm, James Stroud wrote:
> If "__call__" allows anobject() and "__getitem__" allows anobject[arange], why 
> not have "__brace__" (or some other, better name) for anobject{something}. 
> Such braces might be useful for cross-sectioning nested data structures:
[...]
> Though I positively can not see what is wrong with this suggestion, I am sure 
> this will raise more than a few objections. Please bash my naivete publicly 
> on the list.

I think it's backwards to come up with some symbolic syntax that we haven't
used and then flail around looking for a semantics application.

It's good to think that we have such options still (despite the fact that the
small space of symbolic operators is getting fairly full and fairly overloaded
already).  But surely the right approach is to wait until a pressing need for
some new semantics comes along, and *then* flail around looking for the
right syntax to represent it?

I think this is whence comes the criticism for the use case you made --- it
doesn't seem compelling enough an application to warrant fundamental
additions to Python's syntax.

Also, I think you have to realize that Python has chosen a very definite
design trade in making *most* operations loadable by module and making
most syntax use words, because those approaches are better self-documenting.

Symbolic language is reserved for only the very most common operations
where the overhead of using a word operator like "PLUS" would just be
ludicrous (Cobal anyone?).  I think it's a good design decision, and I
suspect it accounts for an awful lot of my intuitive preference for Python
over languages like Perl.

I agree that the syntax could be made to work, and I'm intrigued by
the thought.  But no, we don't need it, so we shouldn't do it.

The comparison to __call__ is a bit spurious. We need that, because we
need the ability to make classes act like functions for interface reasons.
We need __getitem__ because we need them to act like sequences or
collections at other times.  What would __brace__  make the class act
like?  I think it's just "something else", and that can be handled with
methods.

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com




More information about the Python-list mailing list