Python Productivity over C++

Martijn Faassen m.faassen at vet.uu.nl
Fri Jun 9 09:50:04 EDT 2000


Wim Lavrijsen <wlav at hpatl26.cern.ch> wrote:
> stevemul at ozemail.com.au (Steve Mullarkey) writes:

>>I have read in several places productivity claims of 5 to 10 times over
>>'C' and "C++". I would like to ask for some feedback from "C++"
>>programmers who have moved to Python as to whether these estimates are
>>realistic.

> I'm a C++ programmer (leave out the quotes ;) ).

> First off, any claim of an order of magnitude increase in productivity is
> pure nonsense. See Brooks for an explanation or Boehms and McConnell for
> hard data.

That's likely true. I do suspect there are more anecdotal examples of
"I did the same project in Python and I finished in half the time!" compared
to C++ than the other way around, but these aren't very scientific. Usually
the person already had experience with the problem domain before reaching
for Python, for instance. Still, Python is far more dynamic than C++ and
probably fits certain problem domains more naturally. I have a hard
time seeing Zope in C++, for instance.

> <snip enumeration of tools>

>>I don't want to start a flame war but, given the above, I just can't see
>>where the productivity increase is generated. I am genuinely interested
>>to ask "C++" programmers :-

>>1. What productivity increase do you achieve ?

>>2. How long did you use Python before you achieved increased
>>productivity ?

> I want to use Python for scripting tasks. I dislike 'ordinary' scripting
> languages as they lack the ability to recover from errors; a problem that
> Python, being a real programming language, does not have.

> Up to now, I've been using C++ for scripting. I'm not proficient in Python
> yet, so writing a Python script takes far longer than writing a C++ utility
> and the Python code itself is larger than the equivalent C++ code.

But then you must be very good at C++. :) (Hi Wim!) My experience was that I
was faster than C++ after a couple of days already. Note that I haven't had
any real experience with post-STL C++, which may or may not matter.

When you write a class in C++ and you want to do it *well*, you have to
think about a horrible amount of stuff; constructor, destructor, copy
constructor, assignment operator, possibly other operators, public, private,
protected. Without the STL you'll have to do lots of manual memory 
management as well; reallocating arrays, etc. If you want to write a
generic class there's a whole set of extra things to consider.
I found that this took a long time in C++, while whipping up a decent
class in Python is a piece of cake in comparison. Even generic Python
classes.

It's perhaps just a difference in philosophies as well; C++ is a statically
typed language and its proponents put a lot of emphasis on this kind of
correctness. In Python you might come up with lots of correctness rules
as well, but people don't, as the whole approach is different. People
rarely care about things like public/private, even. This also means a lack
of getters/setters in many cases; those will only be created if they
are deemed necessary. This means encapsulation can be broken easily,
but Python programmers don't care about this so much -- in practice often
it is more of a problem to strictly preserve encapsulation (and type safety)
than it is to fix any problems when and if they arise.

> What I expect from Python, is that I can reuse scripting utilities,
> something that I do not do for C++ utilities. This could, perhaps, yield
> a 10% increase in productivity, but I'm not writing scripts all day, so
> my overall productivity increase will be negligible.

I think that in quite a few problem domains more increase of productivity
can be seen, but it's extremely hard to measure and probably also
depends on the individual.

> Most of all, however, I enjoy the incremental coding (I come originally
> from a Smalltalk background). I *like* Python, which is all excuse I need
> to use it.

Right -- it's just plain fun. In my opinion, it's more fun than C++, where
the fun is really in dealing with its the dark side. :) So in many cases, 
I can have more fun coding in Python than in C++, while my productivity is
at least not adversely affected (and in many cases I believe positively
affected). Since run-time speed often doesn't matter, this means I'd rather
use Python in many cases.

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?



More information about the Python-list mailing list