Why I Use D
Bill Baxter
dnewsgroup at billbaxter.com
Sun Mar 30 18:34:40 PDT 2008
Leandro Lucarella wrote:
> bearophile, el 30 de marzo a las 16:03 me escribiste:
>> Leandro Lucarella:
>>> In python this is array[5:-1], which seems a lot nicer to me...
>> I know many languages, and in many situations I think Python has a good syntax (like Python list comprehensions and generators, two things that I think D may enjoy a LOT). But in this case I think D has chosen a better solution: if you allow a syntax like [5:-1], then in every access to an array you have to compute a modulus, or a sum, for the wrap around. ShedSkin does this, but in tight loops on arrays this slows down the code (in ShedSkin there is a compilation option to disable that, to increase running speed). For Python that's not a big problem, because Python is designed to be the best for the programmer first, and for the CPU then, but D is supposed to be fast almost as C, and just adding a single $ character it avoids that slowdown, so I think this is a really good compromise (that future languages will probably copy from D).
>
> I really can't see any overhead in array[5..-1] being syntax sugar for
> array[5..$-1]. I'm not talking about array[5..-1] returning an empty array
> if the array.lenght is 3 for example (which is really nice too, but I
> agree that the overhead could be ... polemic, so it might better suite
> in the standard library).
Yeh, array[5..-1] wouldn't necessarily have any overhead, but how about
array[5..a]?
--bb
More information about the Digitalmars-d
mailing list