2 ms·
Except you often need an index, so you can't just tell everyone to use a foreach and be done with it.
by EpicEng 13y ago
Except you often need an index, so you can't just tell everyone to use a foreach and be done with it.
- brudgers 13y agoForeach is used as an example of working at a higher level of abstraction than iterating over a loop like for i = 0, i <= myarray.length - 1, i++ do foo(myarray[i]) end I'm not suggesting that foreach is singing, dancing and all-powerful, so of course it doesn't serve for accessing arrays by position. What I am suggesting is that the syntax used for arrays was not inscribed on stone tablets upon Mount Olympus, and that myarray.get(6) //return the sixth element myarray.foreach('foo 6 19) //operate on part of the array May be better abstractions for general purpose programming. Syntax should facilitate the programmer.
- EpicEng 13y agoFair enough, but let's not fool ourselves into thinking that pointers are going away. Sure, for higher level stuff I don't want to mess with manual memory management, but what about the massive mountain of software that all of these high level programs rely upon? We are always going to need this stuff for certain tasks. For example, I'd love to see a simply 3x3 filter operation on an image without using indices. I am also a bit biased; I'm a systems programmer, I don't write UI's and web apps. I tend to work more in the trenches, where abstraction gets in your way almost as often as it helps you get things done more quickly.