Re:Lisp vs Python
by neutronicus on Sunday February 20, 2011 @07:12PM
(#2243623)
I want to communicate, using indentation, that more_main_scope_stuff() and subsequent code do not depend on c. c is conceptually part of the loop, and not of the surrounding code. (Like the initialization statement in C/C++).
The code I wrote does this (because c is 1 indentation level deeper than the main_scope functions). I do not know if it is legal Python to simply increase indentation level to demarcate a new scope, but I suspect it is not, and it is certainly not common practice.
This is really a minor gripe - but then again so are the article's - it's pretty easy to tell a binding from a function call.
Ah, I see -- this is a really good point, thanks for bringing it up. You're right, one can not arbitrarily increase scope in Python. The most common way I've seen of demarcating this kind of structure is actually using a blank line. For example, the code would instead look more like:
c = create_context()
for foo in foos:
do_something(foo, c)
do_other_thing(foo, c)
accumulate(foos, c)
do_other_stuff
One could also throw the separate stuff into a new function.
Re:Lisp vs Python
by neutronicus on Sunday February 20, 2011 @07:34PM
(#2243674)
One could also throw the separate stuff into a new function.
That's the elephant in the room in all of these "my language is more readable" discussions, isn't it?
I'm not really sure what you're trying to show with that code, though. Is your objection that every do_ function is requiring a context?
Edit: I see what the parent was saying now, see bottom comment. Also, see StavrosK's comment if you're fine using Python 2.5 (released 2006).