views:

2031

answers:

20

Where I work I see a lot of otherwise very talented C++ developers produce ugly C# code, purely because they are not as familiar with the .NET framework and the features of C#.

Now I only started programming relatively recently, but already wheras I am very familiar with .NET 2.0 I find myself rarely (if ever) using any features of .NET 3.5:

  • I have never used "var"
  • I have no idea what Lambda expressions are

I'm not worried about encountering code that I don't understand - if I see any new feature that I'm not familiar with I'll just look it up, but I am a tad worried that that by not keeping up-to date with these new features I'm gradually being left behind (especially with more new features arriving in C# 4.0 just around the corner.)

Should I be making more of an effort to learn and use these new features on a day-to-day basis, or am I OK for the moment?

+14  A: 

You are OK for the moment. As long as you are adding value.

But you should prepare for the day when the newer feaures become the norm. E.g. try using the newer features on non-critical projects. E.g. small utilities for your own use.

Peter Mortensen
I like the idea of trying it out on non-critical projects. I might go further and state that you try it in personal/tiny projects - using something new in code that will be supported by others who may not know the technology might make negatively impact how you are perceived by others including your boss (or make you a star - but it's a risk).
Mayo
+7  A: 

Find something you can develop in your own time in the evening and weekends and try and use the latest and greatest features of the language in that. It doesn't have to be anything world shattering.

For example, over the last few months I've written three very simple apps to use and manage my music collection. I started them using C# on .NET 2.0, but have changed them to use the 3.5 framework. I've even rewritten one in WPF and used Spring.NET to practice (basic) dependency injection. I want to rewrite another of them using out of browser Silverlight, but I can't seem to find the time at the moment, though now 4.0 is in beta I really should.

Even though none of these were particularly difficult they've given me an understanding of some of the new features of the language.

Another approach is to work through some of the online tutorials and videos. I found the ASP.MVC one informative (though I'm not writing ASP.NET websites any more) and as that used LINQ it gave me a fairly good grounding in the area. Search for the areas you're interested in - there are lots of tutorials out there.

ChrisF
+32  A: 

Well, .NET 3.0 is (largely) WCF, WF and WPF; WCF is useful for a better comms API; but workflow is still a bit flakey, and if you don't need WPF you simply don't need WPF (i.e. if you are mainly server-based (including web), or are happy with your winforms for the moment).

However; .NET 3.5 carries LINQ; even if you don't use the database stuff, the query syntax and improved sequence handling is very versatile and can vastly simplify a lot of code that works with collections (and collection/sequence processing). So LINQ(-to-objects) probably is worth investigating, to see if you are missing a trick. Note that you can use LINQ-to-Objects on .NET 2.0 (with C# 3.0 / VS2008), via LINQBridge; so you don't (necessarily) need to target the new framework to use the new features.

And of course you might choose to investigate the ORM side too (but there are perfectly good non-LINQ ORM tools). It also includes a lot of other things like XDocument; if you use a lot of xml this may be useful. And there are tons or other changes...

In many ways, .NET 4.0 is a much more minor change; dynamic and parallel being the highlights. The second may be important if you do a lot of threaded code.

Marc Gravell
code contracts are the highlights ! >_<
Nicolas Dorier
@Slashene - I was meaning in terms of core changes to the "do something" libraries... code contracts aid development, but do nothing for the end-user experience (except deliver code that stands more chance of being on-time and defect-free, but who wants that?)
Marc Gravell
http://stackoverflow.com/questions/8676/entity-framework-vs-linq-to-sql - be wary that LINQ-to-SQL *may* not have a clear future (at least in its current form)
Mayo
It is also, at least for now, IMO the better product (compared to EF) ;-p That *may* change in 4.0 - I haven't done a full analysis.
Marc Gravell
The number of people who believe EF is superior to Linq to SQL seems *very* small. If they fail to achieve at least parity in 4.0 then I see trouble ahead.
ShuggyCoUk
WF is flakey is an understatement.
womp
@Mayo that's old, I don't have the link at hand, but we have gone over that and there is v. clear info that linq2sql will continue to exist/be improved
eglasius
Oh, absolutely LINQ-to-SQL will continue to evolve; there are bug fixes and minor VAEs in 4.0; just not the same level of development as EF.
Marc Gravell
+1 I Agree with this a lot more than the accepted answer.
Kyle Rozendo
+2  A: 

In my experience, only if you're regularly using LINQ do you really need to know about Lambda expressions, the var keyword, anonymous types, the new kinds of initializers, and such.

LINQ is very convenient for doing operations on generalized lists, but not really a necessity either. You can use all the LINQ query operations by just calling static methods (those of System.Linq.Enumerable) too.

You might want to read What's New in Visual C# to get an overview of what you're 'missing' and which parts seem interesting enough to look at. I suggest you just keep programming whichever way you're comfortable, and slowly try to expand your comfort zone just in case it'll help you make better programs.

Joren
Not true. I hardly use LINQ in practice, but it would be very difficult for me to no longer use lambdas. C# moving more towards the functional programming paradigm is much more important than "LINQ = SQL in your code" (because that's just not what it is, basically).
peSHIr
Yes, I also use lambdas way more often than LINQ. But talking about whether you *need* lambdas, I don't think you do except for with LINQ, as anonymous methods do most of the things lambdas do. (All except expression trees? I'm not entirely sure.) Of course lambdas are way more expressive and convenient than any other kind of delegates.
Joren
+5  A: 

If you're code works then you don't need the features of .NET 3.x. The two features you mentioned, var and lambda expressions, are syntactical sugar (for the most part). They are there to make your life, and the lives of other developers who need to read your code, easier.

However, why put off learning something new? A lot of the new features being released in .NET 4.0 build upon the features added in 3.x. If you wait until 4.0 is released you'll simply be further behind.

Edit: Mistakenly typed 'LINQ' instead of 'lambda expressions'. Responded before I had my coffee.

Justin R.
He didn't mention LINQ, he mentioned lambda expressions. While I admit they are related (in the fact that one is used in the implementation of the other), they basically have "nothing to do with each other".
peSHIr
Thanks for pointing that out - I correct the statement in my post.
Justin R.
+4  A: 

I disagree with people which says to test these features in a side project. The best thing to do is to read .NET blogs and articles, because a lots of people share cool ideas and practical use cases of these features.

If it's really a cool idea, you will want to use it in your own project, even critical because you are persuated that it will help you.

One example of cool idea with expression trees and lambda expression is the possibility to create a method which return the name a property and keeps type safety.

String a;
String name = GetPropertyName(()=>a.Length);
//name == "Length"

I became aware of expression trees once someone in a blog told this trick.

Nicolas Dorier
Reading is great, and I wouldn't under-recommend it - but as the sole learning mechanism, it'll never top *doing* as a means of learning.
Erik Forbes
@Erik, I can't agree more. I just disagree with the fact that you should experiment on side project. Because most of the times, these side projects are not realistic enough to evaluate a feature. And sometimes, you can't see the usefulness of a feature if you have not seen any cool idea based on it.You can learn the "how" with practices, the "why" comes from people with cool ideas and expertise.
Nicolas Dorier
+19  A: 

Lots of people writing lots of stuff. Let me be short about it: You are missing out on some way cool and productive stuff.

Frankly, I'd rather hit myself with a hammer than go without lambdas and linq, not to mention WPF, WCF, MVC, and all the other amazing stuff we have in our toolboxes.

Will
I disagree - you'd use what you'd need to use and not because it's the latest greatest. And when time comes or there is a need, you'd use what you haven't used before. Linq is a pretty handy tool to have, but I will not kill myself if I do not use WPF and MVC. In the famous (not exact) words of Grady Booch: "an electric drill is a nifty piece of tool, but it does not always make a great hammer".
Partha Choudhury
@Partha: but if you don't know that lambdas or LINQ or yield offered more elegant ways to do things, then well... you'd never know that you were missing out.
Alex Baranosky
@GordonG - if an existing software option is not working great for me, I start getting itchy all over and start looking for what else is out there and then if I find something that gives me a beter option or makes my life simpler, I embrace it. But I don't try to fit my sqare project in a round solution just because that's the current hot stuff in the block. For example, I started looking at Linq when I was working on a project that was using a lot of xml and List<T> as datasource - and it came real handy. On the other hand, I think I'm sticking to my winforms and web apps for now.
Partha Choudhury
@partha - you ever DO remoting using the old 2.0 method? I did. I wanted to kill myself. Having to connect to a process without WCF is crazy complicated and badly documented. WPF? Beautiful, flexible, and the binding is a dream compared to forms. MVC? I cut the codebase for a website in half by converting it to MVC from ASP.NET. Its more like the difference between an electric drill and a deer antler.
Will
+11  A: 

It depends what kind of work you're doing. If you're iterating over collections and using delegates in .Net 2.0 for example, you should really consider using LINQ, or Lambda Expressions and the extension methods provided by LINQ.

For example, if you want to search a List<T> of Person objects and pull out those matching a certain criteria, in .Net 2.0 you'd perhaps use the FindAll(Predicate<T> match) method, where you could supply the predicate as an anonymous method:

people.FindAll(delegate(Person p) { return p.FirstName == "Bob"; });

Whereas with Lambdas and the Where Linq extension method, this becomes

people.Where(p => p.FirstName == "Bob");

Or with full-blown Linq (probably a bit overkill in this case):

from p in people
where p.FirstName == "Bob"
select p;

Using LINQ (either the complete expression syntax above or the extension methods with Lambdas) can make your code much easier to write, and more importantly much clearer to future readers. You can get rid of all the bloated delegate syntax and just concentrate on what you're trying to do.

Graham Clark
Lambdas for the win! I even see them easier to read than complete expression syntax.
Arnis L.
Me too, and there are plenty of Linq extension methods that don't have an equivalent expression syntax (so are only available through Lambda / delegate syntax).
Graham Clark
Definitely agree. More and more modern libraries/frameworks (such as Moq) are using the lambda syntax in their APIs. If you don't grok lambdas, you'll be lost. And as Partario mentioned, LINQ makes dealing with collections (and XML, and...) much simpler.
TrueWill
+3  A: 

You're not missing anything by ignoring .NET 3.0 (except for WPF which is less exciting than it sounds), but .NET 3.5 adds a whole bunch of useful features as you and others have already mentioned.

However, given that you've used neither, why not just go straight to .NET 4.0? The beta is available for download, and it has all the cool features of .NET 3.5 plus additional ones such as the dynamic keyword which is explained very well in this blog entry:

http://tore.vestues.no/2009/01/05/creating-a-dynamic-xml-reader-with-c-40

IMO, neither var nor lambda expressions nor LINQ are particularly difficult concepts to understand; if you have a good understanding of .NET in general you won't have any problems picking up on how to use these new constructs.

Ian Kemp
+1 for xml reader
Arnis L.
+2  A: 

One of the bigger problems I face is that to use the features of .NET Framework 3.0/3.5 is that I have to upgrade from Visual Studio 2005 (VS2008 is needed). We're not just talking about whether to learn this stuff - but whether you are allowed to install the tools to do so. VS2008 Express could be used as a temporary shortcut around this problem, if you have a decent level of control over your development PC =)

It'll be harder to learn those features if you don't have a right IDE available at your workplace.

Joel Goodwin
It's a shame that some workplaces won't pay for VS2008 for its developers.
Jim G.
Well, in these credit crunching times... =) But it's not just the cost, it's the red tape and having to wait for your Company to build a network-deployable package if they don't already have one. It may kill a chunk of time trying to get that organised and the more pragmatic may just pass on it.
Joel Goodwin
+7  A: 

