4 ms·
Iterators are a technique and are not bound to any particular programming language. Iterators abstract the idea of iterating through data. Instead of keeping tr
by tbirdz 11y ago
Iterators are a technique and are not bound to any particular programming language. Iterators abstract the idea of iterating through data. Instead of keeping track of the array index and thinking of it in terms of counting up or down, you instead create an iterator that will abstract this for you. You can create iterators to traverse the array in forward, backwards, every odd number, whatever way you want. Then you write your client code to operate on an iterator, and so completely separate the traversal of the sequence from the action to be performed on each element. Another useful abstraction in this context are list comprehensions (map, filter, reduce, etc.).
You can create iterators in any language, and I was referring to the abstract concept of iterators, not the particular form of iterators found in C++'s standard library.
- TorKlingberg 11y agoSure, you can write iterators in C, but nobody wants to drag all that complexity just for a reverse loop. In a language like Python of course, iterators are native and idiomatic.
- tbirdz 11y agoThe complexity is already there, iterators just help you manage it better. Even "just a reverse loop" is more complex than you might think, as evidenced by the article above.
- SamReidHughes 11y agoHow do they help you manage it better in C?