Article Discussion
CLR Design Choices
Summary: Anders Hejlsberg, the lead C# architect, talks with Bruce Eckel and Bill Venners about IL instructions, non-virtual methods, unsafe code, value types, and immutables.
16 posts on 2 pages.      
« Previous 1 2 Next »
The ability to add new comments in this discussion is temporarily disabled.
Most recent reply: March 10, 2004 4:02 PM by Howard
Howard
Posts: 25 / Nickname: hlovatt / Registered: March 3, 2003 1:20 PM
Re: CLR Design Choices
March 10, 2004 4:02 PM      
Steven Roberts said:

> About the only thing in the series that really had me in
> disagreement with Anders was his remarks about 'const'.
>
> [Stuff deleted]
>
> Back in my main C++ days (most of my programming these
> days is in perl doing network admin automation and
> internal tools since my company went Java and I can't
> stand java :)) we used const quite effectively to provide
> a good semantic communication to people writing code.

The standard method in Java is to define a class with a constant interface, get methods and **no** set methods, then to derive a class from it with the set methods. This behaves just like const in C++.

The problem, as in C++, is that the above const/mutable classes can't be compiler enforced, only enforced at runtime. IE you can cast away const delibrately or accidently! A further issue is that you often need to repeat methods, e.g. a max method that returns a const for consts and a max method that returns a mutable for mutables. I think this is what Anders Hejlsberg was getting at and is the big difference between final in Java and const in C++.

A better method is immutable, see:

http://developer.java.sun.com/developer/bugParade/bugs/4617197.html

A compiler that enforces immutables as described in the above RFE and available under the LGPL is:

https://pec.dev.java.net/
16 posts on 2 pages.
« Previous 1 2 Next »