Seems like Joel Spolsky had an article that half-jokingly accused Microsoft of pushing out so much new technology specifically to keep developers on their heels. I think it's probably wise to balance. I would say at this point, if you aren't at least aware of lambdas, auto-properties, WPF, MVC, and Linq, it might be a good idea to at least gloss over them and see what they're about.

turboneat
http://www.joelonsoftware.com/articles/fog0000000339.html
Arnis L.
+2  A: 

As has been mentioned already, LINQ and the IEnumerable extensions are the big things you should try to get to grips with. I am not saying that you'll be left behind if you don't use them, but they are incredibly useful things for boosting productivity.

Your original question talks of "ugly code" produced by C++ devs. I guess this is your point of view from a perspective of being well-versed in a newer language. Imagine how youer own code today will look in a year's time when you have got to grips with the newer goodies in the framework... I've only been using LINQ and the other goodnesses for a short time, and I can't begin to imagine how I put up with the convoluted code I used to write to achieve the same effects.

ZombieSheep
+22  A: 

Let me answer a slightly different question.

Should I be making more of an effort to learn and use LINQ and lambda expressions on a day-to-day basis?

Unequivocally, yes.

Question: Could you finish C# projects without knowing how to type?
Answer: Well yes you could; but you'd pale in comparison to your typist brethren.

