Explicit Frustration of the Self

Erik Max Francis max at alcyone.com
Tue Dec 31 22:57:54 EST 2002


Cliff Wells wrote:

> I (sheepishly) admit that I'm kind of fond of the "with" statement
> some
> languages have:
> 
> somelongname.x = 1
> 
> with somelongname:
>     .x += 1
>     print .x

Well, at least this form of a with construct makes a great deal more
sense than the more naive form that's generally suggested, in which it
would be written

	with somelongname:
	    x += 1
	    print x

The problems with this are legion in a dynamic language like Python.

I tend to eschew "with" constructs in general (even setting aside the
obvious issue with the naive form and Python's dynamicism).  At least
the prefixed dot version has the form of being terse and make it clear
what's intended to be abbreviated and what's not.  But then again,
wouldn't:

	_ = somelongname
	_.x += 1
	print _.x
	del _ # if you want to be really anal

be just as good (or some other single-character name instead of _)?

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Did you ever love somebody / Did you ever really care
\__/ Cassandra Wilson
    The laws list / http://www.alcyone.com/max/physics/laws/
 Laws, rules, principles, effects, paradoxes, etc. in physics.




More information about the Python-list mailing list