Am 29.10.2012 16:20 schrieb andrea crotti:
Now on one hand I would love to use only immutable data in my code, but
on the other hand I wonder if it makes so much sense in Python.
You can have both. Many mutable types distinguish between them with
their operators.
To pick up your example,
On Oct 31, 1:45 am, Neal Becker wrote:
> rusi wrote:
> > On Oct 29, 8:20 pm, andrea crotti wrote:
> >
> >> Any comments about this? What do you prefer and why?
>
> > Im not sure how what the 'prefer' is about -- your specific num
> > wrapper or is it about the general question of choosing mutabl
rusi wrote:
> On Oct 29, 8:20 pm, andrea crotti wrote:
>
>> Any comments about this? What do you prefer and why?
>
> Im not sure how what the 'prefer' is about -- your specific num
> wrapper or is it about the general question of choosing mutable or
> immutable types?
>
> If the latter I would
On Oct 29, 8:20 pm, andrea crotti wrote:
> Any comments about this? What do you prefer and why?
Im not sure how what the 'prefer' is about -- your specific num
wrapper or is it about the general question of choosing mutable or
immutable types?
If the latter I would suggest you read
http://en.wi
On Mon, 29 Oct 2012 15:45:59 -0700, Chris Kaynor wrote:
> On Mon, Oct 29, 2012 at 3:30 PM, Steven D'Aprano
> wrote:
>> On Mon, 29 Oct 2012 17:05:07 +, andrea crotti wrote:
>>
>>> I meant how do I create new immutables classes myself, I guess that's
>>> possible writing C extensions but I don'
On Mon, 29 Oct 2012 15:20:02 +, andrea crotti wrote:
> I have a philosofical doubt about immutability, that arised while doing
> the SCALA functional programming course.
"Philosophical". Like most words derived from the ancient Greeks, the "F"
sound uses "ph" rather than "f".
> Now suppose
On Mon, Oct 29, 2012 at 3:30 PM, Steven D'Aprano
wrote:
> On Mon, 29 Oct 2012 17:05:07 +, andrea crotti wrote:
>
>> I meant how do I create new immutables classes myself, I guess that's
>> possible writing C extensions but I don't see in pure Python..
>
> Well, you can't *quite* make a truly i
On Tue, 30 Oct 2012 06:36:52 +1100, Chris Angelico wrote:
> On Tue, Oct 30, 2012 at 6:23 AM, Ian Kelly
> wrote:
>> _MyImmutableClass = namedtuple('MyImmutableClass', 'field1 field2
>> field3 field4')
>>
>> class MyImmutableClass(_MyImmutableClass):
>
> Question: Is it clearer to take advantage o
On Mon, 29 Oct 2012 17:05:07 +, andrea crotti wrote:
> I meant how do I create new immutables classes myself, I guess that's
> possible writing C extensions but I don't see in pure Python..
Well, you can't *quite* make a truly immutable class in pure-Python,
because if *your* Python code can
On Mon, Oct 29, 2012 at 1:36 PM, Chris Angelico wrote:
> Question: Is it clearer to take advantage of the fact that the base
> class can be an arbitrary expression?
>
> class MyImmutableClass(namedtuple('MyImmutableClass', 'field1 field2
> field3 field4')):
>
> You lose the unnecessary temporary a
On Tue, Oct 30, 2012 at 6:23 AM, Ian Kelly wrote:
> _MyImmutableClass = namedtuple('MyImmutableClass', 'field1 field2
> field3 field4')
>
> class MyImmutableClass(_MyImmutableClass):
Question: Is it clearer to take advantage of the fact that the base
class can be an arbitrary expression?
class M
On Mon, Oct 29, 2012 at 10:12 AM, andrea crotti
wrote:
> Also because how doi I make an immutable object in pure Python?
I sometimes use namedtuples for this.
from collections import namedtuple
MyImmutableClass = namedtuple('MyImmutableClass', 'field1 field2 field3 field4')
If you want default
On Mon, Oct 29, 2012 at 12:46 PM, Paul Rubin wrote:
> andrea crotti writes:
>> Also because how doi I make an immutable object in pure Python?
>
> Numbers in Python are already immutable. What you're really looking for
> is a programming style where you don't bind any variable more than once.
N
On 10/29/2012 1:05 PM, andrea crotti wrote:
I meant how do I create new immutables classes myself, I guess that's
possible writing C extensions but I don't see in pure Python..
If you mean class with immutable instances, mutate new instances in
__new__ instead of __init__ and write a custom .
On 10/29/2012 12:05 PM, andrea crotti wrote:
> I meant how do I create new immutables classes myself, I guess that's
> possible writing C extensions but I don't see in pure Python..
The short answer is: you don't, not really, except by using NamedTuple
if that gives you what you want.
The longer
On 10/29/2012 11:20 AM, andrea crotti wrote:
I have a philosofical doubt about immutability, that arised while doing
the SCALA functional programming course.
In real life, the physical world, things have mutable state, at least
down to the atomic level. Do you only want to model mathematical w
andrea crotti writes:
> Also because how doi I make an immutable object in pure Python?
Numbers in Python are already immutable. What you're really looking for
is a programming style where you don't bind any variable more than once.
This gives rise to a programming style that Python can support
2012/10/29 Chris Angelico :
> On Tue, Oct 30, 2012 at 2:55 AM, Paul Rubin wrote:
>> andrea crotti writes:
>>> and we want to change its state incrementing the number ...
>>> the immutability purists would instead suggest to do this:
>>> def increment(self):
>>> return NumWrapper(self
2012/10/29 Jean-Michel Pichavant :
>
>
> In an OOP language num.increment() is expected to modify the object in place.
> So I think you're right when you say that functional languages technics do
> not necessarily apply to Python, because they don't.
>
> I would add that what you're trying to sugg
On Tue, Oct 30, 2012 at 2:55 AM, Paul Rubin wrote:
> andrea crotti writes:
>> and we want to change its state incrementing the number ...
>> the immutability purists would instead suggest to do this:
>> def increment(self):
>> return NumWrapper(self.number + 1)
>
> Immutability puris
- Original Message -
> 2012/10/29 Jean-Michel Pichavant :
> >
> > "return NumWrapper(self.number + 1) "
> >
> > still returns a(nother) mutable object.
> >
> > So what's the point of all this ?
> >
> > JM
> >
>
> Well sure but it doesn't modify the first object, just creates a new
> one.
andrea crotti writes:
> and we want to change its state incrementing the number ...
> the immutability purists would instead suggest to do this:
> def increment(self):
> return NumWrapper(self.number + 1)
Immutability purists would say that numbers don't have "state" and if
you're tr
On 29/10/2012 15:20, andrea crotti wrote:
I have a philosofical doubt about immutability, that arised while doing
the SCALA functional programming course.
Now suppose I have a simple NumWrapper class, that very stupidly does:
class NumWrapper(object):
def __init__(self, number):
s
2012/10/29 andrea crotti :
>>
>
> Well sure but it doesn't modify the first object, just creates a new
> one. There are in general good reasons to do that, for example I can
> then compose things nicely:
>
> num.increment().increment()
>
> or I can parallelize operations safely not caring about th
2012/10/29 Jean-Michel Pichavant :
>
> "return NumWrapper(self.number + 1) "
>
> still returns a(nother) mutable object.
>
> So what's the point of all this ?
>
> JM
>
Well sure but it doesn't modify the first object, just creates a new
one. There are in general good reasons to do that, for examp
- Original Message -
> I have a philosofical doubt about immutability, that arised while
> doing
> the SCALA functional programming course.
>
> Now suppose I have a simple NumWrapper class, that very stupidly
> does:
>
> class NumWrapper(object):
> def __init__(self, number):
>
26 matches
Mail list logo