Re:Four days of Go
by markrages on Wednesday April 22, 2015 @08:54PM
(#9424449)
Your editor can indent / dedent whole regions of code with just a few keystrokes. If this is not true, find another editor.
[ Parent
| on HN ]
But 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.
in 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.
Uh, 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.