Python vs C++
Neil D. Cerutti
neilc at norwich.edu
Thu Aug 21 09:42:41 EDT 2014
On 8/21/2014 8:54 AM, David Palao wrote:
> Hello,
> I consider myself a python programmer, although C++ was one of the
> first languages I learned (not really deeply and long time ago).
Hey, that sounds just like me.
> Now I decided to retake C++, to broaden my view of the business.
> However, as I progress in learning C++, I cannot take out of my head
> one question
I have gone back and attempted to use C++ again a couple of times, but
<spoiler> it turns out to not be worthwhile in my current position.
> Why to use C++ instead of python?
>
> It is not ranting against C++. I was/am looking for small-medium
> projects to exercise my C++ skills. But I'm interested in a "genuine"
> C++ project: some task where C++ is really THE language (and where
> python is actually a bad ab initio choice).
> The usual argument in favour of C++ (when comparing to python) is
> performance. But I'm convinced that, in general, the right approach is
> "python-profiling-(extension/numpy/Cython/...)". At least for a python
> programmer. I might be wrong, though.
Python, for me, is the ultimate translator and aggregator of data. I use
it constantly to get data from one place, combine it with some other
data over there, fiddle with it, and spit it out in some usable manner.
I could certainly use C++ for my projects. I think the standard
containers, iterators, and algorithms provided in the STL are beautiful.
Simple things can be relatively simple in C++, when I use the right
parts of it. But in that case C++ doesn't provide me many
benefits--virtually zero. Python's immutable strings and hash-based
mapping type can even be faster than C++ in some cases. But I simply
don't need efficiency. My longest running program takes less than 3
seconds to complete, and that's plenty fast for my purpose. The archaic
separate compilation/linking model and the complication of static type
declarations seem a pain in the ass that I don't benefit very much from.
The one program I needed that was just horribly slow in Python involved
trying to match up names in a fuzzy manner between two systems, to help
me find students who couldn't be bothered to get their own social
security number correct. This took nearly 20 minutes to run. But,
ummm.., it turned out I was doing the wrong thing. Even students who
can't remember their SSN mostly got their phone number or email address
correct, it turns out.
There's a tall stack of stuff *not* written in Python that I depend on,
though: Python itself, sqlite3, gvim, Windows 7, etc. At this point I
feel hopelessly unqualified to write any of that stuff, but if I had to,
I'd need to resuscitate my C++, or at least my C, as a starting point.
There's a growing number of projects hoping to bridge an apparent gap
between Python and C. C++ can be regarded as an early effort--so early
that there was no Python to measure against. Maybe it would've turned
out better if there had been. ;)
Python developers are filling part of the gap with libraries, e.g.,
numpy and scipy. I could take advantage of numpy by installing Pandas;
I'll learn Pandas long before I resort to C++.
--
Neil Cerutti
More information about the Python-list
mailing list