3 ms·
The correct solution to this problem is an autoformatter. You should be indenting your code to match its structure, yes, but if you use Python you have to do so
by bobbylarrybobby 6y ago
The correct solution to this problem is an autoformatter. You should be indenting your code to match its structure, yes, but if you use Python you have to do so, whereas if you use a brace delimited language you don’t, as it’s handled for you (by the autoformatter). In both cases, your code looks right before you run it, but the editing experiences differ drastically. In Python, a simple cut/paste is nontrivial to get right and it’s difficult for editors to infer how to indent a line when you press the return key. In a brace delimited language, these problems simply don’t exist.
- Kim_Bruning 6y agoI don't think anything will save you if you mess up your block structure. You can mess up your block structure with indents, or you can mess it up with braces. Personally I think it's easier to spot mess-ups with indents. Some people think braces are easier. I won't fight with those people today :-). But I don't think randomly cut&pasting code anywhere is a good idea. If you do paste code, you really should understand what the code is doing first.
- kortex 6y agoThis is absolutely true. If I paste some c++ into my IDE with unbalanced braces, it can throw the whole file off. The real key is: treat excess indentation and nesting as a code smell. Python should aim for 5 tabs deep max, imho. Anything else should be refactored into functions.
- belorn 6y agoI would add that the same is true for braces in c++. Debugging the differences between }}))} and }))}} can be quite difficult , as nested scopes is never easy in any language.