Built-in unsafety in D

bearophile bearophileHUGS at lycos.com
Fri Mar 12 08:49:11 PST 2010


Ellery Newcomer:
> foreach(k; arr){
> 	k = something;
> }
> when k should have a ref attribute.

I have found 2 bugs like that one in my code where 'arr' was an array of structs.
Another related bug was, done 2 times in my code:

void foo(string s) {
  s.length += 1;
}

Here outside foo the length of the string s is seen as unchanged (and allowing to change the length of a string that's supposed to be immutable is a bit silly. D docs have to explain very well that D strings are not immutable).

The number of times I have spelled "length" wrong (as lenght) is now uncountable. I really think that "len" or "size" are 100 times better for this purpose.

Bye,
bearophile



More information about the Digitalmars-d mailing list