Using Python for programming algorithms

Lie Lie.1296 at gmail.com
Sun May 18 04:57:26 EDT 2008


On May 18, 5:32 am, Vicent Giner <vgi... at gmail.com> wrote:
> Hello.
>
> I am new to Python. It seems a very interesting language to me. Its
> simplicity is very attractive.
>
> However, it is usually said that Python is not a compiled but
> interpreted programming language —I mean, it is not like C, in that
> sense.
>
> I am working on my PhD Thesis, which is about Operations Research,
> heuristic algorithms, etc., and I am considering the possibility of
> programming all my algorithms in Python.
>
> The usual alternative is C, but I like Python more.
>
> The main drawbacks I see to using Python are these:
>
> * As far as I understand, the fact that Python is not a compiled
> language makes it slower than C, when performing huge amounts of
> computations within an algorithm or program.

It is slower than a goodly written C code. C codes might be slower
than Python if the writer of C isn't very familiar with C, on the
other hand Python's implementation of things like list, dictionary,
sets, etc are a very optimized piece of code (some says it's the most
fine tuned implementation in the world) and a sloppily written array/
dict/sets implementation in C might be slower than Python.

> * I don't know how likely it is to find libraries in Python related to
> my research field.
>
> * I know Python is a "serious" and mature programming language, of
> course. But I do not know if it is seen as "just funny" in a research
> context. Is Python considered as a good programming language for
> implementing Operations Research algorithms, such as heuristics and
> other soft-computing algorithms?

Why not ask your peers? AFAIK (since I'm not a researcher, just a high-
school student with a "too much time" to program, I'm not even
familiar with Operation Research), in a Operation Research context (as
I understand it from wikipedia) the important thing is the algorithm
instead of pure speed, and codes are written just to describe the
algorithm you're devising. So any programming language that isn't an
esoteric language (like Whitespace or Brainfuck) would not be
considered a "just funny".

> Maybe this is not the right forum, but maybe you can give me some
> hints or tips...
>
> Thank you in advance.


On May 18, 11:37 am, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> On Sat, 17 May 2008 20:25:18 -0700 (PDT), Henrique Dante de Almeida
> <hda... at gmail.com> declaimed the following in comp.lang.python:
> >  My opinion: choose compiled or byte compiled languages. Choose the
> > language paradigm that best suit the algorithms.
>
>         Python IS byte compiled -- that's what .pyc and .pyo files contain
> (strangely though, one must specify a command line argument to get the
> "optimized" .pyo, rather than the .pyc with debugging data embedded).

Just to note, currently, "optimized" python code (using -O or -OO)
does very little to make your code goes faster as it doesn't (yet) do
anything but removing docstrings. The -O(ptimized) flags is reserved
to make it possible to add optimizations that might make some features
unavailable or behave differently (such as the docstrings removal that
breaks codes that uses __doc__).



More information about the Python-list mailing list