do people really complain about significant whitespace?

Stephen Kellett snail at objmedia.demon.co.uk
Thu Aug 10 06:40:01 EDT 2006


In message <1155133454.975325.237770 at b28g2000cwb.googlegroups.com>, Carl
Banks <pavlovevidence at gmail.com> writes
>Stephen Kellett wrote:
>I don't really understand how a closing brace helps here.  Care to
>explain why it helps you?

>(Deeply nested long functions are evil anyways.  If you have such a

I didn't write deeply nested. I wrote multiple levels of indentation.
They are not the same thing (they can be, but they don't have to be). A
lot of code gets to 3 or 4 levels of indentation quite easily. I
wouldn't call that deeply nested, not by a long shot.

To answer your first question: In C++/Ruby/Pascal you'd have something
like this

function()
{
        loop1()
        {
                blah
                blah

                loop2()
                {
                        blah

                        loop3()
                        {
                                blah
                        }

                        blah
                }
        }

        otherloop()
        {
                blah
        }
}

and in Python that gets to

function()
        loop1()
                blah
                blah

                loop2()
                        blah

                        loop3()
                                blah

                        blah3

        otherloop()
                blah

I really dislike that the end of loop2  is implicit rather than
explicit. If its implicit you have to look for it. And if blah3 didn't
exist then both loop2 and loop3 would be ending implicitly. This problem
gets worse with longer functions and more indentation.  I'm sure some
people are thinking the above is elegant. To me, its clumsy, and here is
why...

Now, the above Python version looks nice, I grant you, but that is
because it is short. I'm talking about long functions which take up some
space. When you come to add loop4, which for arguments sake is after
loop2 but before otherloop() and at the same indentation as loop2, thats
trivial in C/Ruby/etc but in Python I've got to scroll up the screen
find loop2, remembers its indentation go back down and carefully insert
it hoping I've got it right. I don't have do that with C/Ruby etc
because loop2() ends with a brace/end statement so I know its
indentation/end point without having to go and find the start of it
(which is off the screen).

Yes the above example is contrived - so that I could demonstrate what I
wanted to demonstrate. But I've run into these problems with Python code
I've written and when reading code written by others. Its a real
problem, not just one I've cooked up for an argument.

As part of my day job I get to look at a lot of code written by other
people, mainly people I've never met and often people I've never even
traded email with. Strangely, if people have traded email with me, code
that arrives is usually well formatted :-) The amount of code written in
horrible styles is amazing, but if you can't spot the start/end of
loops/conditionals easily and quickly without having to actually read
the code then scanning for the actual code of interest becomes a lot
harder. C/C++ have quite a number of horrible styles (K/R being one)
which can be fixed with a code formatter, but that implicit loop ending
thing with Python I demo above - thats a language feature and nothing I
can do will make that go away.

I'm always thinking maintenance and readability, some time after the
fact. I know that I'll have a reason to come back some time later. Maybe
for a bug fix, a feature improvement or just to lift some code. That is
why stuff like this is important to me. It needs to be as fast,
efficient and error free as possible. And the above doesn't do if for
me.

Now I'm sure some of you will think I'm mad or whatever, but things like
this are important (to me, at least). I don't want to waste my time with
issues like the above. If I'm wasting my time on stuff like this it
can't be that readable can it? If you think the above isn't an issue
we'll just have to agree to disagree.

There some are people on the c.l.ruby newsgroup that love Ruby because
they don't have to type semicolons anymore. Not that its going to change
the world, but its important for them. I think that is one of the least
important things you can think of about Ruby, but there you go.

Stephen
-- 
Stephen Kellett
Object Media Limited    http://www.objmedia.demon.co.uk/software.html
Computer Consultancy, Software Development
Windows C++, Java, Assembler, Performance Analysis, Troubleshooting



More information about the Python-list mailing list