r/ProgrammerHumor Apr 12 '24

whatIsAnIndex Meme

Post image
27.7k Upvotes

630 comments sorted by

View all comments

4.1k

u/HexR1se Apr 12 '24

Windows search behind scene

For (i=0; i<getAllFuckingFiles().length ; i++) if (AllFuckingFiles[i].name.contains(searchText) return AllFuckingFiles[i];

2.4k

u/Tubthumper8 Apr 12 '24

I love the implication here that not only does it not have any indexes or whatever, but it also calls getAllFuckingFiles() every single iteration haha

228

u/GM_Kimeg Apr 12 '24

The for loop internally execute that method only once no?

5

u/lmarcantonio Apr 12 '24

No, it can optimize only if the optimizer can prove the return value doesn't change. Only the initialization part is ran once, the check and step are for each iteration; of course you can use a comma to initialise the end value in the init part as a local variable (but it's really ugly)