example sources in both Python and C++
Daniel Berlin
dberlin at redhat.com
Mon Oct 2 20:06:58 EDT 2000
wmcclain at salamander.com (Bill McClain) writes:
> Here is something for the beginning Python programmer, or
> anyone who wants to compare the language with C++.
>
> I have put up an astronomical package implemented in both
> Python and C++. It is just a subroutine library and a few
> simple applications, all with console interfaces:
>
> http://astrolabe.sourceforge.net/
>
> This is probably not the best example for language comparison,
> in that most of the code is numerical and would look much
> the same in Fortran. But comparing cronus.py with cronus.cpp
> gives some idea of how tasks are approached in both languages.
>
> Some notes from the home page:
>
> Years ago, I originally wrote the astrolabe routines in C. Now, I
> always implement in Python first, then make a C++ version as a
> more-or-less direct translation. The C++ source has a lot of
> compromises required for compatability with different compilers,
> which are, however, getting closer to the standard with time.
>
> The Python sources are obviously more compact than the C++
> versions and have less declarative overhead. To me, the most
> unfortunate aspects of C++ are:
>
> * STL containers cannot have initialization lists, meaning that
> inline data must first be held in C-arrays, then copied to
> the containers at run-time. I use some macros to make this a
> bit more natural-looking.
Yes, this sucks.
> * Template arguments cannot be local types. That means STL
> containers must use types declared at the outer scope, which
> is ugly.
Wait, what?
Explain what you mean, this is confusing.
If you mean you can only use types in the outermost, or global scope,
as template arguments, your compiler is severely broken.
> * Functions may not return multiple values. Where Python can
> have:
>
> ra, dec = func()
>
> C++ requires:
>
> void func(double &ra, double &dec);
> double ra, dec;
> func(ra, dec);
>
> ...or a struct for a return value, which would require more
> declarations. In an alternative C-like language, this would
> be just as strongly-typed as the function shown above:
>
> double, double func()
> double ra, double dec = func();
You could overload operator , for a tuple like class, and use that
>
> -Bill
> --
> http://www.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list