do people really complain about significant whitespace?

Jean-Paul Calderone exarkun at divmod.com
Wed Aug 9 09:08:47 EDT 2006


On Wed, 09 Aug 2006 13:47:03 +0100, Pierre Barbier de Reuille <p.barbierdereuille at free.fr> wrote:
>Carl Banks wrote:
>> Michiel Sikma wrote:
>>> Op 8-aug-2006, om 1:49 heeft Ben Finney het volgende geschreven:
>>>
>>>> As others have pointed out, these people really do exist, and they
>>>> each believe their preconception -- that significant whitespace is
>>>> intrinsically wrong -- is valid, and automatically makes Python a
>>>> lesser language.
>>> Well, I most certainly disagree with that, of course, but you gotta
>>> admit that there's something really charming about running an auto-
>>> formatting script on a large piece of C code, turning it from an
>>> unreadable mess into a beautifully indented and organized document.
>>
>> The only time I get that satisfaction is when I run the formatter to
>> format some C code I'm asked to debug.  Quite often the problem was
>> something that could have been easily spotted if the coder had used
>> good indentation in the first place.  Though they probably wouldn't
>> have seen it anyways, considering the poor programming skills of most
>> engineers (the classical definition, not computer engineers).
>>
>> The very fact the code formatters exist should tell you that grouping
>> by indentation is superior.
>>
>>
>> Carl Banks
>>
>
>Problem being : grouping by indentation do *not* imply good indentation.
>For example, I had to read a piece of (almost working) code which looked
>like that :
>
>
>  if cond1 :             stmt1
>                         stmt2
>                         stmt3
>      if cond2:          stmt4
>                         stmt5
>      elif cond3:        stmt6
>                         stmt7
>  else:                  stmt8
>                         stmt9
>                         stmt10
>                         stmt11
>

This isn't actually legal Python.  Each branch starts with a simple suite and then proceeds to try to have a full suite as well.  A block can consist of one or the other, but not both.  Additionally, the nested if/elif has the wrong indentation and fits into no suite.

The closest legal example I can think of is:

  if cond1 :
                         stmt2
                         stmt3
                         if cond2:
                                        stmt5
                         elif cond3:
                                        stmt7
  else:
                         stmt9
                         stmt10
                         stmt11

Which, while ugly, actually makes it much clearer what is going on.

>
>So you can tell what you want, but this code is valid but impossible to
>read and impossible to reindent correctly. So although I personnaly like
>Python, I still don't think meaningful indentation is good.

If your example were actually valid (which it isn't), all it would
demonstrate is that Python should be even stricter about indentation,
since it would have meant that there is still some whitespace which
has no meaning and therefore can be adjusted in meaingless ways by
each programmer, resulting in unreadable junk.

Jean-Paul



More information about the Python-list mailing list