Just in case it ever disappears from StackOverflow, I want to quickly capture my favorite Skeet comment from StackOverflow:

We might see some abuse. We might also see some much simpler code where we just want a tuple, basically. Not everything needs to be an object with complex behaviour. Sometimes "just the data" is the Right Thing. IMO, of course. โ€“ Jon Skeet Feb 10 '09 at 23:18

insert alt text

What I really like about Skeet's comment here is that he shows he's [likely] always considering the anti-pattern. Too many developers hear rules from people they respect and start spouting them as gospel without 1.) checking to see if they really are the best way to approach a problem, and 2.) without continually double-checking that decision when they run into new, real-world problems that challenge the rule.

Say what you will about returning anonymous types, there's an argument for it. I love to use anonymous types as return objects for controller actions, when it's appropriate and you don't need a viewmodel (or already have one to reuse (which is essentially the same thing)). I've also, on my personal projects, caught myself using Tuples with more frequency than I'd expect. Is there a case to use anonymous types further up the line? Perhaps! If there's a repository method that's always producing read-only data, perhaps!

It's not whether the answer's right. There often isn't a kneejerk Right Thing To Do. It's that you consider every reasonable answer before deciding on today's solution.

That is, stop the cargo culting. Your fellow coders will, eventually, thank you for it, because a deliberate culture makes everyone a better coder.

Labels: , , ,