Why I Use D

Leandro Lucarella llucax at gmail.com
Sun Mar 30 17:54:02 PDT 2008


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).

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
Una mujer en bicicleta, con sombrero de paja, es la más flagrante
violación a las leyes de la aerodinamia.
	-- Ricardo Vaporeso. 21 de Septiembre de 1917.



More information about the Digitalmars-d mailing list