[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: the benefits of immutability
- To: address@hidden
- Subject: Re: the benefits of immutability
- From: "Perry E. Metzger" <address@hidden>
- Date: 19 Aug 2003 16:09:35 -0400
- Cc: address@hidden
- In-reply-to: <Pine.LNX.4.44.0308191239250.14501-100000@manjula.frotz.bogus>
- References: <Pine.LNX.4.44.0308191239250.14501-100000@manjula.frotz.bogus>
- Sender: address@hidden
- User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2
ranjan@frotz.com writes:
> On 19 Aug 2003, Perry E. Metzger wrote:
>
> > *All* of Java's base object types are final -- String, StringBuffer,
> > Boolean, Integer, etc., and the vast majority of those are mutable.
> >
> > His explanation was pretty damn weak in that context.
> >
>
> String, Boolean, Double, Long, Float, and Integer are immutable, unless
> you've got a different notion of mutability than what I've seen.
Sure, but my point is that everything in sight (see StringBuffer,
which is pretty obviously mutable) was made final by Java's designers,
on the premise, presumably, that they knew everything you would ever
want such an object to do. I'm sure this provided them with teeny
improvements in optimization (but given the fact that the stock JDK
barely has any optimization at all that's ignorable) and with teeny
improvements in their ability to force certain interfaces to be
"Secure" for some definition of "Secure", but it is also a royal pain
in the ass.
> Even if these weren't declared final, anybody reading code where they were
> subclassed would think that something weird was going on -- who subclasses
> String? Why would you want to?
In this case, I was using Java's types to represent types in a higher
level language I was interpreting and wanted to add some protocols to
all said types to ask them to do various things, like evaluating
themselves. It would have been very convenient. I was forced to use
much less convenient techniques.
However, "why would you want to" is the perpetual mantra I suspect
Java's designers chanted every morning before thinking of another set
training wheels to impose upon their users.
Good programmers are not cattle. They are creative professionals, and
often come up with uses for tools that the designer never
anticipated. This does mean that idiots might get themselves in
trouble, but, to paraphrase the old saw about Unix, "A good system
does not stop you from doing stupid things because that would also
stop you from doing clever things."
One of many problems with Windows, BTW, is that it will only let you
do things the designers anticipated you would need to be able to
do. Anything they didn't think of is difficult to impossible.
The pathetic thing about Java is that not only is it crippled to make
it safe, but it isn't even safe. Overflows, for example, are ignored,
presumably to make it look more like C. Yuck.
Perry