DEV Community

Discussion on: Hiding Complexity Does Not Make It Go Away, Or Does It?

frosnerd profile image
Frank Rosner Author

I totally agree with you. It is usually better to use data structures that are provided by the standard library instead of inventing your own unless you have strong reasons to do so. And in my case there is no strong reason.

I would probably not have done this in anything but a fun project. I did it for the sake of learning and having fun doing it. However I think that this is why having a powerful collection library is so important for me in a language. Because then you can conveniently pick the right datastructure for the job without having to "invent" it first.

I hear you when you say that index = (index + 1) % array.length is common and therefore easy to understand for (as you said) most developers. But that does not make it simpler than calling next on an iterator. That is actually the difference between simple and easy which I was refering to.

You are right that what I implemented was not really a circular list (which is an iterable) but an iterator on a circular list. The iterator has a state, pointing to the current element.

Thanks for commenting and pointing this out!