I don't embrace everything that is shiny and new in the programming world; but LINQ and lambda expressions will soon be must-haves for C# programmers.

And if I've convinced you, then I recommend that you read Linq in Action.

--

Unless there's a pressing need, I'd defer learning Windows Workflow.
On DotNetRocks, Brian Noyes noted that WF 4.0 will include significant changes.

Jim G.
Since then I've started a new side project involving lots of collections and I've realised lambda expressions are just awesome!
Kragen
I agree; these features are mostly extra libraries and syntactic sugar that you don't have to use, but their use makes your code simpler and more readable - if you know how to read it (you have learn to read LINQ statements and Lamda expressions).
Travis Heseman
+1  A: 

Wow, all these people loving .Net 3x? I'm a 2.0'er as well and frankly it has everything I need. I'm aware of and have some experience with 3x features... I can honestly say the only thing I miss is Extension Methods. Funny huh... Yes I know I can still use them and auto properties on the 2.0 framework if I use the 3.5 build tools, however, to prevent other problems we force the build tools to 2.0.

Frankly my opinion of C#3.0 (as in the language extensions included in 3.5) is not a good one. I see it as 'syntactic sugar'. Yes it can make your code a little tighter but you can do anything in 2.0 that you can do in 3x with a little more typing. Honestly, I would rather MS had spent the last few years fixing defects and adding capabilities in the framework rather than sugar-coating the language.

