5 ms·
Does no one have auto indentation in their editors? Every so often I just select the block of code I'm editing and auto indent it, which matches indentation wit
by newen 8y ago
Does no one have auto indentation in their editors? Every so often I just select the block of code I'm editing and auto indent it, which matches indentation with semantics without me having to think about it. Annoyingly impossible to do this with python since indentation is semantics. It also results in copy pasting of code being 100 times harder in python than other languages.
- acdha 8y agoThat doesn't help with the problem you're replying to – in fact it would contribute to it. More generally, yes, many people use auto-indenting and it works in Python in most editors. It's possible that you're using one where it doesn't work correctly but that doesn't mean that's true for everyone else.
- newen 8y agoIt does help with the problem I replied to, which was code written in C. Auto indenting that code block would indent the `someotherstatement;` line correctly and I would notice that mistake. Anyway, single line if statement is a flaw in C's design. What I said was that in Python's case, if I indent some code block wrong, I can't just fix the indentation using auto indenting in python, because the indentation is the semantics. There would be "nothing" to fix and the code would just run wrong. This problem comes up always when I copy paste python code. Of course I should notice that it's indented wrongly but that doesn't always happen. (And please don't advise me to never copy paste code. Life doesn't work that way.)
- acdha 8y ago> Auto indenting that code block would indent the `someotherstatement;` line correctly and I would notice that mistake. In my experience that last part is somewhat optimistic for the implication that someone would notice it immediately. > if I indent some code block wrong, I can't just fix the indentation using auto indenting in python, because the indentation is the semantics. There would be "nothing" to fix and the code would just run wrong. This is true in some cases — most of the time you'll get an indentation error instead of it running incorrectly — but also why many editors have an auto-indent option for pasted code and autoformatters covert things like code which is consistently indented to match your project's indentation size.
- Symmetry 8y agoIf this were code that I was writing myself it wouldn't be a problem because I always use braces even for single statements. And I do use an auto-indentor. But these issues come up when I'm reading other people's code, especially libraries supplied by IC vendors. As for pasting, if you're using an IDE that ought to be taken care of for you. I use a vim and the sequence for indenting or de-indenting the text I just pasted is now second nature. For the first 5 or so years of my career I used Algol syntax (and a bit of Lisp) exclusively. But having been trading off between C, C++, and Python since then I've come to prefer Python's syntax, though not its lack of static types.