- #1
Jamin2112
- 986
- 12
I see on StackOverflow people doing stuff like
for (int k = 0; k < something.length(); k++)
where the body of the for loop never has any chance of modify something's length. I thought that was considered bad coding practice. The implementation of something's class might not return a private variable, instead might calculate the length on-call. Even if it did return a private variable, that's a couple nanoseconds of overhead. I guess it's considered ok coding practice to do stuff like that? I mean, it does look better than
for (int k = 0, len = something.length(); k < len; k++)
I've also seen people on StackOverflow say "Be careful of micro optimization." Can something explain what they mean by this?
for (int k = 0; k < something.length(); k++)
where the body of the for loop never has any chance of modify something's length. I thought that was considered bad coding practice. The implementation of something's class might not return a private variable, instead might calculate the length on-call. Even if it did return a private variable, that's a couple nanoseconds of overhead. I guess it's considered ok coding practice to do stuff like that? I mean, it does look better than
for (int k = 0, len = something.length(); k < len; k++)
I've also seen people on StackOverflow say "Be careful of micro optimization." Can something explain what they mean by this?