So will 4.0 be a different story? From everything I've read my hope is that it will be.

Oh, and to directly answer your original question: Yes you need to know 3.5 in the current job market.

csharptest.net
" I would rather MS had spent the last few years fixing defects and adding capabilities in the framework...": Which framework defects annoy you the most? Which capabilities does the framework lack?
Jim G.
"...Rather than sugar-coating the language.": Smartly 'sugar-coating the language' (as you put it) makes developers enormously more productive and makes the code more maintainable.
Jim G.
I don't deny that it provides some productivity imrovements as well as cleaning up some code. I just believe that we would benefit MORE from different improvements, not that we didn't see an improvement.
csharptest.net
You could say that 'foreach' is sugar-coating when you've got a 'for' statement. I think lambda's and linq are just the next evolutionary step. When you've used List<>.RemoveAll(x => x...) you'll start to see the light.
Jon Mitchell
Lambda functions aren't really sugar-coating. They add a functional paradigm to a previously non-functional language.
Matt
+1  A: 

Not really, but...

Software development is a career that's all about constant learning. We're like knowledge sharks and the job gets dull quick if there isn't something new.

In terms of jobs right now a C#3.5 expert is worth more than a C#2 one. Devs with cutting edge experience mostly earn more than those without (up to a point - you can earn serious money working in decrepit tech cause no-one else wants to, just look at COBOL).

