Ayende @ Rahien

Hi!
My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:

ayende@ayende.com

+972 52-548-6969

, @ Q c

Posts: 08 | Comments: 19

filter by tags archive

Is Linq For Mortals?

time to read 2 min | 228 words

Mike Taulty has posted about Linq syntax, at the end, he shows a simple way to do joins and then aggregation between two collections. The code looks like this:

var a = products.Join(
      
sales,
        p => p.Id,
        s => s.ProductId,
      (p,s) => new { Country=s.Country, Sales=s.Sales, Product=p.Name })
.GroupBy( p => new { p.Country, p.Product })
.Select( gp => new { gp.Key, TotalSales = gp.Sum(s => s.Sales) });

I am sorry, but I cant read this. I can't even understand what this is meant to do. Now, I am the first to admit that my knowledge of Linq is weak at best, but still... Assume that I have a bug in such a code, how do I debug it?

That is a much bigger concern to me, I am not worried about learning the new stuff, I am worried about what I need to do when they break. I have some experiance in debugging applications via Reflector, and that is not nice. Especially if the compiler is doing funky magic and you are left reading the IL.


Comments

mawi

@ayende re luke

a linq query analyzer with F5 simplicity to make the cycle similarly quick, seems feasible though - doesn't it? (real question, I'm probably forgetting something)

Ayende Rahien

Not easily, no.

You would need to import all the referenced assemblies, etc.

It is possible, just not trivial.

Most so because often enough what would happen is the query won't run in memory but translated to some other form (SQL, XPath), which may cause wildly different results

Luke Breuer

@Ayende,

Perhaps one could do some IL munging to get the results set after each extension method call? I assume you are familiar with how LINQ syntactic sugar gets converted to a string of method calls?

Ayende Rahien

Yes, I know how it is translated, it is just that this is getting scary.

IL Munging is not for the faint of heart, and getting it wrong can be very confusing.

I wonder what the debugger guys are working on now.

Luke Breuer

The IL munging only needs to be done once if it is done well.

Comment preview

Comments have been closed on this topic.

FUTURE POSTS

  1. Production postmortem: The case of the memory eater and high load - 3 days from now
  2. Production postmortem: The case of the lying configuration file - 4 days from now
  3. Production postmortem: The industry at large - 5 days from now
  4. The insidious cost of allocations - 6 days from now
  5. Find the bug: The concurrent memory buster - 7 days from now

And 4 more posts are pending...

There are posts all the way to Sep 10, 2015

RECENT SERIES

  1. Find the bug (5):
    20 Apr 2011 - Why do I get a Null Reference Exception?
  2. Production postmortem (10):
    14 Aug 2015 - The case of the man in the middle
  3. What is new in RavenDB 3.5 (7):
    12 Aug 2015 - Monitoring support
  4. Career planning (6):
    24 Jul 2015 - The immortal choices aren't
View all series

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats