It also makes it hard to modify some data structure you are working with. I was experimenting with some object-oriented programming in Matlab, and you actually have to explicitly inherit from "handle" if you have any methods that modify internal state. That was a surprise!
If you've got a data structure built out of arrays or cell arrays and you want to not make copies everytime you pass it into or out of a function, you pretty much have to wrap it in one of these classes. Another option is to use closures, with function handles, but that's pretty clunky also. Cheers On Monday 06 December 2010, Wayne Werner wrote: > On Mon, Dec 6, 2010 at 11:09 AM, Joel Schwartz <j...@joelschwartz.com>wrote: > > Chris, > > > > Can you say more about number (7) in your list? What does "pass by value" > > mean and what are the alternatives? > > Pass by value is exactly what it sounds like - you pass the value (a copy > of everything in the memory). This is bad when you're passing a 10,000 > item list to a function - because you now have *two* 10,000 item lists. > It's even worse when you have many times that amount of data. > > Python, OTOH passes by reference - instead of copying the list, a pointer > to the list is passed, so when you see something like this: > > def do_something(a_list): > a_list[2] = 4 > > mylist = [1,2,3,4] > do_something(mylist) > > now mylist is: > > [1,2,4,4]. > > This is much more efficient (although it tends to bite novice > programmers!). > > HTH, > Wayne _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor