5 ms·
I think Python's mandatory whitespace has a similar nature as Go's unused-as-an-error. They are definitely great in production code, but when I play with code,
by barosl 11y ago
I think Python's mandatory whitespace has a similar nature as Go's unused-as-an-error. They are definitely great in production code, but when I play with code, sometimes I do want to mess them up while adding and removing the parts of the code. Even though I've used Python for more than 10 years, I often feel like "I don't want to indent these lines for now. I wish there were a way to wrap them up without changing the indentation" after copying and pasting some lines.
- markrages 11y agoYour editor can indent / dedent whole regions of code with just a few keystrokes. If this is not true, find another editor.
- barosl 11y agoBut then again, unfortunately, Python's significant whitespace makes automatic indentation hard, because there are some edge cases that an editor cannot extract the actual intention by the programmer well. For example, if there is a code as: for i in range(10): if i % 2 == 0: print('hello') and I paste `print('world')` after that, there are at least three possibilities of the proper indentation of the line. It can match with `print('hello')`, or with `if`, or even with `for`. That's because Python encodes block information solely using whitespace. So, if the indentation changes, the actual meaning of the code also changes! In fact, that's why it is called "significant". You cannot automate it, just like you cannot automate writing code.
- markrages 11y agoin my editor, I press "tab" anywhere on the line with print('world') and it cycles between the three options. If I want to move a whole block in one level, I select the block, then press control-C and '>'. That's what I mean.
- barosl 11y agoUh, yeah, same for me, but that's the "I don't want to indent these lines for now" situation that I mentioned above... Wasn't I clear about that? To me, regardless of the number of the key strokes needed, it's still a manual indentation that bothers me more or less while coding.
- deleted 11y ago[deleted]
- deleted 11y ago[deleted]