Ayende @ Rahien

It's a girl

Dense code

The amount of information that you can push into just a few lines of code keeps amazing me.

image

This is doing so much stuff that it is just creepy. And yes, it is quite elegant at the same time, since it is handling the required scenario in such a simple manner.

Comments

Tim Jones
10/26/2009 11:01 AM by
Tim Jones

You could replace the "Count() == 0" conditions with "!Any()" for additional elegance :)

Eugene Burmako
10/26/2009 11:30 AM by
Eugene Burmako

Yeah, quite scary, barely debuggable, but I vote for such style. Imho a drastic increase in the quality of both reading (conciseness = less to read, easier to understand) and writing (conciseness = less points to introduce an error) far supercedes these inconveniences. And after all most of the time it's only the signature that matters to this method's user.

Rasmus Faber
10/26/2009 11:39 AM by
Rasmus Faber

The Pluralize-method seems a bit naive. Try calling it with "boy" or "monkey".

hitechnical
10/26/2009 11:47 AM by
hitechnical

Pluralize :) ... lol

Jason Jarrett
10/26/2009 12:28 PM by
Jason Jarrett

You might want to look at .ToList()ing the enumerabe variables, as leaving them as enumerable will cause "elements" and "attributes" variable to be re-evaluated each time you do anything with them (such as attributes.Count()) - this method may perform a little faster as well...

Thilak Nathen
10/26/2009 12:32 PM by
Thilak Nathen

@Eugene

The code is perfectly debuggable. You realist the debugger allows you to step through linq statements even on vs 2008.

Rafal
10/26/2009 04:29 PM by
Rafal

Is it Newtonsoft.Json?

anon
10/26/2009 06:37 PM by
anon

Pls comment your code :)

Eugene Burmako
10/27/2009 10:29 AM by
Eugene Burmako

@Thilak

Debugging lazy LINQ-to-Objects queries is quite inconvenient in comparison with debugging regular collections. Yeh, you can still "enumerate the results", but it's an extra click/keystroke as opposed to watching a collection with a debug visualizer.

And, what's more important, you can't watch the result of partial application of a query, e.g. the result of lines 4 and 5, but not 6 on the screenshot above). The best what I can come with is to manually refactor subquery into a local variable, but this requires manual work tho R# can alleviate it significantly. Usually, one has to repeat this for a few times because it's rare to find a bug at the very first watch you perform.

Comments have been closed on this topic.