Python vs C for a mail server

Magnus Lycka lycka at carmen.se
Wed Feb 1 08:25:24 EST 2006


Jens Theisen wrote:
> Jay wrote:
>> How much time in your C/C++ code is spent casting and trying to
>>trick the compiler into doing something that it thinks you shouldn't be
>>doing?
> 
> Not much frankly. Though I have no doubt that there is a lot of code that  
> does, but more so in older C++ code.

I think the real difference between Python and C++ code in this
respect is rather how easy it is to adapt the code to a change in
requirements. How many lines of code of C++ or Python needs to be
changed when you get a particular change request. There are some
cases where the Python programmer will simply smile and say, "that
already works" (well, he should probably write a test case and run
that first), where the C++ programmer gets to do a lot of changes
to his code. Usually, the difference is probably smaller than that,
but the Python coder is probably less nervous about change requests
(provided that he has proper automated tests)...

There is probably more logical duplication in the C++ code, with
different code snippets handling different cases where one set of
Python code works with several differnt types. Changes in the
semantics of these functions lead to changes in one place for the
Python coder, and several changes for the C++ coder, which means
a risk that a fix is partially implemented, and works in some cases
but fails in others.

>>Because in all of my own industry experience, it's been MUCH easier to
>>jump into someone else's Python code than someone else's C++ code (and
>>at my last job, I had to do a lot of both). I find Python to be much
>>more self-documenting, because there's not so much scaffolding all over
>>the place obfuscating the true intention of the code.

I'm sure this depends a lot on what people are used to.
I had to provide source code for inspection for a job
interview, and the reviewers (who write both C++ and
Python) said that they felt that my code was more difficult
to understand than the other code samples (which were in
C++ or Java). (I still got a job though.)

This might be because I'm a crappy programmer, or because
the other people typically handed in some university project
they had been fully in charge of and written for the purpose
of examination, while my code had been changed over a few
years based on the whim of a fairly non-technical customer,
and only ever read by me. It might be because my code dealt
with a more complex problem, or at least something that was
difficult for the reviewers to grasp. It could also be because
the reviewers were more used to C++. They said that they felt
that the lack of .h-files made it difficult for them to get
an overview of the code, but it didn't seem that they used
anything like pydoc to get a picture of the API. In other
words, your milage might vary, and the choice of programming
language is just one among many factors that influence how
easy it is to read code.

Having said that, I agree: It's typically easier to get into
someone else's Python code. Particularly when so-called C++
code is really C with lots of globals, no classes and 63
pages of functions (many of which are several pages long,
the longest being 13 pages) which often modify the global
variables. (Yes, I have such a nice thing on my table now.
Happily, I don't have to maintain it. I'm writing a Python
program that partially does the same thing, but I doubt this
program will help me understand the problems involved, or
help me find optimal solutions...)



More information about the Python-list mailing list