About reading Python code

Jeff Schwab jeff at schwabcenter.com
Mon Mar 17 21:29:17 EDT 2008


sturlamolden wrote:
> On 17 Mar, 04:54, WaterWalk <toolmas... at 163.com> wrote:
> 
>> So I'm curious how to read code effectively. I agree that python code
>> is clear, but when it becomes long, reading it can still be a hard
>> work.
> 
> First, I recommend that you write readable code! Don't use Python as
> if you're entering the obfuscated C contest.

Er, don't use anything other than C if you're entering an obfuscated C 
contest, or anything other Perl for an obfuscated Perl contest, etc.

Do use Python if you're entering an obfuscated Python contest.  Found 
online:

[#[#[#[#[#[#[#[#[# By TaroOgawa #]#]#]#]#]#]#]#]#]


                      globals()
                .update({   "______":
             lambda x:         globals()
             .update((         dict([[x]
                *2])))}),   ______(((
                      "Just")))
                ,______((   "another"
             )),______         ("Python"
          ),______(               "Hacker")
          ];print (               " ".join(
             [(Just),(         (another)
                ),(Python   ),Hacker]
                      ));______


> Two particularly important points:
> 
> * If you find yourself thinking this module is too long, that's
> probably what it is. Half a page of code per module is fine. Two pages
> of code per module can be too much.
> 
> * Comments are always helpful to the reader.

If only 'twere so.  *Good* comments are always helpful.  Please do not 
comment every method with "this is a method" or the like.  One of the 
things that often makes newb code stand out is that the programmer 
couldn't tell the things that needed to be commented from the places 
where comments just got in the way.

> Second, I recommend getting a good IDE. E.g. pick one of:
> 
> * Microsoft Visual Studio (commercial)
> * Eclipse with PyDev and CDT (free)
> * SPE (free)
> * ActiveState Komodo IDE (commercial)

* Vim on Linux.  (No desire here to debate the meaning of IDE, but with 
Vim or Emacs on any Unix-like platform, the whole system effectively is 
the IDE.)



More information about the Python-list mailing list