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)
Then what does "same types" in this context mean? They have different types, but statically their types won't change?
Edit: Oh, I get it, there are multiple plugins loading for each "index", which isn't actually an index at all, but a type identifier? :-) Yeah, this is shitty programming allright.
Some constants or perhaps an enum would clear up the confusion greatly. With an additional note that the values are actually used as indices and can't be changed.
I'm curious to what the value() method returns. An array? A delimited string? Another identifier? The naming here is so confusing.
So the plugins are dependent of each other and the code will throw if any of them are missing, and (out of scope) roll back the previously attached plugins?
Edit: I'm only asking because I'm not sure if this is the intended behaviour. Maybe it's fine if plugin[2] is missing, but it should continue to load the rest of them anyway. With code like this, hiding away behaviour with exceptions can be really misleading if not documented properly.
Edit2: And while I think std::optional is a nice way to hide the nullability of pointers, it can introduce much unintended behaviour.
View all comments
Show parent comment
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.