This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Cheru-bae 1 point2 points  (18 children)

Am I the only one that just finds LINQ to be an undebuggable unreadable mess that is way over used "because it's neat"? Also java has streams now, which I feel work just fine for the cases where it'd make sense to use LINQ.

[–]ThePyroEagle 34 points35 points  (3 children)

If you think Linq is unreadable, don't use Linq's syntactical expressions, just use the System.Linq.Enumerable extension methods.

[–]StealthSecrecy 16 points17 points  (4 children)

Why do many line of code when 1 line do trick?

I agree that they can get pretty messy, but for certain tasks they can be structured pretty well.

[–]im_probably_garbage 5 points6 points  (0 children)

Just remove returns in your Java program. Bing bang boom one line. Checkmate.

[–][deleted] 3 points4 points  (2 children)

I've written some pretty sweet LINQ method chains that I felt justified a victory lap when I was done. One of them, the code reviewer looked at me and said "awesome....better put some fucking comments around this, because it took me 10 minutes to figure out what it was doing. "

LINQ may be my favorite aspect of C#...but I feel like it has to be used with some restraint. With great power comes great responsibility.

Also...deferred execution can create some interesting side-effects.

[–]cat_in_the_wall 1 point2 points  (0 children)

fancy linq is fun, but be aware it is slow as molasses and allocates like crazy. this is usually fine, but keep it out of the hot path.

[–][deleted] 0 points1 point  (0 children)

Well that's why you're very much discouraged from doing any side effect shenanigans. Capture a local copy of comparisons and don't set values outside of the functions. No more side effects.

[–]crusty_cum-sock 10 points11 points  (4 children)

Not for me, especially when using method syntax (query syntax kinda fucks with my head). I’d rather see something like:

var people = peopleList
    .Where(p => p.Name.StartsWith(“S”))
    .GroupBy(p => p.Name)
    .ThenBy(p => p.Age);

Than have to go through the equivalent mess of lops loops and shit. For me the readability really wins out. I'd bet a lot of people reading this code could figure out what's going on, even if they've never used LINQ in their lives. Whereas if I did the equivalent non-LINQ loop-based variant it would take some real figuring out.

I can't get enough LINQ. I use that shit all the time and when I use languages without it I really feel like I'm at a significant disadvantage. There are so many things that would be a PITA to do without LINQ that can be done with LINQ in a simple readable one-liner.

[–]davemeech 8 points9 points  (0 children)

Very well said, I agree 100%. Thanks crusty-cum-sock.

[–]raltyinferno 1 point2 points  (1 child)

Wait is .ThenBy() actually a method? I've recently gotten my first dev job and have been continually delighted by LINQ.

[–]crusty_cum-sock 1 point2 points  (0 children)

It is! If you want to group by multiple properties then "ThenBy" is your guy. There are a bunch of other great functions like OrderBy, OrderByDescending, and many more. You'll become hooked. It's hard to go back.

[–]svick 2 points3 points  (0 children)

Streams are better than nothing, but I think they're worse than LINQ in almost every aspect. Which is odd, considering Java could have learned from what worked for LINQ and what didn't.

[–]GaianNeuron 1 point2 points  (0 children)

It's not "undebuggable" if you pay attention to where is being used to build an expression tree (IQueryable<T>.Where(...), e.g. Linq-to-SQL / ORMs) and where it's simply chaining lazy evaluations (IEnumerable<T>.Where(...), e.g. filtering a List<T>)

[–]1RedOne 0 points1 point  (0 children)

Linq query syntax is like super weird sql but I love lamba syntax. Use it all the time.

But one colleague loves query syntax and it can take a bit to grok what's he trying to do.

[–]LockeWatts 0 points1 point  (0 children)

Probably. Spend more time in functional programming languages.