Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It honestly depends on the compiler.


It's a great default assumption when you don't know all the quirks of the specific language or compiler, because either it will help you or at least won't hurt you.


It might hurt if you add this extra variable to every loop and at some point the array length changes within the loop. It also makes the code more verbose. This optimisation should be done like all optimisations: first you benchmark and then see if it makes sense to make this change. Most of the time there's no point doing so.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: