Why learn Python ??
John J. Lee
jjl at pobox.com
Wed Jan 14 15:40:16 EST 2004
"Derek" <none at none.com> writes:
> "John J. Lee" wrote:
[...]
> > for the
> > great majority of projects, optimisation does not require
> > implementation of the *entire* system in a language like
> > C++. The sum of C++ and Python is greater than the parts.
>
> Python and C++ can also be a bigger mess than sum of either part.
> Take your pick.
Not entirely sure what you mean, so I'll try and restate it:
You're saying that the C++ code for a Python extension is uglier than
the equivalent C++ code you'd write for a pure-C++ solution, where the
C++ code in question is that used to solve the *small part* of the
*whole* problem that you've farmed out to C++. Right?
Actually, I think that's only true if you're writing wrappers in C on
the C API level. Leaving that important point aside, though, the
choice we're discussing here is between:
1. Most code in Python, plus small amount (say 10 percent) of C/C++
code plus ugly code to wrap it (or the latter two mixed up
together, if you prefer).
2. All code in C++.
For cases where it meets the performance requirements, 1 is preferable
to 2 because, even given an overhead of ugliness (which I dispute,
thanks to SWIG and Boost Python) in that 10 percent of the problem
recoded in C++, you make a saving on the other 90 percent that (far!)
more than compensates. A ratio of 5-10 in terms of lines of code is
often quoted, and that ratio applies to 90% of the project.
John
More information about the Python-list
mailing list