Good practice when writing modules...

bearophileHUGS at bearophileHUGS at
Sun Nov 16 08:58:21 CET 2008

John Machin:
> > import foo # used by baz()
> > import bar # used by spam()
> Why bother with the ()?

I code in other language too beside Python, in those languages there
are other things (like templates in D language) beside functions, so
my comment helps me remember that baz() is a function instead of a
template written in lowercase: baz!().

> Why bother at all?

If I remove a function/class that uses baz from the module, I can go
at its top and find in a short time what imports to remove. Probably
there are other purposes too.

> Do you remember to adjust the comment when a function/class is changed
> so that it doesn't use the module any more?

Most of the times yes. Even if I forget doing it 2%-5% of the times,
it's worth it, for me. Notice that I have just shown what coding
practices seem currently good for me, for certain kinds of programs,
etc. Feel free to use your own.

> Your modules are callable???

No, they aren't, it's a mistake of mine, sorry.

> > Time ago I have read an interesting article that says that comments of
> > today will often become statements and declaration and tags of
> > tomorrow, that is stuff that the interpreter/compiler/editor
> > understands. This means that such annotations of mine may be something
> > fit to become a syntax of the language.
> I hope not.

Can you explain why you don't like my idea?


More information about the Python-list mailing list