Python vs C++

Stefan Behnel stefan_ml at behnel.de
Fri Aug 22 02:44:54 EDT 2014


dieter schrieb am 22.08.2014 um 08:12:
> David Palao writes:
>>  Why to use C++ instead of python?
> 
> Likely, you would not use Python to implement most parts of an
> operating system (where, for efficiency reasons, some parts
> are even implemented in an assembler language).
> 
> I can imagine that the GNU compiler developers, too, had good
> reasons to implement them in C rather than a scripting language.
> It makes a huge difference whether you wait one or several hours
> before a large system is built.
> 
> "firefox", too, seems to be implemented in C/C++. There, too, I
> see good reasons:
>   *  it is nice when your pages are rendered quickly
> 
>   *  "firefox" depends on lots of external libraries, all of them
>      with C/C++ interfaces; while is is possible to create
>      Python bindings for them, this is quite some work
> 
>   *  as it is, "firefox" is a huge "memory eater"; one might
>      fear that things would be worse if implemented in a
>      higher level language (with everything on the heap).
>      Though, the fear might not be justified.
> 
> 
> All these examples are really large projects. I like Python a lot
> for smaller projects.

While I agree that there are very valid reasons to write C/C++ code (and
operating systems clearly fall into that category), most of the above might
turn out to be fallacies. With a more high-level language, it is easier to
get a system running and then focus on optimisation than in a low-level
language that requires a lot of concentrated work just to get things done
at all. Especially in the long run, where the maintenance burden of
low-level code starts getting so much in the way that it becomes harder and
harder to keep improving the system and adding new features.

If, instead, you start with a high-level language, your first
implementation might not be as fast as your first C++ implementation could
have been, but it'll be almost certainly available much earlier, so that
you can then give it real world testing and performance evaluation. That
gives you a head start for optimisation and improvements, which then leads
to a faster system again. Thus, it's not unlikely that you already get an
even faster and better system (in terms of actual user experience) in the
same timeframe that you would otherwise have spent on getting even a first
working version of your system in a low-level language.

And the optimisation that you apply to your system may still include
rewriting parts of it in C++, but then really only those parts where real
world evaluation proved that it's worth the effort and maintenance overhead.

I've given a talk about this topic at PyCon-DE 2012. It's in German, but it
contains a lot of figures that should be understandable even if you don't
understand that language.

http://consulting.behnel.de/PyConDE/2012/ohnecpp.html

Stefan





More information about the Python-list mailing list