C++ or Python

Nick Dumas drakonik at gmail.com
Sat Jun 28 02:53:14 CEST 2008

Hash: SHA1

Kurda Yon wrote:
> I would like to know what are advantages of Python in comparison with C
> ++? In which cases and why Python can be a better tool than C++?
> Thank you!
I'm a relative novice, so I couldn't tell you about deeply hidden
features or tricks, but there are a few advantages which influence my
choice to code in Python.

1) Portability. A well-written Python app is 100% system agnostic.
Sometimes, you just have to get dirty and make calls directly to the
system, but if you're creative, you can make do with pure Python calls.
This means that there's no porting of code. You don't have to maintain a
version for *nix's, a version for Windows XP, a version for Vista, and a
version for OS X. Although different versions for each allow for
fine-tuned optimization for individual systems, it's a hell of a lot of
work to take care of all that code.

A subset of this is that Python isn't compiled. With C++, even if your
code is completely system agnostic, you must compile a linux version, a
win32 (and nowadays, maybe even a 64) version, and a map version. With
each added compilation, you add the potential for bugs, breakage, and
other nastiness.

2) Python's coding style. This is a really broad category and great
subjective. I LOVE the whitespace coding. It makes code blocks really
look like blocks. Loops and if-elif-else blocks are clearly defined, and
it helps for maintenance, and it just makes my code look pretty.

Python also looks like English. My familiarity with the language has
some to do with it, but I can just READ the code. I don't have to write
down numbers and then look back to the code and try to interpret the
code. It reads like English.

3) I suppose it's sorta cheating to add Python's interpreted-language
status again, but it's worth reiterating, and an excellent example of
this will be illustrated by this story:

For one of my classes, we're allowed to do any kind of project we wanted
(assuming it was something school appropriate). I decided to code a
Dungeons and Dragons 3.5 Character stat generator in Python. On the day
my project was evaluated, I realized there was a bug in my code. Because
of some funky index slicing, numbers were being cut off. Thanks to
Python being interpreted rather than compiled, I was able to correct the
bug ON SITE, and present the properly functioning code.

4) Extensive libraries. Python has a vast, active community developing
libraries for just about anything you could ant. Pygame, Scipy,
wxPython, any kind of toolkit for any kind of job imaginable. The ease
of obtaining these tools helps me spend time on exercising my creativity
and coding skills, rather than spending time trying to find libraries
that do what I need.

Your mileage may vary, but for me, Python provides a reliable, portable
platform for things that I want or need. Yeah, for heavy-duty things
like gaming, heavy gaming, not tetris or Snake, C or C++ where memory
management is more available to the programmer is preferable. But for
everyday "I need to make a tool in 15 minutes" needs, Python's perfect.
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


More information about the Python-list mailing list