[Tutor] running a script from IDLE
alan.gauld@bt.com
alan.gauld@bt.com
Mon, 11 Mar 2002 19:02:30 -0000
> >In Smalltalk an FP style is encouraged and the default
> >return value from methods is self...
>
> But my point was that forcing myfoo to return an object
> can be expensive overhead
It's no more expensive to return a reference to an object
than to return a reference to a number or string. The point
being you don't need to create a new object, you reference
the modified original.
> >You need to do that anyway since the original is different
> >to the rotated version. I don't see the difference?
>
> The difference is I don't have to keep the original.
You don't have to keep the original in FP either.
You either pass in a reference to the object, modify it
in the function then pas back the reference to the
(same) modified object OR you pass in the original object
create a new modified object(as you would with a tuple say)
and pass back the new object. The original can now be
left to die.
> were themselves objects, so I'd have needed to deepcopy
> to work with a clone to return it as a new object.
But you don't need to do that in FP (OK some would say you
do but most pragmatic FP'ers don't). you just pass in the
reference and return the same reference.
> I tend to agree with this -- I like the cosmopolitan flavor
> of Python for example, because of the synergy.
Absolutely, the reason why I am still using Python after having
played with Ruby. Ruby has too much of a feel of "When all
you have is a hammer every problem looks like a nail" to it.
> My take: functional programming is about minimizing state,
Minimizing yes, but not eliminating.
Alan g.