4 ms·
Do you never move code around? Especially moving things into and out of loops? That was my experience in Python. -> These statements need to be in this other
by lostdog 5y ago
Do you never move code around? Especially moving things into and out of loops?
That was my experience in Python.
-> These statements need to be in this other loop.
-> Cut...paste
-> Reindent
-> Turn my brain to extreme paranoia, and double-check that I properly indented the first and last lines of the code I moved.
In braces-languages, it was just cut..paste..autoformat. If you missed a brace, you hear about it from the compiler.
Python is a great language in a lot of ways, but I caught myself making indentation mistakes twice a week. Significant indentation is, in my opinion, an error in language design.
- formerly_proven 5y agoI've never had a problem with this when moving code around. Cut/paste, indent entire block to match initial level, done. Where is the potential for errors? There really is none, because the brainbox keeps track of what I just pasted and tab/shift-tab moves that block as a unit. I find moving stuff around in braced languages a wee bit more work, actually, because you have to move the braces manually instead of shifting the block in and out, which is quicker. Personally I've been way more annoyed when I've typed something up in the REPL and can't paste that over directly because of the >>> and ... but that's really a small tooling issue; a smarter editor would remove the REPL marks when pasting. Same for other REPL languages, most of them have PSn...
- lostdog 5y agoI have frequently had code like this: if other < mine: update_comments(other, mine) write_billing(other) and then I paste it, but get the indentation wrong on the last line, and it falls outside of the if block. Maybe my brainbox needs an upgrade. And yeah, pasting code into a repl would be easier too if I could rely on braces to convey scope.
- housecarpenter 5y agoI normally select the whole block that I just pasted and then press Tab or Shift+Tab to indent/dedent the whole thing at once---no possibility of missing the last line then. This works in most editors.