From: Henrik Martensson Date: 2006-01-05T10:32:42+09:00 Subject: Re: Can't change the value of self Immutable classes are less prone to bugs than mutable classes. This is because they have a single state. They are also thread safe. It is good practise to favor immutability when there are no compelling reasons for making a class mutable. A Time object represents an instance in time. Making it mutable could easily get confusing. Consider: time = MutableTime.at(946702800) rocket.launch_time = time ... time.change(946701565) # Changes the launch time of the rocket The launch time of the rocket can be changed without setting the launch_time property explicitly. This is a potential source of bugs. /Henrik On Mon, 2006-01-02 at 02:11, Jonathan Leighton wrote: > On Mon, 2006-01-02 at 09:47 +0900, Hal Fulton wrote: > > James Britt wrote: > > > Jonathan Leighton wrote: > > > > > >> Can't change the value of self (SyntaxError) > > >> self = round_to *args > > >> > > >> Why doesn't it work? What can I do instead? > > > > > > > > > "Destructive" methods must alter self using that self's existing > > > destructive methods. > > > > To which we should add: Time has no destructive methods, since > > Time objects are immutable. > > > > But someone once created a MutableTime class -- anyone recall > > who/when/where and whether it's complete? > > Thanks for the replies. Why is Time immutable (presumably it's > deliberately designed like that)? The MutableTime class sounds > interesting but it's probably overkill for what I wanted to do -- I'll > just modify variables at a higher level. > > Thanks