Stepping back and looking at constness from another angle.

Jeff Nowakowski jeff at dilacero.org
Tue Jun 5 22:01:49 PDT 2007


Sean Kelly wrote:
> That said, I suspect it may be important for D to gain acceptance in 
> corporate environments, and wonder why no one has ever complained about 
> Java's lack of const (to my knowledge).

People have:

http://www.google.coam/search?q=java+const

I'm a Java programmer, and I have often wished for something like const. 
  It would save me some bugs and some peace of mind in reasoning about 
my code.  It would definitely help with threading.

By the way, from the above search I found a Java bug filed in 1999 
requesting something like const.  The comments from Sun on why they will 
not add it sound familiar:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4211070

"It's possible, but I would rather hold the line on creaping featurism. 
One can design around this (using interfaces, wrappers etc.)."

"In addition to creeping featurism, we see the following problems
with this feature:

* Adding const is too late now.  Had this been added from 1.0,
   the situation could have been different.

* Const pollution: the C++ approach requires all const methods
   to be marked with a const keyword.  This means that most
   methods will have to be marked const explicitly.  This tend
   to clutter all methods in C++.

* Compatibility is a very important feature of the JDK.
   Arguably, the collection classes should be modified to
   indicate that the elements are const.  That would
   require all existing implementations to be updated in
   the same way, effectively breaking all existing non-JDK
   implementations of the collection interfaces.  Similarly,
   hashCode would have to be const, breaking the current
   implementation of String."



More information about the Digitalmars-d mailing list