4 ms·
Indentation makes copy/paste bugs too hard. It’s difficult to copy/paste when the source and destination are at different indentation levels. I strongly prefer
by forrestthewoods 5y ago
Indentation makes copy/paste bugs too hard. It’s difficult to copy/paste when the source and destination are at different indentation levels.
I strongly prefer braces. But I also increasingly languages with a standard style and formatter. Go and Rust both do this well.
- kjeetgill 5y ago> Indentation makes copy/paste bugs too hard. I love Python's indentation based blocks (in Python) but this is the biggest issue I've had with it. That and maybe occasionally when word wrapping. I think Python's general terseness mitigates most of the reasons I might miss blocks in C or Java.
- boardwaalk 5y agoSelecting and hitting tab or shift-tab (or <, > in Vim) to adjust the indent level isn't all that difficult.
- kinjba11 5y agoTools like Prettier can automate this with curly-brace languages, so indentation (tabs or spaces?) stops being something you waste brain power on, similar to how code editors will match the current line's indent on the next line when you press enter even though it's just "press tab a few times". It adds up. // just copied some code into this while block, oops I copied an extra space out front... while (...) { if (...) { ...} } // after Ctrl+S tied to autoformat while (...) { if (...) { ... } }
- xigoi 5y agofor line in lines_to_paste: paste(current_indent .. line)
- dragonwriter 5y ago> Indentation makes copy/paste bugs too hard. Making copy/paste bugs too hard discourages copy/pasting code rather than reading and rewriting, so, mixed bag there, IMO.
- lostdog 5y agoDo 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.
- Too 5y agoPycharm matches the indentation level to where the cursor is located when pasting. This is hardly ever a problem in practice.