[logback-dev] on immutability
jhuxhorn at googlemail.com
Tue Feb 24 14:05:57 CET 2009
Ceki Gulcu wrote:
> Hello Joern,
> Joern Huxhorn wrote:
>> Ok, I *do* understand what immutability is *supposed* to be about but
>> reality is quite different. In the two languages that I know best - Java
>> and C++ - constness and immutability can be circumvented easily.
> The fact that immutability can be circumvented by technical means is
> in my opinion inconsequential.
Depends on your point of view.
C++ is just a very thin layer on top of assembly and a void pointer just
points to arbitrary memory so obviously the ability to say "this memory
is actually a ..." is needed. And casting an XYZ pointer back to a void
pointer is comparable to using Object in Java.
One can disable the ability to use reflection for this kind of dark
magic using security constraints. Because of this, I think everything is
OK with Java either.
> Marking an object instance immutable
> conveys intent. You can build additional logic on top of the
> immutability hypothesis. If someone intentionally circumvents
> immutability, the ensuing problems are theirs, not ours.
That's exactly what I was trying to say in the following paragraph.
Using an ImmutableLoggingEvent interface should be sufficient to mark
that intent. Casting from ImmutableLoggingEvent to MutableLoggingEvent
is similar to using reflection magic.
More information about the logback-dev