How coding in Python is bad for you

BartC bc at freeuk.com
Tue Jan 24 06:52:51 EST 2017


On 24/01/2017 04:41, Chris Angelico wrote:
> On Tue, Jan 24, 2017 at 3:22 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> But more seriously, it's easy to typo an extra indent. It's harder to typo
>> "endif" when you actually meant to type, oh, "ending = 1 if condition else 3",
>> say. So faced with ambiguity, and the insistence that the right way to break
>> ambiguity is to guess ("Do What I Mean, dammit!!!") the most likely guess is
>> that the indentation is wrong.
>>
>> But not guaranteed. That's the thing about being ambiguous -- there is a chance
>> that the indentation is correct.
>
> Indeed. I teach JavaScript as well as Python, and I've seen some
> pretty horrendous indentation flaws (examples available if people ask
> privately, but I will anonymize them because I'm not here to shame
> students) - but there have been nearly as many cases where the
> indentation's fine and the bracket nesting isn't. I probably sound
> like a broken record [1] with the number of times I've said "check
> your indentation", as a hint to where the missed-out close brace or
> parenthesis is. True, with "endif" it's a bit harder to typo, but it's
> still just as easy to make a copy-and-paste error and end up with code
> like this:
>
> if condition:
>     statement
> endif
>     statement
> endif
>
> What's this code meant to do? Can't know.

But whatever it does, a language that enforces 'endif' would report an 
error, so requiring further investigation. Without the 'endifs', it 
would look like this:

  if condition:
      statement
      statement

Legal python.

Presumably you don't like parentheses in function calls for the same 
reasons; you'd prefer 'f a,b,c' rather than 'f(a,b,c)' in case, with 
copy&paste, someone might end up with: 'f(a,b,c),d)'.

Having 'f a,b,c,d' is better; much less chance of those pesky syntax errors!

> Remember: If you have only one clock, it might be right and it might
> be wrong, but it's consistent. If you have two clocks and they
> disagree, you have no clue what the time is.

I've actually got three wall clocks. Usually only one will disagree with 
the other two, meaning it needs a new battery. But don't they use such 
systems in avionics?

-- 
Bartc


More information about the Python-list mailing list