The Artima Developer Community
Sponsored Link

Articles Forum
CLR Design Choices

15 replies on 2 pages. Most recent reply: Mar 10, 2004 4:02 PM by Howard Lovatt

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 15 replies on 2 pages [ « | 1 2 ]
Howard Lovatt

Posts: 321
Nickname: hlovatt
Registered: Mar, 2003

Re: CLR Design Choices Posted: Mar 10, 2004 4:02 PM
Reply to this message Reply
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:

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

Flat View: This topic has 15 replies on 2 pages [ « | 1  2 ]
Topic: Elegance and Other Design Ideals Previous Topic   Next Topic Topic: Matz on Craftsmanship

Sponsored Links


Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use