Why I love Python: More rambling...

Bryan belred1 at yahoo.com
Sat Nov 1 23:07:31 EST 2003


> 
> Data point (real world, from a few weeks ago): after spending ~2 weeks (spread
> over a month) writing about 1400 lines of C++, debugging a nasty coredump, and
> pounding the documentation, I had my 'fast' extension module finished for some
> numerical work.  Great, sweaty and exhausted but all proud of myself, I turn
> my attention to the problem of writing a unittest.  I decided to write it in
> python, since I figured it would be easier, and an independent implementation
> of the algorithm (simple one) should suffice, if tested with enough random
> data.
> 
> Python code: 15 lines (no, it's NOT a typo: fifteen).  Time to write it: 10
> minutes.
> 
> The sad part (to my ego, at least:)?  The python runs faster!  The C++ version
> is now in the dustbin.  At least I learned a bunch about the STL and
> templates.  The consolation...
> 
> Cheers,
> 
> f.
> 
> ps for those thinking: you must be an idiot of a C++ programmer. That may well
> be true.  But still, there are reasons for the difference.  The C++ version
> uses a heavily templated library for handling multidimensional arrays with a
> bearable syntax, and g++ isn't the best compiler out there for that kind of
> code.  The python version relies on Numeric.innerproduct(), which is very well
> optimized, and tackles head-on the problem I was avoiding with the templates,
> namely very annoying pointer manipulations for multidimensional tensors.  The
> Numeric guys got their hands dirty, did it once RIGHT, and it works extremely
> well.


i don't think this is an apples-to-apples comparison.  in c++ you wrote everything yourself.  in python, you used the 
numeric package which someone else wrote.  i'm interested in knowing _why_ you chose to write it yourself in c++. and 
_why_ you didn't try to write it yourself in python, but instead chose to use an already written library.  i just did a 
google search for "open source c++ numeric" and got several hits.  i'm not putting you down in any way. i'm just 
interested in knowing why you made these different decisions for each language.

bryan





More information about the Python-list mailing list