Removal of implicit variable "length"

Jarrett Billingsley kb3ctd2 at yahoo.com
Tue Jun 6 17:06:38 PDT 2006


"Bradley Smith" <digitalmars-com at baysmith.com> wrote in message 
news:e64tgp$1gvu$1 at digitaldaemon.com...

> I would guess that most programmers unfamilar with D would answer "B". 
> However, "A" is the correct answer. It certainly has been a lesson I've 
> had to learn the hard way.

Have you heard of $ ?

bar = foo[0 .. $];

Additionally, try turning on warnings for your original code, and you'll 
notice you get one.

It probably is time to deprecate length inside array braces.

> Besides, is "foo[0 .. length]" really better than "foo[0 .. foo.length]"? 
> The first is slightly more convenient but the second is more explicit and 
> readable.

How about things like

int[] x = ALongClassName.AnotherClassName.aNonTrivialOperation()[1 .. $];

It's certainly nice to have a shortcut in cases like this, when typing out 
the original expression is not only prohibitively long, but could possibly 
waste performance re-evaluating the reference to the array. 





More information about the Digitalmars-d-learn mailing list