How an editor can help with block nesting (was Re: How coding in Python is bad for you)

Dan Sommers dan at
Tue Jan 24 20:44:20 EST 2017

On Wed, 25 Jan 2017 12:31:11 +1100, Steve D'Aprano wrote:

> But now I type something which cannot possibly be indented there:
>     def func(a, b):
>         if condition:
>             spam()
>             elif something: |
> and hit ENTER again. There's nothing ambiguous about this, and the
> editor could (and should?) re-indent the elif line, giving this:
>     def func(a, b):
>         if condition:
>             spam()
>         elif something:
>             |
> In other words, with the second scenario, you can never have more than
> one mis-indented line at a time during the normal course of
> editing. (At least not without really working to defeat the editor.)

And then you get to this one:

    def f(x):
        if condition:
            if g(x):
                elif something_else: |

Now, everyone, say it with me:  In the face of ambiguity, refuse the
temptation to guess.

In languages with braces, re-indenting lines as I press ENTER is
possible (I happen not to like that behavior, but that's a personal
preference, and editors that won't get out of the way and let me edit my
own code get deleted).

In Python, I prefer to get the indent right myself before I press ENTER.


More information about the Python-list mailing list