5 ms·
I'm talking about something like this.. def foo(): do_this() and_this() later I change it.. def foo(): if something():
by jahnu 12y ago
I'm talking about something like this..
def foo():
do_this()
and_this()
later I change it..
def foo():
if something():
do_this()
and_this()
oops... and_this() should have been in the if block and I won't find out till I run it.
(imagine a much bigger more complex example of the above function)
In large pieces of code this can be easy do.
If you are forced to use parenthesis it's much more difficult to make this error. One could argue that experience prevents you from doing this but I have sadly found this not to be the case in practice.
- lutusp 12y ago> If you are forced to use parenthesis it's much more difficult to make this error. By "parentheses" you mean delimiters, which create visible boundaries to defined areas in code. Parentheses are an example of delimiters, but not all delimiters are parentheses. Bash has if ... then ... else ... fi Ruby has if ... else ... end C/C++/Java have (logical test) { controlled area }, nested to any practical depth. And so forth. Python doesn't. > One could argue that experience prevents you from doing this but I have sadly found this not to be the case in practice. This is an argument against complex functions that do a lot, as opposed to breaking program logic up into smaller blocks that are easier to understand and control. The old argument against this practice was that a large function that did everything was faster than the same logic broken into smaller blocks. A modern compiler will generally prevent this from happening.
- jahnu 12y agoWell I used the word parenthesis since the topic was Lisp. > This is an argument against complex functions that do a lot Functions large and complex enough to make this problem significant seem to be the reality I have to deal with when programming in the large. It's only my opinion but a language feature that improves my real world experience at no cost is a bonus.
- andreasvc 12y agoI fail to see your point. You could accidentally put a brace in the wrong spot, or use an if statement without braces in a C-like language, and it would stand out visually much less than the code you cite above.
- crististm 12y agoAfter you write a fair amount of Python code (<5000 lines I guess), that idiom will strike you immediately.