Is all this Invarient **** er... stuff, premature optimisation?

Me Here p9e883002 at sneakemail.com
Mon Apr 28 08:16:51 PDT 2008


Janice Caron wrote:

> you could do
> 
>     char[] tmp = a.dup;
>     tmp[2..5] = "XXX";
>     a = assumeUnique(tmp);
> 

Ah! Again, 3 lines instead of 1. Plus two function calls and a temporary variable.

You do realise that there is a very strong correlation between bugs and line count?
That's been so for all of the last 30+years regardless of language or paradigm.

So, you made it more verbose and more complex and much slower. 

And, in doing so, introduced more scopes for errors than you've cured.

>That's one approach. Another is don't try to treat strings as mutable.

Ram is mutable--it's its purpose in being, 
Variables live in RAM, and vary--that's their purpose in being.

Making a copy of a <strike>string</strike> piece of ram and throwing the old one away, 
every time I want alter its contents...kinda reminds me of disposable nappies. 
A costly convenience.

I'll revert to 1.x and pray that 2.x fades away through lack of interest before it turns
D into Yet Another Dead Language--for OO purists and academics only.

Cheers, b.

-- 




More information about the Digitalmars-d mailing list