That shouldn't influence you if you're happy doing what you doing and there's new and interesting challenges for you every day in what you're doing now.

Don't worry about the new stuff - when you get to it dive right in and you'll figure it all out soon enough. It's always harder to learn about things in abstract than when you're trying to make them work.

Keith
+3  A: 

Yes. IMHO you are getting left behind.

Ok, some reasons.

Clearly the man is getting left behind. Right now he is only "somewhat behind", but even he notices that there are some things he does not know/understand about this new .NET 3.5 stuff. That is the definition of BEHIND.

If he carries on this way, then soon he will REALLY be behind. Right now it is something he can easily deal with by googling and learning. So it's all good (for now..........).

Alex Baranosky
-1: I agree with you, but you need to back up your opinion with some reasons.
Jim G.
+1 everyone is entitled to an opinion. I think the original question was seeking just that, substantiated or not.
csharptest.net
I added some more detail. Maybe I can get my rep back :( Hehehe.
Alex Baranosky
+1: Thanks for adding your reasons.
Jim G.
phew... much better
Alex Baranosky
+1  A: 

You do not really need var except then using anonymous types. In all other cases var may safe you a bit typing.

If you do not use linq then you aren't forced to use lambda expressions. Delegates will do also, especially the short delegate{} syntax.

In my opinion, most c#3+ features are only invented to save you a bit typing, but makes code much harder to read.

When I sometimes see such "overcleverly" written code with nested expression trees making heavy use of generic lambdas, Iam asking myself where are we going.

Sure it is always fun and interesting to write such code, but very hard to understand it if you read it, even when you wrote it yourself.

codymanix
A: 

You are getting left behind, but paradoxically it isn't anything to worry about. Think about a language or framework as being analogous to a factory that produces widgets of some sort. If you, as the factory owner, spend all of your time and money perpetually retooling the machines to employ the latest technologies, you will go out of business because your factory will never actually produce any widgets. If however, you tool up with the latest technologies and then let your factory run along for a few years, it will produce a huge mess of widgets and you will make a lot of money. Eventually you will get beaten by a competitor using new technology, and you will have to shut your factory down and start the process all over again.

Similarly, with a platform like .Net it makes sense to update your skills with the latest stuff and then let yourself churn out a bunch of software without worrying much about the new things that come along. You will eventually reach a point where the young bucks are able to turn things out two or three times faster than you, or you may hit a point where your knowledge of .Net is so out-of-date that you get laughed out of job interviews, and that will tell you that it's time to shut the factory down and bring in the latest machine tools.

Personally, I'm still using .Net 2.0 and WinForms, because these are things that I'm thoroughly familiar with, and because LINQ and WPF (while undeniably powerful in many contexts) aren't very useful for a software synthesizer with a completely owner-drawn user interface. If you're still writing applications using the tools that you're comfortable with, and your clients are happy and/or you still have a job, don't sweat the new stuff. You can learn the new stuff if and when you need it.

I do have a confession to make, however: I've absorbed a lot about these new technologies just from reading StackOverflow questions on the subject, and I would probably feel somewhat more overwhelmed by them if not for that.

MusiGenesis
+1  A: 

A programming language without lambda is like a day without sunshine.

Brian
+1  A: 

I think the answer is probably, "Yes, but slowly." Your value to your employer is not whether you use all the latest technologies, it's whether you do good work, on time and within budget. The newer technologies (like LINQ) could very well make you more productive, but as you realize, it takes valuable time to master them. I've recently put some serious effort into familiarizing myself with a bunch of new .NET 3.5 technologies. It all started with this brief, which provides a very nice (and quick) introduction to the critical new technologies. It doesn't really cover LINQ, but in literally 10 minutes, you will at least get a glimpse of what you're missing.

DanM