views:

405

answers:

12

I know there are some nice new features in C# 4.0 but I can't, for the life of me, think of a compelling reason for either upgrading existing projects or for switching to new projects.

I've seen some posts where people have said that if their hosting service didn't provide .Net 4 that they'd find another provider as .Net 4 was pinicle to their direction <?>.

Now my boss is trying to get me to agree to switch all our production environments to C# 4 and to do it now.

So the question is has anyone either began using, or converted a project to, C# 4 for a compelling reason? Was there a feature that you just had to have that would make your life so much easier?

A: 

If you can get your boss to pop for the $10,000+ Visual Studio Ultimate Edition, IntelliTrace is a compelling reason to upgrade your environment and justification enough the for investment.

Bob Kaufman
it should be noted that we are a small startup and "money is too tight to mention".
griegs
... then your boss might not want to squander money on new software when the old works just fine! :)
Bob Kaufman
this is exactly my thinking also but people have done it and they must have a reason other than early adoption
griegs
I would like to point out that IntelliTrace can be used without upgrading projects to C#4. The decision to upgrade Visual Studio is a different one than upgrading all prjects to C#4.
Kirk
Is your company eligible for Microsoft's BizSpark program? If so, you can get MSDN (and hence VS) for free. If not, there's always the express editions (which of course don't have nifty things like unit tests / source control integration, etc).
RQDQ
We qualified for WebsiteSpark which is great so now we have VS 2010 Prof.
griegs
A: 

COM integration is much easier with the dynamic datatype, and optional parameters.

GvS
A: 

There are no compelling stability or security reasons to switch. Shouldn't that be your boss's concern?

BC
+4  A: 
  • Quite frankly System.Collections.Concurrent has made developing multi-threaded applications a breeze.

  • The new and improved System.Linq.Expressions makes writing dynamically compiled code seem like child's play.

  • The new named parameters feature means I can have big constructors and not get confused as to what each parameter is. Immutable objects are just that much easier.

ChaosPandion
I do like the concurrent feature yeah. it's pretty good.
griegs
`Collections.Concurrent` and the upgrades to L2SQL and (especially) L2EF are my main reasons
BlueRaja - Danny Pflughoeft
+1  A: 

If you're starting a new project today, it's probably best to start it on 4.0, since down the road you will have to migrate it at some point anyways (assuming it stays around long enough, older versions of .net will simply stop being supported).

C# 4 implies other things.. depending on your project... WCF 4, WPF 4, ASP.NET 4, MVC 2, Entity Framework 2, etc.. So don't just look at C# as the reason to change, you also have to look at the whole stack. If there's still nothing compelling, then staying where you're at is probably a wise choice.

Mystere Man
MEF out of the box ain't bad, either :)
Mark Simpson
+10  A: 

There are some cool new features in C# 4.0:

  • Dynamic member lookup
  • Covariant and contravariant generic type parameters
  • Optional ref Keyword when using COM
  • Optional parameters and named arguments
  • Indexed properties

In his release blog post Scott Guthrie goes into detail about the features of .NET 4 in general. Another great resource is a white paper at http://www.asp.net/learn/whitepapers/aspnet4. However, I'd doubt you are going to need one / any of these new features right away. As Scott Hanselman blogged:

there's a lot of stuff that's new and added in .NET 4, but not in that "overwhelming-I-need-to-relearn-everything" way.

Whether or not you should upgrade is therefore dependent on a variety of other factors. Some reasons that spring to mind:

  • Standardizing your development environment on a single platform VS2010 over VS2008.
  • Size of the .NET Framework is substantially reduced
  • Speed improvements if you are a Visual Studio Tools for Office developer

An open dialogue with your manager seems appropriate to understand his reasoning for the upgrade. I'd argue that because it's shiny isn't a compelling reason.

As a reference this dated Stack Overflow question "Why not upgrade to the latest .net framework" provides the inverse to your question.

ahsteele
+1, thank you for this. very helpful
griegs
I believe items 2-3 can be achieved targeting 3.5 with the 4.0 compiler as well (VS2010).
Marc
After reading 'Indexed properties' above I rushed to my VS2010 to try out this new feature. However, although indexed properties can be consumed (it's possible to access an indexed property using the bracket syntax) the language does not offer the ability to create indexed properties. So this feature has been added only for improving the syntax of COM interop.
Paul Ruane
+2  A: 

Is your question specific to C# 4.0, or .NET 4.0?

In C# 4.0 there are only a couple of really nice new features. Covariance/contravariance is not useful all the time, but when you run into a need for it, it can really save a lot of pain. Optional method parameters can reduce a lot of ugly method overrides, and make certain method calls a lot cleaner. If you're using COM or IronPython or any of a few similar frameworks, the dynamic keyword can also be a real lifesaver.

.NET 4.0 in general has a ton of really interesting features across a variety of frameworks. Foreign Key support in Linq to Entities, for example, is making life a lot easier for us. A lot of people are really excited about POCO support. They also added support for some of the LINQ methods (e.g. Distinct) that were previously missing from the Entity Framework.

So it will really all boil down to which frameworks you're using and how you're using them, and how expensive it will be for you to make the switch.

StriplingWarrior
+1 for co/contravariance. so nice when you need it.
Marc Bollinger
A: 

If you're doing WPF / Silverlight, I would definitely recommend upgrading to Visual Studio 2010 (I know, you can write .NET 4.0 code without an IDE, but that's an edge case if ever there were one).

The multi monitor support is nifty but buggy. I spend a lot of time trying to get windows to refresh.

In terms of language, the COM interop (as @Gvs mentioned) is also vastly improved with the dynamic datatype and optional parameters.

RQDQ
+1  A: 

First, what is compelling to me may mean nothing to you. Having said that, I would upgrade Visual Studio if budget allows. In fact, personally I think there is a huge career risk in staying with a company that doesn't keep your tools up to date. You will fall behind in your knowledge of the field without access to the latest tools.

As for converting all your projects just to convert them it seems like folly to me. Putting aside all the extra work distribution (and upgrading the machines to have .NET 4), you have to consider the chance that you will have something go wrong. (And if you are like me some things must be called from 3rd party programs using .NET 3.5 making them unable to convert.)

My first rule would be that nothing is converted unless you are working on it anyway. But I would seriously look to convert anything that could use improvement from either parallel code, or COM interop.

I do have a compelling project that was converted. I had a long running web method being called. In the version that exists now, I return from the method without knowing the results. Instead I gave the user a way to check later. By moving to a parallel foreach loop this works much better and I can let the user know if there were any errors.

The same project is also being converted to use RIA services which have greatly improved and reducing the amount of my own code.

Kirk
A: 

I upgraded for the same reason everyone else did.

...so I can put it on my resume :)

SteveCav
+3  A: 

Surprisingly not mentioned:

Marc Bollinger
A: 

For me there are two things:

  1. optional arguments -- because I am sick of polluting classes with X versions of the same method (overloading)
  2. dynamic keyword -- because the expressiveness of generics in C# is a joke, this way I can at least "write what I mean" without hoops, of course with execution speed penalty

The more compact the code (i.e. if you express the idea without addition "oh, how to avoid limitation Y of the language"), the better, because the code is much easier to maintain and it is harder to make a stupid (or worse) mistake.

macias