Re: The future of Python immutability

2009-09-08 Thread Steven D'Aprano
On Tue, 08 Sep 2009 11:23:05 -0700, Daniel Fetchinson wrote: >> How does Matlab speed compare to Python in general? Ruby, for example, >> is an order of magnitude slower than Python (at least it was last time >> I looked) > > For what operations? Under what circumstances? I'm just being pedantic

Re: The future of Python immutability

2009-09-08 Thread Daniel Fetchinson
>> > Is the difference because of mutability versus immutability, or >> > because of C code in Numpy versus Matlab code? Are you comparing >> > bananas and pears? >> >> It consisted of something like this > > > Your code does a lot of unnecessary work if you're just trying to > demonstrate immutabi

Re: The future of Python immutability

2009-09-08 Thread John Nagle
Steven D'Aprano wrote: On Tue, 08 Sep 2009 09:38:51 +0200, Hendrik van Rooyen wrote: On Monday 07 September 2009 20:26:02 John Nagle wrote: Right. Tracking mutablity and ownership all the way down without making the language either restrictive or slow is tough. In multi-thread progr

Re: The future of Python immutability

2009-09-08 Thread Steven D'Aprano
On Tue, 08 Sep 2009 09:38:51 +0200, Hendrik van Rooyen wrote: > On Monday 07 September 2009 20:26:02 John Nagle wrote: > >> Right. Tracking mutablity and ownership all the way down without >> making the language either restrictive or slow is tough. >> >> In multi-thread programs, though,

Re: The future of Python immutability

2009-09-08 Thread Paul Rubin
Hendrik van Rooyen writes: > In any case - if you do not actually like juggling with knives, then you > should not be mucking around with concurrency, and by making the language > safe, you are taking the fun out. Oh come on, Erlang and Haskell both take care of it rather well. -- http://mail.

Re: The future of Python immutability

2009-09-08 Thread Hendrik van Rooyen
On Monday 07 September 2009 20:26:02 John Nagle wrote: > Right. Tracking mutablity and ownership all the way down without > making the language either restrictive or slow is tough. > > In multi-thread programs, though, somebody has to be clear on who owns > what. I'm trying to figure out

Re: The future of Python immutability

2009-09-07 Thread Paul Rubin
John Nagle writes: > Right. Tracking mutablity and ownership all the way down without > making the language either restrictive or slow is tough. > > In multi-thread programs, though, somebody has to be clear on who owns > what. I'm trying to figure out a way for the language, rather tha

Re: The future of Python immutability

2009-09-07 Thread John Nagle
Graham Breed wrote: John Nagle wrote: In the beginning, strings, tuples, and numbers were immutable, and everything else was mutable. That was simple enough. But over time, Python has acquired more immutable types - immutable sets and immutable byte arrays. Each of these is a special cas

Re: The future of Python immutability

2009-09-07 Thread Graham Breed
John Nagle wrote: In the beginning, strings, tuples, and numbers were immutable, and everything else was mutable. That was simple enough. But over time, Python has acquired more immutable types - immutable sets and immutable byte arrays. Each of these is a special case. Immutabil

Re: The future of Python immutability

2009-09-07 Thread Simon Brunning
2009/9/7 Terry Reedy : > Dennis Lee Bieber wrote: >> I'd say the >> mutables are in the majority > > I think it depends on whether one counts classes or instances. Typical > programs have a lot of numbers and strings. Ah, but immutable instances can be, and often are, interned. This will cut dow

Re: The future of Python immutability

2009-09-06 Thread Terry Reedy
Dennis Lee Bieber wrote: On Sun, 06 Sep 2009 20:29:47 -0700, John Nagle declaimed the following in gmane.comp.python.general: Python has the advantage that a sizable fraction of its objects, especially the very common ones like numbers and strings, are immutable. Immutable objects

Re: The future of Python immutability

2009-09-06 Thread Steven D'Aprano
On Sun, 06 Sep 2009 10:12:56 -0400, Terry Reedy wrote: > Adam Skutt wrote: >> There's nothing inappropriate about using a lambda for a function I >> don't care to give a name. That's the entire reason they exist. > > But you did give a name -- 'b' -- and that is when a lambda expression > is in

Re: The future of Python immutability

2009-09-06 Thread Steven D'Aprano
On Sun, 06 Sep 2009 06:18:23 -0700, Adam Skutt wrote: > On Sep 5, 7:38 pm, Steven D'Aprano > No. Lambdas are a *syntactical construct*, not an object. You wouldn't >> talk about "while objects" and "if objects" and "comment objects" >> *because they're not objects*. > This rhetoric precludes funct

Re: The future of Python immutability

2009-09-06 Thread John Nagle
Bearophile wrote: John Nagle: The concept here is that objects have an "owner", which is either a thread or some synchronized object. Locking is at the "owner" level. This is simple until "ownership" needs to be transferred. Can this be made to work in a Pythonic way, without explicit syntax?

Re: The future of Python immutability

2009-09-06 Thread Terry Reedy
Adam Skutt wrote: On Sep 5, 10:34 pm, Terry Reedy wrote: Adam Skutt wrote: On Sep 5, 11:29 am, Terry Reedy wrote: This is a pointless replacement for 'def b(x): return x+a' And? That has nothing to do with anything I was saying whatsoever. Agreed. However, posts are read by newbies. Post

Re: The future of Python immutability

2009-09-06 Thread Bearophile
John Nagle: > The concept here is that objects have an "owner", which is either > a thread or some synchronized object.   Locking is at the "owner" > level.  This is simple until "ownership" needs to be transferred. > Can this be made to work in a Pythonic way, without explicit > syntax? > > What w

Re: The future of Python immutability

2009-09-06 Thread Adam Skutt
On Sep 5, 10:34 pm, Terry Reedy wrote: > Adam Skutt wrote: > > On Sep 5, 11:29 am, Terry Reedy wrote: > >> This is a pointless replacement for 'def b(x): return x+a' > > > And?  That has nothing to do with anything I was saying whatsoever. > > Agreed.  However, posts are read by newbies. > Posts

Re: The future of Python immutability

2009-09-06 Thread Adam Skutt
On Sep 5, 7:38 pm, Steven D'Aprano No. Lambdas are a *syntactical construct*, not an object. You wouldn't > talk about "while objects" and "if objects" and "comment objects" > *because they're not objects*. This rhetoric precludes functions objects as well and is entirely non- compelling. > Funct

Re: The future of Python immutability

2009-09-05 Thread John Nagle
Steven D'Aprano wrote: On Fri, 04 Sep 2009 06:36:59 -0700, Adam Skutt wrote: Nope, preventing mutation of the objects themselves is not enough. You also have to forbid variables from being rebound (pointed at another object). Right. What's needed for safe concurrency without global lock

Re: The future of Python immutability

2009-09-05 Thread Terry Reedy
Adam Skutt wrote: On Sep 5, 11:29 am, Terry Reedy wrote: This is a pointless replacement for 'def b(x): return x+a' And? That has nothing to do with anything I was saying whatsoever. Agreed. However, posts are read by newbies. Posts that promote bad habits are fair game for comment. Py

Re: The future of Python immutability

2009-09-05 Thread Steven D'Aprano
On Sat, 05 Sep 2009 04:57:21 -0700, Adam Skutt wrote: >> > so the fact "Foo" and "Bar" are immutable isn't enough to solve the >> > problem. >> >> This is a side-effect of writing code that relies on global variables. >> Global variables are generally a bad idea. Global constants are fine. > > No

Re: The future of Python immutability

2009-09-05 Thread Steven D'Aprano
On Sat, 05 Sep 2009 14:09:57 -0700, Adam Skutt wrote: >> Python does not have lambda objects. It has lambda expressions that >> produce function objects identical except for .__name__ to the >> equivalent def statement output. > > Sure sounds like python has lambda objects to me then... the fact >

Re: The future of Python immutability

2009-09-05 Thread Adam Skutt
On Sep 5, 11:29 am, Terry Reedy wrote: > > This is a pointless replacement for 'def b(x): return x+a' And? That has nothing to do with anything I was saying whatsoever. Point is: any mutable shared state is bad, and making objects immutable isn't enough to remove all shared state, or even reduce

Re: The future of Python immutability

2009-09-05 Thread Terry Reedy
Adam Skutt wrote: \ This is a side-effect of writing code that relies on global variables. Global variables are generally a bad idea. Global constants are fine. Nope, the variables don't have to be global to have this problem, they just have to be shared: >>> a = 3 >>> b = lambda x: x

Re: The future of Python immutability

2009-09-05 Thread Adam Skutt
On Sep 5, 12:06 am, Steven D'Aprano wrote: > On Fri, 04 Sep 2009 06:36:59 -0700, Adam Skutt wrote: > > Nope, preventing mutation of the objects themselves is not enough. You > > also have to forbid variables from being rebound (pointed at another > > object).  Consider this simple example: > > > -

