Jeremy D. Miller -- The Shade Tree Developer

Sponsors

The Lounge

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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?

Posted 01-29-2008 7:40 PM by Jeremy D. Miller

[Advertisement]

Comments

Nermin wrote re: Jeremy hearts C# 3.0
on 01-29-2008 8:24 PM

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.

Jeremy D. Miller wrote re: Jeremy hearts C# 3.0
on 01-29-2008 8:48 PM

@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.

Nermin wrote re: Jeremy hearts C# 3.0
on 01-29-2008 9:03 PM

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

Jimmy Bogard wrote re: Jeremy hearts C# 3.0
on 01-29-2008 9:43 PM

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.

Chad Myers wrote re: Jeremy hearts C# 3.0
on 01-29-2008 11:26 PM

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

List<string> stringList = new List<String>(){ "Foo", "Bar", "Baz"};

Chris Vickerson wrote re: Jeremy hearts C# 3.0
on 01-30-2008 12:49 AM

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

- you can turn off the arrows.

Jeremy D. Miller wrote re: Jeremy hearts C# 3.0
on 01-30-2008 4:53 AM

@Chad,

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

DotNetKicks.com wrote Jeremy hearts C# 3.0
on 01-30-2008 5:55 AM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Kent Boogaart wrote re: Jeremy hearts C# 3.0
on 01-30-2008 7:51 AM

Type inference looks like a finger-saver too.

Jeremy D. Miller wrote re: Jeremy hearts C# 3.0
on 01-30-2008 7:57 AM

I forgot about that!  I'm not using it much yet because ReSharper really doesn't like it.  But SomeType<OtherType<YetOtherType<Dictionary<string, string>>>> is too darned ugly to see twice.

» Daily Bits - January 30, 2008 Alvin Ashcraft’s Daily Geek Bits: Daily links, development, gadgets and raising rugrats. wrote &raquo; Daily Bits - January 30, 2008 Alvin Ashcraft&#8217;s Daily Geek Bits: Daily links, development, gadgets and raising rugrats.
on 01-30-2008 8:33 AM

Pingback from  &raquo; Daily Bits - January 30, 2008 Alvin Ashcraft&#8217;s Daily Geek Bits: Daily links, development, gadgets and raising rugrats.

Aaron Erickson wrote re: Jeremy hearts C# 3.0
on 01-30-2008 8:46 AM

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.

Jimmy Bogard wrote re: Jeremy hearts C# 3.0
on 01-30-2008 2:34 PM

Almost forgot anonymous types too...

How about features I'm afraid of?

Partial methods come to mind.

David Fauber wrote re: Jeremy hearts C# 3.0
on 01-30-2008 5:54 PM

Extension methods are far and away my favorite new feature.

on 03-14-2008 9:36 AM

When I was growing up I used to occasionally hear the saying &quot;a Moped is just fast enough to get

http://139641.subversion.codebetter.com/blogs/jeremy.miller/archive/2008/01/29/jeremy-hearts-c-3-0.aspx wrote http://139641.subversion.codebetter.com/blogs/jeremy.miller/archive/2008/01/29/jeremy-hearts-c-3-0.aspx
on 03-28-2008 5:54 AM
Ultram. wrote Ultram er tablets.
on 06-13-2008 10:51 AM

Ultram. Ultram er. Order ultram no prescription.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?