Arrays vs slices

Steven Schveighoffer schveiguy at yahoo.com
Thu Jun 11 10:40:18 PDT 2009


bearophile Wrote:

> Steve Schveighoffer:
> > No, please no!  Do I really need to carry around an integer that is going 
> > to be unused 99.9% of the time (In my case, probably 100%)?  I'd rather 
> > have a special type that has a stride.
> 
> Strides aren't essential, but once in a while they are useful, I use them now and then in Python. How can you tell that you don't need them so strongly?

The only time I use a "stride" is when I know I need a stride.  That is, carrying the stride around with the slice is only useful if the code using it doesn't know it needs to be strided, and just lets the object tell it what values it needs.

But if you know you want every other element, it's not that hard to construct a for-loop that does what you want.  That method seems far more appealing to me and probably performs better.  Especially in the 99% of cases you want to use a stride of 1, there is no runtime check.

The cases where I want to use a function that operates on an array but stride the input (the only use case I see for stride to be builtin to an array) are non-existent in my code.

-Steve



More information about the Digitalmars-d mailing list