Char[] confusing

bearophile bearophileHUGS at lycos.com
Tue Mar 3 02:07:50 PST 2009


Qian Xu:
> I have to do math in mind in order to keep my code correct ;-)
> IMO, it does not make any sense.

At the beginning you have to think a bit about it, but you quickly learn it, and you find it's the best way to design it :-)
Several languages use this same convention.

It allows you to split an array in two parts with very little troubles:
s[0 .. $] == s[0 .. n] ~ s[n .. $]

It's especially good when all the language uses this idea, for example, in D2, this loops ten times, and x never becomes 10:
foreach (x; 0 .. 10) {...}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list