Python in a desktop environment

Duncan Booth duncan.booth at invalid.invalid
Sun Mar 11 06:22:54 EDT 2007


"David Cramer" <dcramer at gmail.com> wrote:

> On Mar 10, 10:52 pm, "sjdevn... at yahoo.com" <sjdevn... at yahoo.com>
> wrote:
>> David Cramer wrote:
>> > If you had an application that you were about to begin development on
>> > which you wanted to be cross platform (at least Mac and Windows),
>> > would you suggest using c++ and Python?
>>
>> I'd strongly consider a pure python solution (I'd choose wxpython),
>> but if I needed to code backend stuff in a lower level language I'd
>> use C rather than C++.
> 
> Well we want it to be very robust, and python isn't exactly the
> fastest language, or one with the lowest overhead :)
> 
So if you want it to be robust it's a no brainer: Python and no C++ or C.

I'd advise you to start off doing it in pure Python, then when you get it 
working see if it is fast enough, and if not profile it and find the 
bottlenecks. Those bits which really do need speeding up you should then 
rewrite using Pyrex, which won't take long at all since it is basically the 
same syntax. Also see whether Psyco helps.

Python can be slow, but if you leverage the built in functionality 
correctly you'll find it isn't much slower than C/C++ for many tasks, and 
can even be faster than you would get from C/C++ without a spending a very 
long time optimising it (that's because people have already spent a very 
long time optimising Python's builtin functionality).

Even if you do eventually find you have to rewrite parts of the code in 
C/C++ you should first have done what you can to optimise it in Python. 
Usually the best way to speed up something which is too slow is to use a 
different algorithm. That sort of change is comparatively easy to do in 
Python but an expensive programming exercise in C/C++. When you come to 
reimplement it then you'll be converting the already optimised code, which 
in many cases will be much easier than writing it in C/C++ from scratch.

If you look at http://page.mi.fu-berlin.de/~prechelt/Biblio/jccpprtTR.pdf 
you'll see that, at least for that task, the relative runtimes for C/C++ 
and Python widely overlap. Yes, the C/C++ implementation included some very 
fast ones, but they also included slows ones (and only Python of all the 
languages tested had no unusable implementations). OTOH, time to write the 
programs does not overlap. Of course, since that paper was written Python 
has changed a lot.



More information about the Python-list mailing list