Python vs C for a mail server

Randall Parker techiepundit at futurepundit.com
Tue Jan 31 12:10:54 EST 2006


Alex Martelli wrote:

> The "but without declaration it can't be self-documenting" issue is a
> red herring.  Reading, e.g.:
>
> int zappolop(int frep) { ...
>
> gives me no _useful_ "self-documenting" information about the role and
> meaning of frep, or zappolop's result.  The code's author must obviously
> add a little comment here to clarify -- and in that little comment,
> adding the information about type, if at all relevant, is an obvious
> task.

Yes, one can use such simple types that the types do not tell you that
much. They do tell you something though. The arg and return types are
not list structures for example. They aren't floats either.

However, C/C++ at least provide a way to make types tell you far more.
For example, one could declare enum types:

typedef enum MyArgType
{
   // a bunch of enum const names here
} MyArgType;
typedef enum MyResultType
   // another bunch of enum const names
} MyResultType;

Then your example above becomes

MyResultType zappolop(MyArgType frep) { ...

 and that's a lot more insightful.

I return objects in Python and in C++. In C++ I can see what their
types are right on the m method signature. In Python I've got to write
a comment on the line above it. If I change what type I return and
forget to change the comment then the code isn't correctly documented
anymore. I've done recently and found out with a runtime error while
testing the Python. In C++ if I'd changed the return type the compiler
would have told me if I didn't use it that way somewhere else.

There are a lot of stages at which to reduce the chance of bugs. While
coding an editor can give you more help with code completion if you
have more static typing. At compile time the compiler can tell you
about errors if it knows the types you are using.

I use PyChecker and PyLint and while they are incredibly helpful (and
I'm grateful to their authors just as I am to Python's developers) they
do not tell me as much as Borland's C++ compiler does. I get more
runtime errors with my Python code than with my C++ code.

Still, I find Python useful and better than C++ in some situations.
But I wish it provided better options for allowing me to indicate types
so that more errors could get caught sooner and so that editor code
completion could be smarter.




More information about the Python-list mailing list