Python Variable System

Jonathan Gardner jgardner at jonathangardner.net
Wed Aug 13 12:39:10 EDT 2008


Nigel Rantor wrote:
> The Python system is the same as the Java system, apart from Java's 
> primitive types, which is a completely different discussion that I 
> really don't want to get into right now.
>
> So, everything is by reference.
>   
I am not too familiar with Java's system.
> I understand, and agree that a simple system is good. And maybe even 
> preferable. But it isn't always sufficient.
>
> Some algorithms are much easier to write if you know that your 
> parameters are going to be copied and that the function may use them as 
> local variables without having to explicitly create copies.
>   
If you could provide some specific examples, I would appreciate that.

As for me, using Python (and perl, which doesn't make copies when you 
are passing references around) extensively for large projects, I've 
never run into a case where that's bitten me. If I need to make a copy 
of any object, it's a one-line statement in Python. It's pretty rare 
that you do need to make copies of stuff, and it's pretty obvious where 
it needs to be done. I'm glad that it's very explicit.

> You can also reason more easily about what side-effects the function 
> could have if you know it cannot possibly modify your parameters.
>   
We can all keep track of where our hands are by wearing straitjackets as 
well.

As for me, I'd rather make vague promises and use my best judgment with 
complete freedom to deliver the best result.

> Other systems out there require pointer-like semantics (for example 
> CORBA out and inout parameters) which have to be kludged in languages 
> like Java to pass in wrapper objects/boxes that can be assigned values.
>
> Whilst it may be easier to learn a system like python/java, in the end 
> the amount of time spent learning the system is normally dwarfed by the 
> time spent using the system to build software.
I disagree with this. I find myself many factors more productive in 
Python than expert Java developers. I also find that I think about the 
problem while the Java developers are always thinking about how they can 
express themselves in Java properly.

You may want to spend some more time in Python. Once you abandon all of 
your Java-isms and perl-isms, then you'll find it quite relaxing. Most 
of my ramp up time in Python was leaving behind old ideas that were 
specific to the languages I already knew. It takes a while for one to 
realize that programming isn't supposed to be hard.

> I would rather have a type system that is as expressive as possible.
>   
Then you really should look at Haskell.

> Also, note that it is entirely possible to create many, many, many 
> interesting and useful things in Perl without having to resort to 
> references. They are a relatively new feature after all
It's true that Perl's reference system is relatively new, but I can't 
imagine writing even trivial scripts without references. (How do you do 
getopt without references?) The hacks people had to do in the past were 
horrifying. Yes, it's possible. No, it's not preferable.



More information about the Python-list mailing list