style guide says I should use classic for loop ove...
# getting-started
u
style guide says I should use classic for loop over forEach. I am paranoid android and dont want to instantiate iterators on arraylists, so, would creating a extension function forXYZ, which is just a for until loop, be considered antipattern?
k
You're afraid of creating
Iterators
? Why?
d
Although iterators are fairly lightweight. They are optmized out and an indexed for loop is used under the hood. (For arrays only). 🙂
k
For arrays, sure. But for lists? Anyway, the difference really shouldn't matter.
u
Well looking at the bytecode the iterator is there. No im not afraid, but if there is a solution without it, with same level of sugar, why not? Can be helpful on android
k
You would love
C++
I think. It's big on those "costless abstractions", the JVM ecosystem not so much.
u
Well, android endorsed it, and given list are usually small, i think its reasonable to do so, and its theoretically faster. And with kotlin you can give it the same amount of sugar