string types: const(char)[] and cstring

Johan Granberg lijat.meREM at OVEgmail.com
Sat May 26 11:42:36 PDT 2007


Marcin Kuszczak wrote:

> Derek Parnell wrote:
> 
>>> Under the new const/invariant/final regime, what are strings going to be
>>> ? Experience with other languages suggest that strings should be
>>> immutable.
>> 
>> We seem to have different experience. Most of the code I write deals with
>> changing strings - in other words, manipulating strings is very very
>> common in the sorts of programs I write.
>> 
> 
> The same here. I don't have much experience with Java and really don't
> know why const strings are so usefull...
> 
> Maybe someone could elaborate a little bit more?
> 

In my experience they are not really usefull at all (const as in constant
that is). Sometimes it does not matter and sometimes it is inconvenient or
a performance problem. (it is mostly append that is needed in my
experience)

If function parameters was const by default (as in the new behavior of in) I
see no use of immutability here. In java I think it is used to prevent
aliased String objects from changing value, something that could create
unexpected bugs if used by programmers not understanding aliasing.

ps. although I'm no fan of java I have used it for most university
assignments for the past two years, so hopfully I'm not totally wrong ;)



More information about the Digitalmars-d-announce mailing list