• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can someone confirnm this  RSS feed

 
Dan Patrick
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I came across some statements regarding immutable objects that I was wondering what you all think of this. I am finding it hard to reason out some the statements in the foolowing post I came across on some java list server. Please comment if you can. Particularly with regard to immutable objects.
>
> ... a program that has a high proportion of immutable objects
> is easier to reason about than otherwise, since you are, in effect,
> programming with constants. This is a very important and useful
> technique that should not be overlooked. Note that in lisp/scheme,
Joe's response is head-on but not quite forcecful enough.
Java's automatic memory management is the key attribute that makes it
radically different from C++. While the two share a grammar (well, some
elements of grammar), they are as different as night and day when it comes
to the memory model and hence memory safety.

- A programming style that works in C++ is almost certainly bad for
any Java implementation out there.
- A Java program is only a little bit or less memory-intensive than
an equivalent Scheme program written by equally competent programmers.
- Following Joe's advice and working with mostly-immutable data is
*extremely* helpful for Java's garbage collectors.

???
 
Mark Herschberg
Sheriff
Posts: 6037
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't confirm that. If it's wrong, then of course, ti can't be confirmed, but something like that is hard to disprove.
I don't think such a program is easier to reason about. I've got plenty of programs in which I create an object over here, and then read from it over there. That's not much harder to think about, becauase remembering the "over there location" reqiures only a few more bits then "immutable." (While "over there location" may have many more bit in terms of name, its relation to the ovject being passed is similar enough that it only requires a little additional information. Of course, this really comes down to (human) memory models.) I am a big fan of making something slightly less efficent if its easier to understand/maintain. That being said, I don't think I'd ever make something immutable for that reason.
I've yet to see any reason why C++ structure wouldn't work in Java. How do they figure Java and Scheme programs are memory equivalent? Is there some study they cite, or is this speculation?
--Mark
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a big fan of making something slightly less efficent if its easier to understand/maintain. That being said, I don't think I'd ever make something immutable for that reason.
Amen to that. My feelings on immutables is sort of like "if the shoe fits." In some classes immutability just makes sense. For example when using a Flyweight pattern with value objects of some sort. You can lazily instantiate each object when a different value is required and cache that object for later retrieval. The core Java API offers great examples of classes that should be immutabl: String, Integer, Double, etc. I think any developer that puts perfomance ahead of analysis and design has got his priorities mixed up. Rule 1: Get it right, Rule 2: Tune it if you have to.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!