Modifying the {} and [] tokens

Geoff Howland ghowland at lupineNO.SPAMgames.com
Sat Aug 23 12:12:03 EDT 2003


On 23 Aug 2003 08:18:49 -0700, mis6 at pitt.edu (Michele Simionato)
wrote:

>Subclass dict, define __add__ and __sub__ and it will work, but NOT
>with the brace syntax. You must use something like
>
>mydict(a=1,b=2)+mydict(c=3,d=4)

Yeah, I got this to work off the bat.

>Python tries hard not to modify its basic syntax, so you must stay
>with the above. Pythonista would argue that this is a strenght of the 
>language: "explicit is better than implicit".

I agree with this philosophy too.  I'm not sure where the changes I'm
looking to fail to be explicity.

{} + {} makes sense right?  You are adding them together.  There will
obviously be a possibility of key clobbering, but then you could run
something like {}.intersect() and get the keys that will be clobbered
(if it existed).

len([])

[].len()

Both seem to make sense explicitly to me.  Currently we use it through
builtins, but having it as an attribute would also be clear.  It's
duplicated, but at the same time it's consistant.

Yes I know it makes one version of [] different than others, but if
you state it is going to happen, then it is known.  If it is all new
functionality, then it wont break old functionality.  If you change
old functionality, you know you are doing it and risking problems.

Python allows for a lot of different things some people in other
languages claim is dangerous because it's too free-hand.  That doesn't
make them right, and often I've read statements in the spirit of
"Python gives you enough rope to let shoot yourself in the foot", and
it's meant as a good thing.  We're all adults here, etc.

I still think the above things might be good in the language in
general (not just a specific module change), but I would feel a lot
more certain after using them for a while in the real world.


-Geoff Howland
http://ludumdare.com/




More information about the Python-list mailing list