Immutability and strings

Jonathan M Davis jmdavisprog at gmail.com
Wed Aug 18 19:23:51 PDT 2010


On Wednesday, August 18, 2010 19:11:35 Andrej Mitrovic wrote:
> It's just nitpicking, I know. And I'm sure Andrei was specifically
> documenting only that first example. But I do think it was worth
> mentioning that immutability on individual elements isn't a safe bet
> unless you're sure the function does not take a reference parameter.

Well, I thought that that was pretty much a given, but I guess I can see how 
someone could miss that. But really, that's what ref _does_. You can append to 
strings all you like in your own function. Why would expect that not to be 
possible once it's been passed by ref? ref makes it free game to mess with what 
you pass it. So, I guess I can see how someone might  miss this if they're 
thinking of strings being totally immutable, but it's pretty basic. Whatever you 
can do to your variable in your function can be done to in a function that takes 
that variable by ref.

- Jonathna M Davis


More information about the Digitalmars-d mailing list