Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> With a higher level mechanism, we can separate the behavior that we want for loops from the behavior we want for everything else in a nice, clean way.

Yes! One decisive advantage that high-level iteration constructs have over for loops is that they're easier to optimize.

One obvious example here is bounds checks: there's no need to have infrastructure to optimize out bounds checks over arrays during loops if you have a construct that eliminates the indexing entirely.



Genuine question: what do you do when you want to implement your own loop mechanism, iterator, array type, or whatever?


It is the job of the language to ensure that language primitives are reusable and composable.

I think this would apply to whatever mechanism is designed to describe a loop's iteration space.


Most languages use some sort of interface whereby if you implement certain methods for a type then that type can be iterated over using a for loop.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: