[nem-en] Initonly modifier for immutable fields
Michal Moskal
michal.moskal at gmail.com
Sun Jul 9 20:20:59 CEST 2006
On 7/9/06, Kamil Skalski <kamil.skalski at gmail.com> wrote:
> Try this program with and without 'readonly' modifier:
[...]
> The outputs can be quite suprising for anyone ;)
While they are surprising at the first sight, after you think a bit
about it, it makes a perfect sense. When you mark a field initonly --
it cannot be changed. And in case of struct this means that the struct
itself cannot be changed.
The solution here is to avoid mutator methods on structs. It is the
best for structs to be immutable. This is also the advice given by the
C# folks, that I've read somewhere. If you're using mutable structs,
you deserve punishment.
I'm personally happy with the new semantics you've introduced.
--
Michał
More information about the devel-en
mailing list