[Numpy-discussion] matlab vs. python question
David Cournapeau
david@ar.media.kyoto-u.ac...
Wed Apr 25 21:38:09 CDT 2007
Brian Blais wrote:
> Christopher Barker wrote:
>> Sturla Molden wrote:
>>> It is
>>> also easier to write C or Fortran extensions for Matlab than for Python.
>> Really? I"m not so sure about that -- I found mex file writing pretty
>> painful.
>>
>> With weave, boost, pyrex, swig, f2py, etc, the hardest thing about
>> writing extensions for Python is choosing which tool to use!
>>
>
> I agree with Sturla here, up until Pyrex. Looking at the Python API, swig, f2py,
> etc. I found mex files far more straightforward. Mostly this is because of the
> (mostly) single datatype in Matlab: the double matrix. Having to do reference
> counting in the Python API is a drag.
It is a drag, but the matlab's way of doing things is totally broken,
not simple. The Matlab C api is one of the reason why I looked at python
in the first place. First, the memory management in mex files is
unusable for anything non trivial (for example, what happens if you do
Ctrl+C, but you are calling a function from a library which does malloc
? You're screwed; many 3rd party mex files crash when you use ctrl+C in
matlab). Also, wrapping with ctypes is really several order of magnitude
easier AND more powerful than mex files. One thing I use to impress
people used to matlab is to translate mex examples using ctypes: instead
of many lines of boring glue *in C*, a few lines of python
The other big drawback of matlab is the lack of data structures which
are not arrays. Cell is again, unusable for most things (most algorithms
do not work on them): in python, you have list and dictionaries, and
they certainly first class citizens in the language.
Finally, doing complex GUI is impossible in matlab. More generally,
doing things not directly related to numerical computing is really
difficult in matlab, because the language is not suitable for general
programming, and because of the totally brain damaged C api.
I've done a fairly big amount of matlab programming, and consider myself
quite familiar with it. I've done complex mex programming, even some
java programming for interacting between matlab and java list/hashmap,
etc... When you do those kind of things, the limitations of matlab are
striking. Matlab is simpler to use for simple things: for me, there is
no question about that fact. But python makes easy things just a bit
more complicated, and all other things possible. The perfect example is
namespace: not having namespace IS easier, at first. But this quickly
makes things unmanageable. Functions are easier in matlab, but when you
want to define function with many arguments and default values, this
also becomes quickly unmanageable.
David
More information about the Numpy-discussion
mailing list