Collective memory (was: Good code patterns in Python)

Andrew Bennetts andrew-pythonlist at puzzling.org
Sun Jul 6 00:44:06 EDT 2003


On Fri, Jul 04, 2003 at 11:08:33PM -0400, Charles Shannon Hendrix wrote:
> 
> Python uses it for actually determining the logic in your program, which
> IMHO is dangerous.
> 
>     if <something>
>         <work>
>         <more work>
>         <add numbers>
> 
> Is <add numbers> part of the if statement, or did someone with different
> tab settings from the author make a mistake and align it accidentally?

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();

Is add_numbers() part of the if statement?  No.  Did the author intend it to
be?  Maybe.  You can't tell.  They've indented it to imply one way, but it
actually works another way.

Given that you should indent your code to reflect the structure anyway,
Python simply discards the redundant punctuation, and avoids this sort of
ambiguity.  "There should be one-- and preferably only one --obvious way to
do it."

> One really funny problem was when I guy reformatted his Python code,
> around 15K lines of it, and basically unindented *ALL* of the code to
> column 1.  It was the only recoverable copy of the code too.
> 
> He had to read the entire program line by line to recreate the logic.

"Doctor, when I randomly corrupt my source, it doesn't work anymore!"

"So don't do that then."

As another poster pointed out, deleting e.g. all the asterisks from C code
would be equally painful.  It's not Python's fault that guy wasn't using a
version control system.

-Andrew.






More information about the Python-list mailing list