Const sucks
Walter Bright
newshound1 at digitalmars.com
Mon Sep 10 21:14:13 PDT 2007
Bruno Medeiros wrote:
> Walter Bright wrote:
>> What, exactly, is the use case that needs a solution?
>
> Here's another use case, which is significantly different than the other
> (there should be lots more to be found). Say you have a Person class,
> which has a name, and for whatever reasons you want the name be a String
> class instead of const(char)[]. Then you have:
>
> class Person {
> const(String) name;
> ...
>
> but now how do you change the name of the Person?...
I'd redesign String so it holds invariant data, then just have:
class Person {
String name;
...
More information about the Digitalmars-d
mailing list