Is D still alive?

Andrej Mitrovic andrej.mitrovich at gmail.com
Thu Jan 27 10:09:50 PST 2011


Honestly, I think this would just encourage writing sloppy code.

Using min(x, $) explicitly informs the reader of the code of exactly
what happens. It's harder to tell when it's implicit. Not only that,
but it can introduce bugs in your code - because while you might use
any upper bound, you're still not allowed to index beyond the length
of the array. Imagine this could was accepted by DMD:

void main()
{
    auto userArgs = ["foo"];  // runtime arguments by some user input

    auto firstTwo = userArgs[0..2];  // accepted by the new language change,
                                                  // implicitly
changes 2 to min(2, $)

    // more code here

    firstTwo[1] = "test";  // oops!
}


More information about the Digitalmars-d mailing list