Why I Use D

bearophile bearophileHUGS at lycos.com
Sun Mar 30 13:03:01 PDT 2008


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).
The syntax array[..5] / array[5..] looks acceptable, but it allows you to avoid just one char, so it's far from the top of the list of things I'd like to see in D :-)

Bye,
bearophile



More information about the Digitalmars-d mailing list