Python advocacy in scientific computation

Duncan Booth duncan.booth at invalid.invalid
Sun Mar 5 15:44:33 EST 2006


sturlamolden wrote:

> First there are a few things I don't like:
> 
> 1. Intendation as a part of the syntax, really annoying.

Each to his own. I find having the compiler enforce indentation rules is a 
real benefit. There's nothing quite so annoying as having 'coding 
standards' you are supposed to be following which aren't enforced (so 
nobody else working on the code followed them either). C code which never 
executes a for loop because of a spurious ';' can be pretty annoying too.

> 
> 2. The "self.something" syntax is really tedious (look to ruby)!

I find it really useful to use a similar style when programming in other 
languages such as Java or C#. In particular it means that you can 
instantly see when you are referring to a member variable (without 
having to prefix them all with m_ or some other abomination) and when you 
have method arguments which get assigned to member variables you don't have 
to think of different names for each.

> 
> 4. Multithreading and parallel execution is impossible AFAIK because of
> the so-called GIL (global interpreter lock). Matlab is perhaps even
> worse in this respect.

Multithreading and parallel execution work fine. The only problem is that 
you don't get the full benefit when you have multiple processors. This one 
will become more of an annoyance in the future though as more systems have 
hyperthreading and multi-core processors.

> 
> And there is a couple of questions I need answered:
> 
> 1. Can python do "pass by reference"? Are datastructures represented by
> references as in Java (I don't know yet).
> 
Python only does "pass by reference", although it is more normally referred 
to as "pass by object reference" to distinguish it from language where the 
references refer to variables rather than objects.

What it doesn't do is let you rebind a variable in the caller's scope which 
is what many people expect as a consequence of pass by reference. If you 
pass an object to a function (and in Python *every* value is an object) 
then when you mutate the object the changes are visible to everything else 
using the same object. Of course, some objects aren't mutable so it isn't 
that easy to tell that they are always passed by reference.



More information about the Python-list mailing list