For each loop on TArray

for : is the for each statement in C++. Just because theres no foreach keyword doesnt mean it isnt the same thing.

  1. No, its not. If the array isnt being mutated then its fine, and if it is, then i cache the array first.

  2. Its literally a stylstics choice. No one in the history of ever has had worse preforming code because they put the plus signs in the wrong order. Its a complete over reaction, and any code compiler could refactor i++ into ++i if it can. This is micro optimizing.

I prefer i++ because it makes more semantic sense to me. Theres i = i + 1, i += , i.Add(1) so naturally i++ is more constistent to have the identifier first, then the operation afterwards. Preformance wise it will almost never make a difference, and if it does, then that’s the fault of the implimenter of the ++ operator.

  1. What? Are you in the 70s? Computers can handle using even 1000s of ints that arent needed, this is abusrd. In C#, for example, an int is actually faster than a byte or short, because the compilers were designed more efficently to use ints, because they were more common, so it might actually be better to use int.

Do you have any measurements for any of this? This is such a micro optimization that literally doesn’t matter. You’re talking about the preformance of a for loop