[Numpy-discussion] How a transition to C++ could work
Sun Feb 19 03:10:24 CST 2012
> Date: Sun, 19 Feb 2012 01:18:20 -0600
> From: Mark Wiebe <email@example.com>
> Subject: [Numpy-discussion] How a transition to C++ could work
> To: Discussion of Numerical Python <NumPy-Discussion@scipy.org>
> Content-Type: text/plain; charset="utf-8"
> The suggestion of transitioning the NumPy core code from C to C++ has
> sparked a vigorous debate, and I thought I'd start a new thread to give my
> perspective on some of the issues raised, and describe how such a
> transition could occur.
> First, I'd like to reiterate the gcc rationale for their choice to switch:
> In particular, these points deserve emphasis:
> - The C subset of C++ is just as efficient as C.
> - C++ supports cleaner code in several significant cases.
> - C++ makes it easier to write cleaner interfaces by making it harder to
> break interface boundaries.
> - C++ never requires uglier code.
I think they're trying to solve a different problem.
I thought the problem that numpy was trying to solve is "make inner loops
of numerical algorithms very fast". C is great for this because you can
write C code and picture precisely what assembly code will be generated.
C++ removes some of this advantage -- now there is extra code generated by
the compiler to handle constructors, destructors, operators etc which can
make a material difference to fast inner loops. So you end up just writing
On the other hand, if your problem really is "write lots of OO code with
virtual methods and have it turned into machine code" (probably like the
GCC guys) then maybe C++ is the way to go.
Some more opinions on C++:
Sorry if this all seems a bit negative about C++. It's just been my
experience that C++ adds complexity while C keeps things nice and simple.
Looking forward to seeing some more concrete examples.
More information about the NumPy-Discussion