Jeremy hearts C# 3.0

Never let it be said that I can’t say something nice about a Microsoft product.  I’m not enthusiastic about VS2008 itself until ReSharper 4.0 is here and stable, but the new language features rock!  I haven’t even touched any of the LINQ dialects yet, but all those little features that Anders and co added to support LINQ are already making my life easier.

  • Extension Methods:  I’m mostly using Bellware’s nunit-spec extensions for RSpec-style assertions in unit tests like someObject.SomeMethod().ShouldEqual(expected);  I’ve also used them very sparingly to extend a fluent interface from an external assembly.  It’s working, but let’s call that an experiment in progress
  • Object Initializers:  These make test data setup code soooo much more compact.  Especially the initializers for collections.  As silly as it sounds, I’d almost call this the single best thing about .Net 3.5 just because of the mechanical savings.
  • Lambda Expressions:  Besides being so much tighter than anonymous delegates, I’m digging the ability to get at the expression tree.  My old MicroControllers idea in C# 3.0 looks like this:  _binder.Bind(x => x.QuoteDate).To(quoteDateField).WithLabel(quoteDateLabel);  See the little Lambda trick in bold?  Gotta love the compiler safe reflection goodness.  The tighter syntax is also making it easier to utilize some functional-lite programming that cuts down on code here and there.

What do you like about C# 3?  What are you doing that wasn’t possible in C# 2?

About Jeremy Miller

Jeremy is the Chief Software Architect at Dovetail Software, the coolest ISV in Austin. Jeremy began his IT career writing "Shadow IT" applications to automate his engineering documentation, then wandered into software development because it looked like more fun. Jeremy is the author of the open source StructureMap tool for Dependency Injection with .Net, StoryTeller for supercharged acceptance testing in .Net, and one of the principal developers behind FubuMVC. Jeremy's thoughts on all things software can be found at The Shade Tree Developer at http://codebetter.com/jeremymiller.
This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://www.fauberdemo.com/rankings.html David Fauber

    Extension methods are far and away my favorite new feature.

  • http://jimmybogard.lostechies.com Jimmy Bogard

    Almost forgot anonymous types too…

    How about features I’m afraid of?

    Partial methods come to mind.

  • http://blog.magenic.com/blogs/aarone Aaron Erickson

    Adding to the choir – lambdas are teh kewl. Personally, I also love how we have gone full circle with the new property declarations that create an implicit member. (e.g. public Foobar {get; set;} now implementing the property)

    The problem is that you start with C# lambdas as a gateway drug that leads to you shooting F# in a dark alley within months.

  • http://codebetter.com/blogs/jeremy.miller Jeremy D. Miller

    I forgot about that! I’m not using it much yet because ReSharper really doesn’t like it. But SomeType>>> is too darned ugly to see twice.

  • http://kentb.blogspot.com Kent Boogaart

    Type inference looks like a finger-saver too.

  • http://codebetter.com/blogs/jeremy.miller Jeremy D. Miller

    @Chad,

    Absolutely. That’s what really makes test data setup easy.

  • Chris Vickerson

    “I still won’t consider Refactor Pro. Those arrows going everywhere freak me out.”

    - you can turn off the arrows.

  • http://chadmyers.lostechies.com Chad Myers

    @Jeremy At the risk of insulting you, did you happen to notice the collection initializers in addition to the object initializers?

    List stringList = new List(){ “Foo”, “Bar”, “Baz”};

  • http://jimmybogard.lostechies.com Jimmy Bogard

    Well, NBehave’s been a non-starter until C# 3, so pretty much all of the above.

    I still won’t consider Refactor Pro. Those arrows going everywhere freak me out.

  • http://www.nermins.net Nermin

    Funny thing is that I am doing the same – checking their site daily, hoping for at least Beta/Preview release of 4.0.

  • http://codebetter.com/blogs/jeremy.miller Jeremy D. Miller

    @Nermin,

    Roy Osherove left that tip last week. It helps, but then you lose other goodness. Part of my morning routine now is to check the ReSharper page.

  • http://www.nermins.net Nermin

    One trick for VS 2008+ReSharper. For files that have a lot of Extension methods amd Lambda expressions use Ctr+8 (it turns off or on Resharper validation for that file only). Thanks to that I have been using ReSharper 3.1 with VS 2008 for a while.