Code block literals
Mike Rovner
mike at nospam.com
Wed Oct 8 21:02:19 EDT 2003
Dave Benjamin wrote:
> Mike Rovner wrote:
>> Unnamed code blocks considered evil :), use named instead
>> (functions).
>
> Why are they evil? Does being anonymous automatically make you evil?
>
> For instance, I always thought this was a cooler alternative to the
> try/finally block to ensure that a file gets closed (I'll try not to
> mess up this time... ;) :
>
> open('input.txt', { |f|
> do_something_with(f)
> do_something_else_with(f)
> })
>
> Rather than:
>
> f = open('input.txt')
> try:
> do_something_with(f)
> do_something_else_with(f)
> finally:
> f.close()
"Explicit is better than implicit"
Even your example clearly shows that try block is much more readable and
understandable.
That's why it's being considered evil by majority of python developers.
> But the anonymous version still looks more concise to me.
Python prioritize things diferently than other languages.
It's not an APL. "Readability counts"
> Yeah, wasn't something like that up on ASPN? That's an interesting
> trick... are you sure it's not supposed to be "property(*aprop())"
> though? (who's being pedantic now? =)
Yeah, right. Thanks for pointing out.
Mike
More information about the Python-list
mailing list