When I was learning C, I was taught to do stuff, say, if I wanted to loop through a something strlen(string)
times, I should save that value in an 'auxiliary' variable, say count
and put that in the for condition clause instead of the strlen
, as I'd save the need of processing that many times.
Now, when I started learning Java, I noticed this is quite not the norm. I've seen lots of code and programmers doing just what I was told not to do in C.
What's the reason for this? Are they trading efficiency for 'readibility'? Or does the compiler manage to fix that?
E: This is NOT a duplicate to the linked question. I'm not simply asking about string length, mine is a more general question.