Hacker News new | ask | show | jobs
by dszoboszlay 1262 days ago
Based on my quite limited experience with Python the big drawback of indentation sensitivity is copy pasting will only work when your editor has great language support. If I copy a block of code from indentation level X and paste it to indentation level Y when I have explicit end-of-block tokens the worst thing that could happen is that I end up with badly indented code that I have to clean up manually. On the other hand, if indentation matters, and my editor messes up things, I am very likely to get code that looks good, probably compiles too, but does nothing like the original. I have to read through every line carefully and think about where the blocks were meant to end. In the end I'm still not convinced that significant indentation would worth the trouble.
2 comments

I've been writing python for 20 years, and I truly cannot think of an instance where pasting code was an issue. I use vim mostly without any plugins, not any fancy editor.
I've only used python a few years professionally, but seen it multiple times. With other languages I paste in code between some brackets, run the autoformatter and it looks as I want. With python I paste in some code, run the autoformatter, only to see because of spacing issues half the lines I pasted didn't get properly parsed to be inside the for loop or whatever.

Also makes it hard to copy a snippet to run inside a REPL or whatever.

In general just a huge amount of pain, and the "good thing" about how it forces well formatted code I've never seen as an issue with autoformatters and linters in othet languages.

The "trick" is to copy and paste on the right block level. Just set the cursor appropriately (which the editor does for you if you use the feature to jump to block start or end).

Than everything just works.

(For that to work even better the stupid feature of some editors to remove white space form all empty lines should be disabled. So pressing enter or going to the next empty line will always position the cursor on the correct indentation level. Than it's easy to paste code blocks everywhere as even empty lines are correctly indented).

I've written a lot of python in my life (but most of the time not as my main day-to-day language) so whenever I had to try something small in a REPL I do paste. I guess it would work to highlight a piece of code and run it externally with a shortcut, but I've never set that up, so I did indeed run into this problem more often whenever I was just taking up Python again (for example I find [x for x in ....] kinda horrible and have at times fat-fingered if it's twice nested)
Use ipython's magic function, %paste. If you need to make minor edits, %cpaste. If you're exploring, consider using a notebook.
> If I copy a block of code from indentation level X and paste it to indentation level Y when I have explicit end-of-block tokens the worst thing that could happen is that I end up with badly indented code that I have to clean up manually.

That's exactly the same "clean up" you need to do if you did something wrong while copy & pasting code without the useless block delimiters.

The rest is made up as someone pointed out already: Exactly this story comes up every time but in reality it never happens. (Besides when someone tries hard to get it wrong by all means only to prove their made up point).