[Python-Dev] PEP 340: Breaking out.
Nick Coghlan
ncoghlan at gmail.com
Thu May 5 12:55:14 CEST 2005
Alex Martelli wrote:
> Looking for a file with a certain magicnumber in its 1st two bytes...?
>
> for name in filenames:
> opening(name) as f:
> if f.read(2) == 0xFEB0: break
>
> This does seem to make real-life sense to me...
Also consider the vast semantic differences between:
locking(lock):
for item in items:
if can_handle(item): break
for item in items:
locking(lock):
if can_handle(item): break
Instead of simply acquiring and releasing the lock on each iteration as one
might expect, moving to the latter version *also* causes every item to be
checked, instead of only items up to the first one that can be handled. The
break magically becomes meaningless. How does this even come close to executable
pseudocode?
I also think another factor is that currently, instead of doing try/finally's in
loops, there is a tendency to push the try/finally into a function, then call
that function inside the loop. The introduction of block statements means that a
number of those inner functions are likely to be handled as block statements
instead - with the above highly confusing result.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
More information about the Python-Dev
mailing list