Development tools and practices for Pythonistas

Chris Angelico rosuav at gmail.com
Tue Apr 26 16:14:52 EDT 2011


On Wed, Apr 27, 2011 at 12:39 AM, snorble <snorble at hotmail.com> wrote:
> When I write a Python app, I have several unorganized scripts in a
> directory (usually with several named test1.py, test2.py, etc., from
> random ideas I have tested), and maybe a todo.txt file. ... The code is
> usually out of sync with todo.txt. I see people who release new
> versions and bug fixes, so I sometimes will create a new directory and
> continue working from that copy, because it seems like the thing to
> do. But if I ever made something worth releasing, and got a request
> like, "I have problems with the 2.0 version. Can you send me the old
> 1.1 version?"

As other people have said, version control is very handy. I use git
myself, but imho the choice of _which_ VCS you use is far less
important than the choice of _whether_ to use one.

As to the todo file - I tend to keep only vague ideas in a separate
file. Any todo that can be logically associated with a code file or,
especially, a particular piece of code, goes in that source file:

def function(parms):
    # TODO: This should check if Foo matches Bar and shortcut the computation
    ...

I have a very strict format: T, O, D, O, literal ASCII, always
uppercase. Makes it easy to grep (and I try to avoid "todo" in
lower-case, which means I can use a case-insensitive search if I
choose).

Additionally, if there's any task that will require checking of
multiple parts of the code, I'll create a keyword for it. For
instance, if I'm considering adding a local cache to an application to
reduce database traffic, I might do this:

//TODO CACHE: This will need to update the cache
...
//TODO CACHE: Read from cache instead
...
//TODO CACHE: Would this affect the cache?
... etc

The benefits of having the comments right beside the code cannot be
underestimated. Comments are far less likely to get out of sync if
they stare you in the face while you're changing the code - this is
why doxygen and friends are so useful.

Ultimately, it all comes down to discipline, and how important the
project is to you. At work, I have a lot of disciplines; we have a
wiki where stuff gets documented, we have source control, we have
daily backups (as well), etc, etc, etc. For little home projects, it's
not usually worth the effort. Take your pick, where do you want to go?

Chris Angelico



More information about the Python-list mailing list