Is all this Invarient **** er... stuff, premature optimisation?
Simen Kjaeraas
simen.kjaras at gmail.com
Sun Apr 27 17:14:19 PDT 2008
<p9e883002 at sneakemail.com> wrote:
> Of course, a wasn't really mutated. Instead, args[0] was copied and then
> mutated and labelled a. Then a was copied and mutated and reassigned the
> mutated copy.
>
> So, that's two copies of the string, plus a slice, plus an extra method
> call to
> achieve what used to be achievable in place on the original string.
> Which is now
> immutable, but I'll never need it again.
>
> Of course, on these short 1-off strings it doesn't matter a hoot. But
> when the
> strings are 200 to 500 characters a pop and there are 20,000,000 of
> them. It
> matters.
>
> Did I suggest this was an optimisation?
>
> Whatever immutability-purity cool aid you've been drinking, please go
> back to
> coke. And give us usable libraries and sensible implicit conversions.
> Cos this sucks
> bigtime.
>
> b.
Is this what you wanted to write?
int main(string[] args)
{
char[] a = cast(char[])args[0];
a[2..5] = "XXX";
writefln(a);
return 0;
}
This compiles and runs, and seems to do what you describe. Sure, there's a
cast there, but it's not all that bad, is it?
More information about the Digitalmars-d
mailing list