Collective memory (was: Good code patterns in Python)

Alan Kennedy alanmk at hotmail.com
Sun Jul 6 09:29:57 EDT 2003


Andrew Bennetts wrote:

> C code is indented to reflect its structure, but uses braces to reflect
> that structure.  This is IMHO worse.
> 
>     if (something)
>         work();
>         more_work();
>         add_numbers();

Back in my C programming days (late 80s, 90s), I used to always indent
my code python style anyway (before I even knew of the existence of
python, ABC, etc). For example

if (cond)
    {
    work();
    more_work();
    }
else
    {
    other_work();
    and_yet_more();
    }

And I still write all my java that way to this day.

I occasionally got and get some complaints/ribbing from co-workers,
who most often preferred a style like this :-

if (cond) {
    work();
    more_work();
} else {
    otherwork();
}

But to me that was far less readable, especially when there are
multiple nested if/switch/while/etc statements. OK, you can find out
out where code blocks begin and end by using the bracket matching
facilities available in most editors, but that's no use to you when
you're reading a hard-copy printout, for example.

And in practically every C job I ever did, I used to get compliments
from "occasional programmers" (e.g. hardware engineers), who sometimes
had to work with my code to make minor changes. They would say things
like "your code is so easy to read", "I was able to find really
quickly the bit that I needed to change", etc. It was only the full
time programmers who complained, and they were generally from the "it
was hard to write, it should be hard to read" camp.

When I found python (oh serendipity :-), the indentation was
completely natural to me, and I got it right from my very first if
statement. It made my source look more readable, since it did away
with all those lines containing only '{' and '}'.

born-to-code-python-style-ly yrs :-)

-- 
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan:              http://xhaus.com/mailto/alan




More information about the Python-list mailing list