CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeremy D. Miller -- The Shade Tree Developer

Under the hood and working with .Net, TDD, Software Design, and Agile Stuff

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?


Comments

Nermin said:

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.

# January 29, 2008 8:24 PM

Jeremy D. Miller said:

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

# January 29, 2008 8:48 PM

Nermin said:

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

# January 29, 2008 9:03 PM

Jimmy Bogard said:

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.

# January 29, 2008 9:43 PM

Chad Myers said:

@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"};

# January 29, 2008 11:26 PM

Chris Vickerson said:

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

- you can turn off the arrows.

# January 30, 2008 12:49 AM

Jeremy D. Miller said:

@Chad,

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

# January 30, 2008 4:53 AM

DotNetKicks.com said:

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

# January 30, 2008 5:55 AM

Kent Boogaart said:

Type inference looks like a finger-saver too.

# January 30, 2008 7:51 AM

Jeremy D. Miller said:

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.

# January 30, 2008 7:57 AM

» Daily Bits - January 30, 2008 Alvin Ashcraft’s Daily Geek Bits: Daily links, development, gadgets and raising rugrats. said:

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

# January 30, 2008 8:33 AM

Aaron Erickson said:

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.

# January 30, 2008 8:46 AM

Jimmy Bogard said:

Almost forgot anonymous types too...

How about features I'm afraid of?

Partial methods come to mind.

# January 30, 2008 2:34 PM

David Fauber said:

Extension methods are far and away my favorite new feature.

# January 30, 2008 5:54 PM

Jeremy D. Miller -- The Shade Tree Developer said:

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

# March 14, 2008 9:36 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Jeremy D. Miller

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 previously worked as a systems architect building mission critical supply chain software for a Fortune 100 company and learned agile development practices as a .Net consultant at ThoughtWorks, one of the pioneers of agile development. Jeremy is the author of the open source StructureMap (http://structuremap.sourceforge.net) tool for Dependency Injection with .Net and the forthcoming StoryTeller (http://storyteller.tigris.org) tool for supercharged FIT testing in .Net. Jeremy's thoughts on just about everything software related can be found on his weblog "The Shade Tree Developer" at http://codebetter.com/blogs/jeremy.miller, part of the popular CodeBetter site. Jeremy is a Microsoft MVP for C#. Check out Devlicio.us!

This Blog

Syndication

News

All opinions expressed here constitute my (Jeremy D. Miller's) personal opinion, and do not necessarily represent the opinion of any other organization or person, including (but not limited to) my fellow employees, my employer, its clients or their agents.

About Me

"Best Of" Compendium

StructureMap (Dependency Injection for .Net)

StoryTeller (Supercharged Fit)

Build your own Cab

TestDriven

MVP