|
|
|
|
|
by needcheapbw
3216 days ago
|
|
Like, for(int i=0; i<10; i++) { // todo } OK well yes there can be bugs using the index and even C++ back when I was doing it had the Boost library which had for_each. In Java we got something similar back in Java 5 or 6. Also we have fancy stream operations now in Java 8 which took me the longest time to come to appreciate. The only down side is removed compatibility with other languages like C and C++ and C#, locking in the app to a specific language more. There is on rare occasion, however, sometimes a problem that is solved more clearly or handily using indexing, similar to step indexing in BASIC. One use case where I've seen stepped indexing useful is in the field of robotics, which uses step characteristics for synchros and servos. |
|
Using a Stream instead of a for loop does very little to make your code incompatible with C. It is already pretty much incompatible (modulo JNI).
What I mean is: if you want something that looks like C just use that, there is no gain in not learning new constructs just because older languages did not have them.