The Daily WTF
Cicely (previously) returned to the codebase which was providing annoyances last time.
This time, the code is meant for constructing objects based on a URL pattern. Specifically, the URL might have a format like api/resource/{id}. Looking at one of the constructors, though, it didn’t want an ID, it wanted an array of them. Cicely wasn’t passing multiple IDs off the URL, and wasn’t clear, from the documentation, how it worked, how you supplied those IDs, or frankly, what they were used for. Digging into the C# code made it clear, but still raised some additional questions.
int[] ids = Request.FormOrQuerystring(“ids”).EnsureNotNull().Split(“,”). Select(item => item.ToInt32()).Concat(new int[] { id }).ToArray();
Whitespace added for readability, the original was on one line.
This is one of those cases where the code isn’t precisely bad, or wrong. At worst, it’s inefficient with all the LINQs and new arrays. It’s just… why would you do
To read the full article click on the 'post' link at the top.