var q = from m in grains.OfType<Salt>()
where m.Value.Contains(null)
orderby m.irrelevance
select m;
return q.FirstOrDefault();
which fits in 80 characters on one screen. From this post and your reply, it seems like the your complaint is that LINQ is hard to understand if you write it poorly. But that's true of most programming.If you approach it as what it is, yes, a language-integrated query syntax, and avoid the fluent-chaining style most of the time, then you'll see an information-dense productivity booster instead of a "total mess".
The LINQ syntax fits on 1 sheet of paper:
http://www.albahari.com/nutshell/linqsyntax.aspx
Personally, I look at the two-tier language and library support as a case of "the easy things should be simple, and the hard things possible." That's just my own take, but I find that it guides thought process a little better. I look for a syntax solution first, then rewrite it using a chaining style if I need to (e.g. SelectMany), or possibly split into multiple queries. I don't think I've ever written one longer than 10 lines, properly formatted.Now, as far as python and other languages are concerned, LINQ is less "python in C#" and more "PEP 202 in C#".
The from item in blah syntax is just SQL rearranged, and SQL isn't as expressive as programming language constructs, so why try to emulate it?
It encourages you to write the grain of salt statement I mentioned earlier, which requires programmers to read through and understand the implementation of what you are doing, instead of it being embodied in a meaningful method and called. Of course you could just wrap that in a method, and slowly grow the line to 2-3 wide-screen monitors as you add more conditions.
The more tools you add to the core of a language, the more of a monstrosity of a kitchen sink it becomes (c#/.NET). Now you can loop over a list in 6 different ways! Hooray! That is why Dart looks good - a few basic concepts that can be used to build things suited to a particular problem.
grain.OfType<Salt>()
.Where(m => m.Value.Contains(nothing))
.OrderBy(m => m.irrelevance)
.FirstOrDefault();
I don't really get your verbosity criticism, sine any alternative I can think of (eg. using for loops) is much more verbose. grains.select{|g|
g.is_a?(Salt) && g.value.blank?
}.sort{|a,b|
a.irrelevance <=> b.irrelevance
}.first grains.select{|g|
g.is_a?(Salt) && g.value.nil?
}.sort_by(&:irrelevance).first
Edit: Changed from blank? to nil? since that is probably closer to nothing in C#. sort_by{|g|g.irrelevance}
source: http://www.ruby-doc.org/core-1.9.2/Enumerable.html#method-i-... $ ruby -e 'puts VERSION; p ["10", "2", "3"].sort_by(&:to_i)'
1.8.7
["2", "3", "10"]EDIT: said duck typing first. It's too early for thinking.
foreach (var g in grains) {
if (g.TypeOf() == "Salt" && g.Value == nothing)
saltGrains.Add(g);
}saltGrains.sort(m => m.Value.irellevance);
return saltGrains.First();
or something.