Why not allow empty code blocks?

BartC bc at freeuk.com
Sun Jul 24 21:14:46 EDT 2016


On 25/07/2016 01:40, Gregory Ewing wrote:
> BartC wrote:

>> So I still think it's fragile, meaning you have to take a lot of extra
>> care.
>
> The practical experience of a very large number of Python
> programmers suggests that it requires very little additional
> care over and above that normally required for programming.
>
> What's your experience? How often has this caused you trouble,
> and what proportion is it of all the Python programming you've
> done?
>

I've done little Python coding but still, having to use kid gloves for 
indents does figure quite a bit in that.

I can give some more examples but I'll probably be told that I'm using 
the wrong tools! Which suggest there is a problem, but the effort has 
gone into working around them using external tools. (But understandable 
if the language design was fixed 25 years ago.)

For example:

if cond:
     a
     b

I want to comment out the if statement temporarily, but I also have to 
fix the indents:

#if cond:
a
b

(Or add the comment and insert a dummy 'if 1:'.)

Or I want to add a temporary condition around:

a
b

which again requires me to indent those statements (and unindent them 
again later). Or I want to permanently have a commented out #if guard 
around some code:

#if cond:
a
b

to be uncommented from time to time (to do with debugging). But it's not 
as simple as just uncommenting that one line.

Or I want to have a temporary print statement within a block, but it 
needs to be at the right indentation. Not a great imposition, but it's 
now less visible as a temporary addition.

Or I need to move or copy code from one location to another, but the 
indentation levels are different. This would need fixing in other 
languages too, but if this is part of a temporary try out which will 
change again a few minutes later, I can dispense with the correct 
indentation in another language, until the code is more permanent.

In short, because correct indentation is required at all times, it's 
less flexible when you want to do a lot of messing around.

Now, if I was going to do a LOT of Python coding, then I would solve 
most of those problems (by having my own tool to superimpose a more 
amenable syntax on the language). For casual work though I have to go 
along with the indent scheme. (And there are usually other issues with 
Python that are more troublesome than getting the layout right.)

I'll leave you with a code fragment that might be pasted from elsewhere 
(it's not meant to mean anything):

if cond:
     a
     b
     c

The question is: is this the whole block? We don't know, as we can't see 
what came next. But if now I add the next line, and it was this 
(anything actually with one less indent):

if cond2:

then yes it was the whole block, IF we assume an indent didn't get 
clobbered in the process! But if the line happened to be:

else:

now we know for sure.


-- 
Bartc



More information about the Python-list mailing list