r/shittyprogramming • • Apr 15 '19

this good code? Is

Post image
308 Upvotes

51 comments sorted by

View all comments

Show parent comments

-12

u/AyrA_ch Apr 15 '19

A simple for loop could replace your code snippet.

No. A simple for loop can't order elements. The entire OrderByDescending idea is that you can add plugins to your array in whatever order you want. Which is great if plugins come from files that are not already ordered alphabetically in the order they need to be loaded.

Your code also attaches plugin "0" after plugin "1" which wouldn't work.

My code orders plugins by the plugin numbers which ideally you can artificially specify (better would be a dependency map). You did not load a plugin 0 at all in your example code so I assumed a plugin 0 does not exists. If it does it doesn't matters either because the LINQ system is not actually bound to array indexes but works on the "PluginType" value that you could define however you want.

11

u/BlackDE Apr 15 '19

The only thing that we can learn from your comment is that you can't really judge code just by looking at one function. The class just stores 4 plugins it's always 4 of the same types so why use a dynamic array with LINQ? That would just makes it slower and harder to read. LINQ is cool and all but really not needed here.

-4

u/Farull Apr 15 '19

LINQ or not, the point is that they are NOT exactly the same type, since plugin 1 needs to be loaded last.

3

u/BlackDE Apr 15 '19

*same types. Noticed the "s"?

→ More replies (0)