LOC in Python and C++ in large projects

Adriaan Renting renting at astron.nl
Fri Jul 1 08:55:44 EDT 2005


I think the point you want to make is that Python needs vastly less
lines of code as a similar application written in C++. I think Python
might on average be 50-60% of comparable C++ code, but not the 1-2% you
seem to want to claim. LOC is a somewhat arbitrairy measurement, but it
gives an idea of what I'm talking about.

Your single example compares a simple use in Python with a much more
elaborate framework in one of the worst C++ IDE's I know. I can easily
give you a counter example:
If I create a simple form in Eric3 it will generate about 500-600 lines
of Python too.
When using this in actual code the difference between a piece of C++ and
Python would however be mostly cosmetic:
void MyForm::exitFile()
{ close();
}
------------ vs. ----------------
def exitFile(self):
    self.close()

Your example is very good at demonstrating why Python is very useful for
simple and small projects. Simple programs are simpler in Python.
All programming languages can be used to write horrible unreadable and
inefficient code. Therefore I think it's better to compare best cases as
it is to compare worst cases.

In the large projects I've worked on most of the code has nothing to do
with external libraries or IDE generated code, but only with other parts
of the project and most of the advantages Python has in small simple
projects are uninportant.
I think C++ gives a little more tools to keep large projects manageable,
mostly because you can find a lot more communication failures between
programmers at compile time.

I think the choice of a programming language is not very important in
determining the overal succes of a project. C++ and Python are however
my two favorite languages.

I think it would be interesting if any readers with more experience as I
have would comment on how Python behaves in large projects, and how much
less lines they need compared to C++ or Java.
I have worked on several C++ projects with a few million lines of code,
I would appreciate experience with comparable projects. (can you do it
in 10.000 Lines of Python?)

>>> Thomas Heller <theller at python.net> 07/01/05 11:36 AM >>>
Thomas Heller <theller at python.net> writes:

> "Adriaan Renting" <renting at astron.nl> writes:
>
>> I'm not a very experienced Python programmer yet, so I might be
>> mistaken, but there are a few things that would make me prefer C++
over
>> Python for large (over 500.000 LOC) projects.
>> - namespaces
>> - templates
>> - strong type checking
>> - data hiding
>> - more available libraries and more advanced developement tools.
>>
>> I'm talking about managing the code, not the programmers, the project
or
>> schedules or what have you. Those are independent from the chosen
>> programming language.
>
> Just a single datapoint: Implementing a trivial COM object in Python
> requires, let's guess, about 10 or 20 lines of source code.
>
> When I do the same in MSVC6, the wizard creates 10 files, with nearly
> 400 lines of code.  Sure, I didn't have to write these code lines, but
> I'm required to understand and manage them as well.

Sorry, I forgot to include the .dsw and .dsp files in the above figure.
Including them brings the LOC count up to 750 for the C++ project -
although, to be fair, on the Python side a setup.py script for py2exe
would also have to be written.  In simple cases, this is another 10
lines.

Thomas
-- 
http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list