You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
- $\begingroup$ Of course a compiler could optimize this away - this was very common on x86, for example, because of its powerful memory addressing; especially since 486 and Pentium. And of course, just have a look at any modern disassembled code - in most cases, you will not find any direct indexing from the base of the array anyway. Ultimately, in many cases, indexing an array is a relic anyway - for most cases where you see indexing, what you really want is iteration. It's just that many programmers and languages are stuck without distinction between the two. $\endgroup$Luaan– Luaan2018-09-13 10:55:05 +00:00Commented Sep 13, 2018 at 10:55
- $\begingroup$ C or many other languages don't have iteration so we really should know what it is and how it works. Modern techniques sometimes are great but sometimes they are simply overcomplicated, less comprehensive compared to [i] and I don't think there is no kind of index accessing behind iterators - we just don't see it any more. So I doubt iterators are really faster than a simple [i]. $\endgroup$puck– puck2018-09-13 11:07:29 +00:00Commented Sep 13, 2018 at 11:07
- $\begingroup$ C was deficient in that regard even in comparison with other languages of its time. And no, they're certainly not less comprehensive. You need to look at code with fresh eyes - a lot of the crazy doesn't seem crazy anymore when you get used to it. The thing about iterators is that any indexing is strictly an implementation detail - which allows you to give much more freedom to the code that's using them as an interface. If you pass an array, it will always be an array. If you pass an iterable, the implementation can do whatever fits - like using a linked list. $\endgroup$Luaan– Luaan2018-09-13 17:00:23 +00:00Commented Sep 13, 2018 at 17:00
- $\begingroup$ Iterators can easily be faster than pointers, and they can be slower than pointers. But they're definitely easier to understand and reason about, and they allow a lot of optimisations that simply aren't possible with "pointers to an array". Just consider something like map-reduce - it wouldn't be possible if people stuck to the idea that arrays are just a pointer to the first item in an array. Unsurprisingly, it came from the other side of the language spectrum - languages that value abstraction over micro-tweaks. $\endgroup$Luaan– Luaan2018-09-13 17:02:48 +00:00Commented Sep 13, 2018 at 17:02
Add a comment |
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
- create code fences with backticks ` or tildes ~ ```
like so
``` - add language identifier to highlight code ```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible) <https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
- MathJax equations
$\sin^2 \theta$
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. self-learning), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you