Javari's Reference Immutability

Reiner Pope reiner.pope at gmail.com
Thu Jul 27 23:20:07 PDT 2006


I'll make all my replies in this post.

Hasan Aljudy wrote:
> The biggest argument in favor of const has been that writing good libraries requires some constness guarantess.
I would rather say that the const checking makes writing libraries 
_easier_. The important thing about const is, as I said earlier, that it 
saves development time, because it avoids the need for code duplication. 
It is undeniable that all constness guarantees can be emulated by hand, 
but there is clearly a difference between what is needed and what is 
useful. Neither static typing nor unit testing add any efficiency to the 
actual code-/writing/ stage, but they save time on bug-hunting. A 
similar argument is true for const.

> However, as I see it, the only constness needed is one for arrays.
And it isn't even strictly *needed* for arrays, because one could create 
an array-wrapping pair of classes which emulate constness, as Java has 
indeed done for String (readonly form) and StringBuffer (read/write 
form). However, right in my first post which you still seem to have 
ignored, I outlined the trouble with this: duplicate code. An this is 
not theory, but practice, because code is indeed duplicated, as in 
Java's String and StringBuffer classes which are effectively two 
versions of the same thing: char[].

> 
> Java has immutable String class, thus it covers that area.
> As we all know, Java has one of the best libraries around.
We seem to be going round in circles because we disagree on the 
fundamentals. Your assertion: Java has one of the best libraries around. 
My assertion: it is not as good as all that, because of the unnecessary 
copying required. I am not saying that Javari fixes that problem 
(because it doesn't) but rather that looking to the knowledge there can 
provide some insight into avoiding that problem in D. As you may have 
seen from various other proposals for const in D, I have in fact found a 
way to avoid this duplication.

>>> P.S. Are you (or Reiner Pope) saying that Javari provides a better  
>>> solution to this? <g>
No, I'm not. I'm looking for a solution to this in D. If you look at 
some of my other posts, you'll see the solution.

Cheers,

Reiner



More information about the Digitalmars-d-learn mailing list