May 2009 - Posts

Not so Hidden Gems in VS 2010

I’m just going to assume that all readers of my blog know that Visual Studio 2010 Beta one has been released.

I’ve been running it almost exclusively since I downloaded and installed it. There’s a lot to like. For this first post, I’m going to limit my discussion to a very small set of IDE features that thrill me in the new release.

Tear away editor and tool windows

This is a neat feature for single monitor work, but is absolutely wonderful in a multi-monitor scenario.  In VS2010, you can grab the title tab in an editor window (design or code window) and move it out of the VS IDE frame window. It’s wonderful when you’re trying to do some work that requires examining more than one code file at a time.

The fact is that this feature works for tool windows as well as editor windows.  In my setup, I’ve tried to maximize my main code window in the main monitor.  Properties, Solution Explorer, and the build output windows are on the secondary monitor. I’ll pull editor windows out when I need to see multiple code (or designer) files for a particular task.

PascalCased IntelliSense

Love this for discovering classes or methods in the .NET Base Class Libraries. Intellisense now picks up targets that contain the words you type, even if they are not at the beginning. For example, if you type ‘enumer’ in a code window, Intellisense will (as always) contain Enumerable. It will also contain IEnumerable, IOrderedEnumerable, and ParallelEnumerable.

It’s a great way to discover something that might be the solution to your current coding problems.

Real TDD Support: Generate From Usage

Create From Usage means you can really follow a TDD methodology. You can right test scenarios that describe how you want to use a class. Once you’ve written the test, you have a test that doesn’t compile (like now). Right click on each item with red squiggles and select “Generate”.  Types allow you to generate a new class (quick default), or “Generate Other” which displays a dialog that lets you select a class, interface, enum, or struct. Furthermore, that dialog lets you select the access modifiers on the type, select a destination project (if you have multiple projects in your solution).  You can follow the same workflow to generate methods or properties once you’ve created the types.

The IDE will create members that throw NotImplementedExceptions, so all your tests will fail. But, isn’t that the point of TDD?  Once you have those failing tests, you have a task list to make them green.

In future posts, I’ll touch on more of the major features in VS 2010. I wanted to start with these hidden gems because they can be so easily overlooked if you just start using the new version with your old work patterns.

Upcoming Event: MI Software Stimulus Lab

The software industry will be part of the underpinnings for the jobs of the future. (You can read more of my thoughts on the importance of Software to Michigan’s future here).

We created our company to create great software, and help others to do the same. In the current climate, we are holding a series of low cost labs to help developers learn skills currently in demand. Free scholarships are available for developers currently unemployed and in need of updating their skills.

The first of these labs will be at Automation Alley on Monday June 15th.  You can read more about the event here.  You can sign up here.

Please inform other interested developers of the event.

Query Language or Method calls: A matter of taste

My last post (which was too long ago), generated question on whether I prefer the query language or the method notation for LINQ queries.

The answer is ‘yes’.  Jon Skeet mentioned this as well last January, but anything you can do with query syntax can be accomplished with method calls. (Item 36 of More Effective C# discusses is some detail how the query language operators map to method calls.)

From the standpoint of correctness, you can use either construct with no differences. That means it is a matter of style whether you choose the query expressions or the method calls.

My own preference is to use the method call syntax for simpler queries, and use the query syntax for more complex query operations.

For example, I would use the method call syntax below over the query syntax:

   1: int[] numbers = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
   2: var smallNumbers = from n in numbers
   3:                    where n < 5
   4:                    select n;
   5:  
   6: var smallNumbers2 = numbers.Where((n) => n < 5);

However, once a query gets sufficiently complex, I believe the query syntax is more readable:

   1: int[] odds = { 1, 3, 5, 7 };
   2: int[] evens = { 2, 4, 6, 8 };
   3: var values = from oddNumber in odds
   4:             from evenNumber in evens
   5:             where oddNumber > evenNumber
   6:             select new { oddNumber, evenNumber, 
   7:             Sum = oddNumber + evenNumber };
   8:  
   9: var values2 = odds.SelectMany(oddNumber => evens,
  10:     (oddNumber, evenNumber) =>
  11:     new { oddNumber, evenNumber })
  12:     .Where(pair => pair.oddNumber > pair.evenNumber).
  13:     Select(pair => new { 
  14:         pair.oddNumber, 
  15:         pair.evenNumber, 
  16:         Sum = pair.oddNumber + pair.evenNumber });

In my opinion, for more complex queries, the query language produces a much more readable construct. However, on simpler queries, the method calls are easier to understand.

I like Jon’s comment: “next time you’re writing a query expression, take a look at it afterwards – it it’s simple, try writing it without the extra syntactic sugar.” (from the post referenced above).

Search

Go

Blog Group Links

Nascar style badges