Immutability by default [was: Re: Tidy auto [Was: Re: @disable]]
Jason House
jason.james.house at gmail.com
Mon Jan 18 10:22:37 PST 2010
Leandro Lucarella Wrote:
> Walter Bright, el 17 de enero a las 14:45 me escribiste:
> > dsimcha wrote:
> > >Furthermore, I think that less verbosity encourages good practices. I've gotten
> > >into the habit of declaring all my stack variables immutable when writing a
> > >function, unless I really need them to be mutable. This makes code a lot easier
> > >to understand because, when I look at the function later and try to figure out how
> > >it works, I know right off the bat that only a small subset of the variables are
> > >ever modified after they're declared.
> >
> > Andrei introduced me to that style, and I'm starting to use it more
> > and more. I like it for the reasons you state.
>
> Do you remember when people asked for default immutability? I do :)
>
> To be fair, all I can find in the archives are about default immutability
> of function parameters, not local variables, but I'm under the impression
> that there was some discussion about making local variables immutable by
> default...
>
> I like the idea of making x := y an alias for immutable x = y (or even
> enum x = y). That would make this style much more attractive without
> breaking backward compatibility as immutable-by-default would do.
enum is a manifest constant. My vote would be to use pure:
pure x = y;
More information about the Digitalmars-d
mailing list