string types: const(char)[] and cstring

gareis dhasenan at gmail.com
Sat May 26 15:50:32 PDT 2007


== Quote from Bill Baxter (dnewsgroup at billbaxter.com)'s article
> 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?
> Ditto here.  When I've used java I found it more annoying that strings
> were immutable than anything else.
> --bb

I found it more bothersome by far that Integer, Float, etc were immutable. Even
after going through all the trouble of getting classes for all these, you couldn't
use them for out or inout parameters to functions.

Scratch that -- what was really annoying was that you couldn't ever *specify* how
you wanted your parameter. Even in C, you can pass an address (but then,
anything's possible in C). But in Java, you can only call by reference with a
class or an array, so you end up doing things like:
void foo(int[1] inout_parameter) { inout_parameter[0] += 5; }

And the only way to get scope const final sort of deal on a class is to copy and
then submit the copy as a final parameter -- it's the reference, not the data,
that's final.

In short, thank you, Walter, for allowing us to pass anything by reference, and by
allowing the data referenced to be made read-only.



More information about the Digitalmars-d-announce mailing list