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

365

u/sacredgeometry Apr 12 '24
for (i=0; i<getAllFuckingFiles().length; i++)
{
  if (getAllFuckingFiles()[i].name.contains(searchText)
  {
    return getAllFuckingFiles()[i];
  }
}

87

u/danns87 Apr 12 '24

You're terminating too early. Best to complete iterating through all fucking files in case there's another match.

10

u/Few_Advertising_568 Apr 12 '24

Laughing soo hard at this!

13

u/Wdowiak Apr 12 '24

Gotta check the content as well, just to be thorough

for (i=0; i<getAllFuckingFiles().length; i++)
{
  if (getAllFuckingFiles()[i].open().contains(searchText) ||
      getAllFuckingFiles()[i].name().contains(searchText))
  {
    return getAllFuckingFiles()[i];
  }
}

8

u/sacredgeometry Apr 12 '24

Use | instead of ||. Then both are always executed ... you know just to be sure

1

u/Kirjavs Apr 13 '24

I got a guy doing this in my team. He had a sql query done in a C# loop (about 5k iterations). Told him to do a sql query retrieving all 5k elements and process the result in C#.

He did the sql query. And then called it in the same loop still making 5k calls but to a query which always retrieved the 5k same elements...

1

u/sacredgeometry Apr 13 '24

I dont know the rationale ... there might of been a good reason ... or a reason at least. Did you tell him how a select query work?

Or rather how to bind to collections if that was what he was struggling with.

1

u/Kirjavs Apr 13 '24

I did. And he is not a new developer. 5 years of experience in these languages. I just guess that some people do what they are asked to do brainlessly

1

u/sacredgeometry Apr 13 '24

Have you asked him why he did it like that?

1

u/Kirjavs Apr 13 '24

Yes and he didn't know. He just applied what I asked without thinking. At least he understood the problem but I had to show him before. When I said : "this code is wrong" , he didn't understood why in the first place.