The library is really picky about the order in which plugins are attached. Plugins of type "1" have to be attached after the other plugins. Why the library wants that is a mystery.
First of all you don't need LINQ. A simple for loop could replace your code snippet. Your code also attaches plugin "0" after plugin "1" which wouldn't work. I know it's crappy but the library is how it is.
Yeah, your code is more readable than the LINQ snippet. The comment could use some love though. Maybe just copy-paste your reddit commit from above there :P .
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.
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.
The class just stores 4 plugins it's always 4 of the same types so why use a dynamic array with LINQ?
If it's always 4 and always of the same type, why not actually store them in the order you want to load them?
That would just makes it slower and harder to read.
You are iterating over an array once to load plugins, whatever mechanism the loader triggers is going to dwarf the time this Linq query does to the 4 entries.
Linq is also not that hard to read. You can't really get more verbose than OrderByDescending(o=>o.ThisKey) to order a list. It's almost identical to SQL (that syntax is also supported in LINQ)
I imagine the real issue is assigning a numeric value to the idea of "plugin type". It would be far clearer to say "plugin xy is dependent on plugin x" or something similar
You can customize the color scheme. The default might have separate colors for each bracket, but I'm guessing there's a way to make them the same color.
I've seen some weird ass coding conventions in my days. But whatever works for you is the best way to go imo. Had a C++ teacher at uni who would name everything based on scope, type and if it's a pointer. A member variable of type int would be mi_var and a parameter value of type pointer to a class would be ppx_var. I absolutely hated it. The reasoning he had was that it makes it clear what type variable it is. I've never had a problem with keeping track of that so I just go standard camelCase with no extra.
I suppose it might be somewhat cleaner if you populated a List with the plugins in the desired order and then iterated it with a loop, but if the plugin order really is that finicky I think it's better to leave it this way so it's more clear what's happening (I assume you've already checked the size and contents of the plugins array somewhere above this fragment).
Honestly, it's probably not worth worrying that much about four lines of code.
Whould be why better if you created an array with the index values in the correct order and loop over that. Call it plugin load order or whatever. You don't have to repeat everything if only the index changes.
109
u/Ivaalo Apr 15 '19
I really want to know why
12
u/SuperLutin Apr 15 '19
Where is
plugins_[0].value()?6
u/IanSan5653 Apr 15 '19
Why is [ a different color from ]?
3
u/SnowdensOfYesteryear Apr 15 '19
What god awful coding convention requires an underscore after a instance (?) variables?
63
u/SantaCruzDad Apr 15 '19
Could use a little obfuscation and premature optimisation:
6
u/_Nexor Apr 15 '19
finitedely
3
u/AKJ90 Apr 15 '19
esundefinedY
3
u/GogglesPisano Apr 15 '19
I suppose it might be somewhat cleaner if you populated a List with the plugins in the desired order and then iterated it with a loop, but if the plugin order really is that finicky I think it's better to leave it this way so it's more clear what's happening (I assume you've already checked the size and contents of the plugins array somewhere above this fragment).
Honestly, it's probably not worth worrying that much about four lines of code.
3
u/wischichr Apr 15 '19
Whould be why better if you created an array with the index values in the correct order and loop over that. Call it plugin load order or whatever. You don't have to repeat everything if only the index changes.
1
u/farox Apr 15 '19
Sometimes it just is like that
1
u/GargantuanCake Apr 16 '19
Reminds me of finding a decade old comment of
// This is a terrible hack. I'll fix it when I come up with something better but I need this to work right now.
1
u/noonagon Apr 29 '19
1 2 3 4
2 3 4 1
3 4 1 2
4 1 2 3
1 2 3 4
1
u/TheRealSoprano Apr 15 '19
I sense WordPress...
0
u/banksyisafraud Apr 15 '19
Can't tell if JS, but if so here's how I'd write it to make it a little clearer why you're messing about with the order: