tags:

views:

389

answers:

10

I use LINQ in my code all the time. I've gotten to the point where it just seems so natural to Group, Order, an organize a bunch of objects using the LINQ syntax that I struggle to think how I would do the same things without it.

I had never delved into the SQL-esque world before this, but I imagine many people who learned even the normal SQL syntax suddenly felt constricted by most normal programming languages abilities to wrangle complex object hierarchies?

Am I painting myself into a corner becoming reliant on LINQ to do my more complex tasks? It just feels so much more expressive than if I wrote plain C# code.

Is becoming dependent on the LINQ syntax in my day-to-day programming going to hurt me in the long run if I end up switching languages or frameworks where something like it isn't available?

+23  A: 

Fortunately, no. The "LINQ" way of thinking is more properly understood as a "functional" way of thinking, and this is a highly transferable mindset.

Obviously when you move from language to language and framework to framework the syntax and framework methods will be different but the mindset is the same. The important skill that you have aquired is the ability to think in terms of sequences and functional pipelines that process those sequences.

Andrew Hare
I never really got the hype around F# until I started working with LINQ and writing extension methods. I now find my entities are becoming "dumber" and the logic is making its way into static utility classes.
Matthew Whited
True about it just being a special case of functional programming. It may surprise you that it even transfers very well to something as old-school as C++, which has a standard library with quite a few similarities. It's not quite Linq, but it's much the same way to think about manipulating sequences of objects. So go ahead and use Linq as much as possible. It transfers well to most languages, and even in the ones with no direct support for anything like it, it's a useful mindset to have.
jalf
@Matthew Whited: Is it a good thing that your logic is outside your entity classes. I think otherwise. Could you please clarify. Thanks
StackUnderflow
+4  A: 

Does it matter? Every language has its unique nice features. It's like saying "Will using braces in C# make it hard to transfer it to another non curly brace language?"

Mehrdad Afshari
It matters to me, yes. This is not curly braces, this is changing the way I write code day to day and in a significant way. Did you read my question?
If you are talking about the "concepts" behind LINQ, they've been existed long before C# and many languages (e.g. Python) support those ideas. They've been around since Lisp days.
Mehrdad Afshari
BTW, yes, I had read your question. I know many people who rely on "query expression" syntax of LINQ (and no nothing about the concepts) and their way of writing code is also changed significantly. My answer is more targeted at the "query syntax" feature.
Mehrdad Afshari
If it changes the way you code, then it is because it is a useful concept. The more familiar you are with useful concepts, the better you'll be able to make use of them, even if you're forced to work in a language that doesn't directly support them. If the Linq mindset better allows you to express what you want to do, use it. The ability to express what you want to do is important in any language. ;)
jalf
@jalf: I agree. As I said in my comment above, my mindset about the word "LINQ" is mostly the query expression syntax. I completely agree with Andrew's answer that the underlying concepts are just functional programming concepts. Indeed that's why I don't really count things like lambda expressions as LINQ. IMO, they are not LINQ but the thing that LINQ is implemented with.
Mehrdad Afshari
+8  A: 

Instead of looking at your prospective future outside of C#, I would concentrate on what helps you get your work done today.

If that means using and becoming fluent with LINQ, so be it. As long as you're willing to learn and adapt in the future (just like today) it won't be that big of an issue.

micahtan
+3  A: 

Its not going to hurt you. I truly believe all modern languages are going to move to this syntax very shortly. Java is already moving in that direction, and other languages will follow with something similar. MS, for all of the bashing they take, were way ahead of the curve on this one. The wiped out a whole class of bugs related to temporary variables/arrays in terms of querying array objects. The benefits to this are enormous.

Steve
A: 

Yes, it will hurt you if LINQ to SQL is the only sql you know.

dotjoe
Indeed. BTW, I'd argue LINQ to SQL is not SQL... :)
Mehrdad Afshari
+3  A: 

Yes, your concern is valid.

That is, when you get good at using any tool, you start to forget how to function well without the tool. You also get frustrated when that tool is not available.

For millions of years humans were able to feed themselves without the use of metal tools. They weren't miserable. Today very few know how to do that, and most are scared of what that would be like.

For tens of years humans wrote software without real-time interaction with a computer, e.g. punch cards. They weren't miserable. Today very few know how to do that. The idea of doing that sounds miserable to me.

If you become adept with Linq, you will miss it when it's not around. It's a great tool. As your skill with Linq grows, your skill of programming without Linq (which you aren't practicing) will become rusty.

In all the above cases, we have replaced a human skill with a tool + a new human skill. Each time, the idea of giving up the tool sounds scary. I believe there's always some value in exploring the older, lower-tech way of doing things, as it helps me become more well-rounded, but usually I'll pick the higher-tech way.

So, don't shy away from Linq, but do explore other ways of doing things, as part of your self-education as a programmer.

Jay Bazuzi
"... without the use of metal tools" well guess thats why they gave you sqlmetal.exe
DotDot
+1  A: 

LINQ is a great thing. It will spread. In fact, the spread has already begun.

Nosredna
A: 

I find that understanding the logic behind it helps me feel better about using LINQ extension methods. If you can write your own Where or Group ..etc extension methods then there is no shame in using them.

Stan R.
+1  A: 

If it could be equated to learning OO, I know people who have gone from C to an OO language and back to C and although they didn't have objects available, they tended to be able to use many techniques in a language without objects.

Could the same thing happen with LINQ?

Bill K
A: 

I think it's important to understand what's going on behind the scenes of high-level abstractions like LINQ - otherwise you can have problems such as performance. Funnily enough our host's latest blog post is on this subject.

So if "thinking in LINQ" means forgetting this, which I suspect it does for some developers (present company excepted), it could be considered "bad".

Joe