Re: The future of Python immutability

2009-09-05 Thread sturlamolden
On 5 Sep, 08:47, Steven D'Aprano wrote: > How do you know? After more than 10 years experience with scientific programming I just do. When it comes to numerics I have a gut feeling for what is fast and what is slow. It's not difficult actually. You just have to imagine how often the interpreter

Re: The future of Python immutability

2009-09-04 Thread Steven D'Aprano
On Fri, 04 Sep 2009 22:30:44 -0700, sturlamolden wrote: > On 5 Sep, 07:04, Steven D'Aprano > wrote: > >> How does Matlab speed compare to Python in general? > > Speed-wise Matlab is slower, but it is not the interpreter limiting the > speed here. How do you know? -- Steven -- http://mail.p

Re: The future of Python immutability

2009-09-04 Thread sturlamolden
On 5 Sep, 07:04, Steven D'Aprano wrote: > How does Matlab speed compare to Python in general? Speed-wise Matlab is slower, but it is not the interpreter limiting the speed here. -- http://mail.python.org/mailman/listinfo/python-list

Re: The future of Python immutability

2009-09-04 Thread sturlamolden
On 5 Sep, 07:04, Steven D'Aprano wrote: > Your code does a lot of unnecessary work if you're just trying to > demonstrate immutability is faster or slower than mutability. No ... I was trying to compute D4 wavelet transforms. I wanted to see how NumPy compared with Matlab. > How does Matlab sp

Re: The future of Python immutability

2009-09-04 Thread Steven D'Aprano
On Fri, 04 Sep 2009 20:48:13 -0700, sturlamolden wrote: > > Is the difference because of mutability versus immutability, or > > because of C code in Numpy versus Matlab code? Are you comparing > > bananas and pears? > > It consisted of something like this Your code does a lot of unnecessary wor

Re: The future of Python immutability

2009-09-04 Thread Steven D'Aprano
On Fri, 04 Sep 2009 06:36:59 -0700, Adam Skutt wrote: > Nope, preventing mutation of the objects themselves is not enough. You > also have to forbid variables from being rebound (pointed at another > object). Consider this simple example: > > -- Thread 1 -- | -- Thread 2

Re: The future of Python immutability

2009-09-04 Thread sturlamolden
On 5 Sep, 05:12, Steven D'Aprano wrote: > Is the difference because of mutability versus immutability, or because > of C code in Numpy versus Matlab code? Are you comparing bananas and > pears? It consisted of something like this import numpy def D4_Transform(x, s1=None, d1=None, d2=None):

Re: The future of Python immutability

2009-09-04 Thread Steven D'Aprano
On Fri, 04 Sep 2009 19:23:06 -0700, sturlamolden wrote: > I one did a test of NumPy's mutable arrays against Matlab's immutable > arrays on D4 wavelet transforms. On an array of 64 MB of double > precision floats, the Python/NumPy version was faster by an order of > magnitude. Is the difference b

Re: The future of Python immutability

2009-09-04 Thread sturlamolden
On 3 Sep, 20:03, John Nagle wrote: >      Python doesn't have immutable objects as a general concept, but > it may be headed in that direction.  There was some fooling around > with an "immmutability API" associated with NumPy back in 2007, but > that was removed.  As more immutable types are add

Re: The future of Python immutability

2009-09-04 Thread sturlamolden
On 4 Sep, 06:20, John Nagle wrote: > > In the current CPython implementation, every object has a reference > > count, even immutable ones. This must be a writable field - and here you > > have your race condition, even for immutable objects. > >     That's an implementation problem with CPython.

Re: The future of Python immutability

2009-09-04 Thread Scott David Daniels
John Nagle wrote: ... Suppose, for discussion purposes, we had general "immutable objects". Objects inherited from "immutableobject" instead of "object" would be unchangeable once "__init__" had returned. Where does this take us? Traditionally in Python we make that, "once __new__ had returned

Re: The future of Python immutability

2009-09-04 Thread Adam Skutt
On Sep 3, 2:03 pm, John Nagle wrote: >      Suppose, for discussion purposes, we had general "immutable objects". > Objects inherited from "immutableobject" instead of "object" would be > unchangeable once "__init__" had returned.  Where does this take us? You can create this in various ways thro

Re: The future of Python immutability

2009-09-04 Thread Hendrik van Rooyen
On Thursday 03 September 2009 21:07:21 Nigel Rantor wrote: > That is not the challenge, that's the easy part. The challenge is > getting useful information out of a system that has only been fed > immutable objects. Is it really that difficult? (completely speculative): class MyAnswer(object):

Re: The future of Python immutability

2009-09-04 Thread Paul Rubin
Ulrich Eckhardt writes: > Lastly, for the message passing, you also need shared, mutable structures > (queues), so you can't live completely without conventional locking. But that can be completely behind the scenes in the language or library implementation. The application programmer doesn't ha

Re: The future of Python immutability

2009-09-04 Thread Ulrich Eckhardt
Nigel Rantor wrote: > John Nagle wrote: >> Immutability is interesting for threaded programs, because >> immutable objects can be shared without risk. Consider a programming >> model where objects shared between threads must be either immutable or >> "synchronized" in the sense that Java uses

Re: The future of Python immutability

2009-09-04 Thread Francesco Bochicchio
On Sep 3, 9:07 pm, Nigel Rantor wrote: > > Right, this is where I would love to have had more experience with Haksell. > > Yes, as soon as you get to a situation where no thread can access shared > state that is mutable your problems go away, you're also getting no work > done becasue the threads,

Re: The future of Python immutability

2009-09-04 Thread r
"""The future of Python immutability""" Define future: The future is a time period commonly understood to contain all events that have yet to occur. It is the opposite of the past, and is the time after the present Define immutability: Not subject or susceptible

Re: The future of Python immutability

2009-09-03 Thread John Nagle
Gabriel Genellina wrote: En Thu, 03 Sep 2009 15:03:13 -0300, John Nagle escribió: Python's concept of immutability is useful, but it could be more general. Immutability is interesting for threaded programs, because immutable objects can be shared without risk. Consider a programmi

Re: The future of Python immutability

2009-09-03 Thread Gabriel Genellina
En Thu, 03 Sep 2009 15:03:13 -0300, John Nagle escribió: Python's concept of immutability is useful, but it could be more general. Immutability is interesting for threaded programs, because immutable objects can be shared without risk. Consider a programming model where objects sh

Re: The future of Python immutability

2009-09-03 Thread Paul Rubin
Stefan Behnel writes: > Read again what he wrote. In a language with only immutable data types > (which doesn't mean that you can't efficiently create modified versions of > a data container), avoiding race conditions is trivial. The most well known > example is clearly Erlang. Adding "synchronise

Re: The future of Python immutability

2009-09-03 Thread Stefan Behnel
John Nagle wrote: > With this mechanism, multi-thread programs with shared data > structures can be written with little or no explicit locking by > the programmer. If the restrictions are made a bit stricter, > strict enough that threads cannot share mutable unsynchronized data, > removal of t

Re: The future of Python immutability

2009-09-03 Thread Stefan Behnel
Nigel Rantor wrote: > My comment you quoted was talking about Java and the use of > synchronized. I fthat was unclear I apologise. Well, it was clear. But it was also unrelated to what the OP wrote. He was talking about the semantics of "synchronized" in Java, not the use. Stefan -- http://mail.

Re: The future of Python immutability

2009-09-03 Thread Nigel Rantor
Stefan Behnel wrote: Nigel Rantor wrote: John Nagle wrote: Immutability is interesting for threaded programs, because immutable objects can be shared without risk. Consider a programming model where objects shared between threads must be either immutable or "synchronized" in the sense that

Re: The future of Python immutability

2009-09-03 Thread Stefan Behnel
Nigel Rantor wrote: > > John Nagle wrote: >> Immutability is interesting for threaded programs, because >> immutable objects can be shared without risk. Consider a programming >> model where objects shared between threads must be either immutable or >> "synchronized" in the sense that Java us

Re: The future of Python immutability

2009-09-03 Thread Nigel Rantor
John Nagle wrote: Python's concept of immutability is useful, but it could be more general. In the beginning, strings, tuples, and numbers were immutable, and everything else was mutable. That was simple enough. But over time, Python has acquired more immutable types - immutable sets

The future of Python immutability

2009-09-03 Thread John Nagle
Python's concept of immutability is useful, but it could be more general. In the beginning, strings, tuples, and numbers were immutable, and everything else was mutable. That was simple enough. But over time, Python has acquired more immutable types - immutable sets and immutable byte a