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

Chris Angelico rosuav at
Tue Jan 24 20:47:28 EST 2017

On Wed, Jan 25, 2017 at 12:31 PM, Steve D'Aprano
<steve+python at> wrote:
>> With my JavaScript students, the greatest help is probably a keystroke
>> beautifier. You edit your code with sloppy indentation, and then bam,
>> it reindents for you.
> Really? I wouldn't want that, or find it helpful to type badly formatted
> code.

This isn't something I use (when I want a beautifier, it's because I'm
de-minifying some code to figure out what it does, so I just paste it
into or something), but I've seen my students
move braces around and then hit the beautifier, where I would
highlight the text and hit Tab or Shift-Tab to adjust the indentation

> I would want one of two things:
> (1) Indentation is up to you. You either get it syntactically right, or the
> code won't run, like Python. That teaches you to get the indentation right
> through negative reinforcement.
> (2) Or the editor won't let you enter sloppy indentation in the first place.
> This teaches you good indentation by example.
> [chomp details of entering code for the first time]

Tell me, how often do you enter code and it works the first time? :)

Much more common - and this is especially true of student programmers,
but we're none of us immune to it - the code gets tinkered with and
edited and manipulated many times before it's finally working. Stuff
gets reordered, conditionals get added or removed, etc, etc, etc. So
there are a few possibilities:

1) Get the symbols right, then adjust the indentation to match
2) Get the indentation right, then adjust the symbols to match
3) Check before permitting code to be committed, and reject if they don't match
4) Check before permitting code even to be run
5) Ignore the indentation because it "doesn't matter", and then waste
your instructor's time when you call him in to help you figure out
where your bug is.

Python makes the second option easier (by having no symbols for the
most common indentation), but doesn't eliminate the problem entirely.
The fifth option is what most often happens. The first is the "hit the
beautifier key" option, and is fine as long as you absolutely
definitely got the symbols right. I'm thinking the third or fourth
might be the best :)


More information about the Python-list mailing list