Collective memory (was: Good code patterns in Python)

Michael Sparks zathras at thwackety.com
Sun Jul 6 19:50:57 CEST 2003


On Fri, 4 Jul 2003, Charles Shannon Hendrix wrote:
>     if <something>
>         <work>
>         <more work>
>         <add numbers>

If this is solely tabs, this is unambiguous with no special rules needing
invocation. If this is spaces, again, this is unambiguous with no special
rules needing invocation.

If this is tabs and spaces mixed, then this looks ambiguous, and you need
to look at special rules. That said, if you have one user who uses // for
comments in C++ and another who exclusively uses /* */ what happens when
the first user attempts to comment out the block of code by the second
user?

Also C has more corner cases due to allowing its block structure
delimiters being slightly inconsistant than anything else.

After all without checking how many C programmers could say what this
means:

if (<test>)
if (<another test>)
<do something>
else
<do otherthing>

Is that:
   if <test>
      if <test>
         <do something>
      else
        <do something>

Or is it:
   if <test>
      if <test>
         <do something>
   else
      <do something>

The "problem" really boils down to choosing to use language features
inconsistantly. This applies to C, C++, Python, Perl (eg allowing
whitespace in regexes or not), and even functional languages. You might
choose to always use braces for blocks even where not necessary, always to
use tabs rather than spaces (or vice versa) and so on.

In python I personally tend to find that only having one major decision to
make - spaces vs tabs actually makes interaction with others code a lot
simpler.

> 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.

I changed all the permissions in /etc once by accident as well. (to 777
IIRC) This quite spectacularly busted my system, and that took a long
while to sort out. At the time that was probably a similar number of lines
affected by a pretty stupid simple action.

What's the moral? Backup regularly and often and especially before doing
something that touches a significant amount of stuff. (Where significant
means >2 hours to fix) It certainly isn't "permissions are bad", nor
"whitespace is bad".

Inconsistent functionality abuse combined with stupidity is pretty hard
for any system to cope with...

Regards,


Michael.






More information about the Python-list mailing list