Hot Key Happiness

I use hot keys so frequently that I tend to take them for granted and forget that not everyone uses as many as I do.  Many times when I’m working with a colleague I habitually hit some key sequence that is immediately followed by a quizzical “How’d you do that!?” So, for the benefit of those looking for a few easy productivity enhancers I’m providing this simple list.  Although some well-known key sequences are included this post is in no way intended to be another all-inclusive list but rather just a listing of those that I find most useful from day-to-day.

Windows 7

My primary operating system is Windows 7. With Windows 7 Microsoft was kind enough to give us lots of new hot keys for positioning windows and switching between applications in addition to leaving traditional ones in place.

Window Position/Management

Windows Key + D
Show desktop

Windows Key + P
Change projector/2nd monitor mode (duplicate, extend, etc…)

Windows Key + Up Arrow
Maximize window

Windows Key + Down Arrow
Restore/minimize window

Windows Key + Shift + Right | Left Arrow
Move window to different monitor

Switching Between Applications

Windows Key + [task bar index #]
Start a new instance of the item at the specified index or switch to the active instance if it is already running
Example: Assuming Internet Explorer is the first item on the task bar Windows Key + 1 will open IE.

Windows Key + Shift + [task bar index #]
Force a new instance of the item at the specified index to start

Alt + Shift + Tab
Cycle backwards through task chooser
No, I’m not going to describe the version w/o shift. Also, I hardly ever the alternative Aero Flip (Windows Key + Tab) but sometimes it’s handy. :)

Visual Studio 2010

Although Visual Studio 2010 is now RTM and exposes some nice functionality through hot keys but most of my favorites have been in place for quite some time. A great resource for learning some of the lesser-known (or sometimes rather well-known) is Zain Naboulsi‘s Visual Studio Tips and Tricks blog.

Code Formatting

Ctrl + E, D
Format document

Ctrl + E, F
Format selection

Code Navigation

F12
Go to definition

Shift + F12 (or Ctrl + K, R)
Find all references

Ctrl + K, Ctrl + T
View call hierarchy

Ctrl + G
Go to line

Ctrl + –
Navigate backward

Ctrl + Shift + –
Navigate forward

Ctrl + B, T
Toggle bookmark

Ctrl + B, N
Go to next bookmark

Ctrl + B, P
Go to previous bookmark

Ctrl + B, C
Delete all bookmarks

Commenting

Ctrl + E, C (or Ctrl + K, C)
Comment line/selection

Ctrl + E, U (or Ctrl + K, U)
Uncomment line/selection

Outlining

Ctrl + M, Ctrl + H
Hide current selection

Ctrl + M, L
Toggle all outlining

Ctrl + M, M
Toggle outlining expansion

Refactoring

Ctrl + R, R (or F2)
Rename symbol

Ctrl + R, M
Extract method

Breakpoints

F9
Toggle breakpoint

Ctrl + Shift + F9
Delete all breakpoints

Ctrl + D, N
Break at function

Miscellaneous

Shift + Alt + C
Add class to project

Ctrl + E, S (or Ctrl + R, W)
Show/Hide whitespace characters

LINQ: IEnumerable to DataTable

Over the past several months I’ve been promoting LINQ pretty heavily at work.  Several of my coworkers have jumped on the bandwagon and are realizing how much power is available to them.

This week two of my coworkers were working on unrelated projects but both needed to convert a list of simple objects to a DataTable and asked me for an easy way to do it.  LINQ to DataSet provides wonderful functionality for exposing DataTables to LINQ expressions and converting the data into another structure but it doesn’t have anything for turning a collection of objects into a DataTable.  Lucky for us LINQ makes this task really easy.

First we need to use reflection to get the properties for the type we’re converting to a DataTable.

var props = typeof(MyClass).GetProperties();

Once we have our property list we build the structure of the DataTable by converting the PropertyInfo[] into DataColumn[].  We can add each DataColumn to the DataTable at one time with the AddRange method.

var dt = new DataTable();
dt.Columns.AddRange(
  props.Select(p => new DataColumn(p.Name, p.PropertyType)).ToArray()
);

Now that the structure is defined all that’s left is to populate the DataTable.  This is also trivial since the Add method on the Rows collection has an overload that accepts params object[] as an argument.  With LINQ we can easily build a list of property values for each object, convert that list to an array, and pass it to the Add method.

source.ToList().ForEach(
  i => dt.Rows.Add(props.Select(p =>; p.GetValue(i, null)).ToArray())
);

That’s all there is to it for collections of simple objects.  Those familiar with LINQ to DataSet might note that the example doesn’t use the CopyToDataTable extension method.  The main reason for adding the rows directly to the DataTable instead of using CopyToDataTable is that we’d be doing extra work.  CopyToDataTable accepts IEnumerable but constrains T to DataRow.  In order to make use of the extension method (or its overloads) we still have to iterate over the source collection to convert each item into a DataRow, add each row into a collection, then call CopyToDataTable with that collection.  By adding the rows directly to the DataTable we avoid the extra step altogether.

We can now bring the above code together into a functional example. To run this example open LINQPad, change the language selection to C# Program, and paste the code into the snippet editor.

class MyClass
{
  public Guid ID { get; set; }
  public int ItemNumber { get; set; }
  public string Name { get; set; }
  public bool Active { get; set; }
}

IEnumerable<MyClass> BuildList(int count)
{
  return Enumerable
    .Range(1, count)
    .Select(
      i =>
      new MyClass()
      {
        ID = Guid.NewGuid(),
        ItemNumber = i,
        Name = String.Format("Item {0}", i),
        Active = (i % 2 == 0)
      }
    );
}

DataTable ConvertToDataTable<TSource>(IEnumerable<TSource> source)
{
  var props = typeof(TSource).GetProperties();

  var dt = new DataTable();
  dt.Columns.AddRange(
    props.Select(p => new DataColumn(p.Name, p.PropertyType)).ToArray()
  );

  source.ToList().ForEach(
    i => dt.Rows.Add(props.Select(p => p.GetValue(i, null)).ToArray())
  );

  return dt;
}

void Main()
{
  var dt = ConvertToDataTable(
    BuildList(100)
  );

  // NOTE: The Dump() method below is a LINQPad extension method.
  //       To run this example outside of LINQPad this method
  //       will need to be revised.

  Console.WriteLine(dt.GetType().FullName);
  dt.Dump();
}

Of course there are other ways to accomplish this and the full example has some holes but it’s pretty easy to expand. An obvious enhancement would be to rename the ConvertToDataTable method and change it to handle child collections and return a full DataSet.

KalamazooX Recap

The KalamazooX conference was held on Saturday, April 10.  It lived up to the expectations set by all of the positive comments I’ve seen and heard about last year’s event.   This year’s event consisted of eleven sessions that lasted approximately 30 minutes each.  The sessions all focused on soft rather than technical skills.  It really was worth the trip.

Be a Better Developer

Presented By: Mike Wood

A few days before the conference I read through Mike’s blog posts about this subject and was looking forward to hearing him present the abbreviated version.  I highly recommend reading through the full series.

Key Points

  • Don’t be a code monkey
    • Code monkey’s are expendible minions
    • Stand out from the crowd
    • Thinking about programming can’t stop at 5:01 PM

If all your learning happens on the job, all you learn is the job.

  • “Shift” happens
    • Learn to deal with change
    • Keep up with changes in the field
    • “Steal” time to learn
      • Listen to podcasts during a commute
      • Study over lunch
    • Find a mentor
  • Be a salesman
    • Need to sell yourself and ideas
    • Don’t be a sleazy salesman

Additional Resources

Why Testing is Important

Presented By: Phil Japikse
As I mentioned in a previous post, Phil recently spoke about Behavior Driven Development (BDD) at the March IndyNDA meeting.  This session touched a bit on BDD but only briefly.

“If you don’t test, your customers will.”

Key Points

  • Unit Testing
    • Testing individual blocks leads to better certainty that the system as a whole will work
    • Helps close the developer/requirements mismatch by becoming a rapid feedback loop
    • Helps improve team trust through collective ownership
    • Provides a safety net for change
    • Helps with estimation by identifying points of impact
  • Test Driven Development
    • Less code – only develop enough to satisfy requirements
    • Higher code coverage – tests are written up front rather than never due to schedule constraints
    • Cleaner design – code is written in small increments

Women in Technology: Why You Should Care and How You Can Help

Presented By: Jennifer Marsman

Although Jennifer’s talk was focused on attracting women to technology and keeping them there she started off with a general discussion about diversity.  What I really appreciated about this portion of her talk was how she made a point to show that diversity doesn’t need to be restricted to race and that a group of white males from differing backgrounds counts as diversity as well.

Key Points

  • Two Problems
    • Recruiting
      • No interest
    • Retention
      • Reasons women leave the field
        • Lack of role models
        • Lack of mentors and career coaching
        • Sexual Harassment
  • Addressing Recruiting
    • Need to get them interested in the first place
      • Encourage daughters
      • Leverage obsessions
        • Wouldn’t it be cool to build facebook?
  • Addressing Retention
    • Understand that men can be mentors for women
    • Connect women to each other
    • Have women speak at conferences
      • Avoid having a “token” woman for PC reasons
    • Understand that harassement does exist
      • Often not blatantly but as the summation of many little things
      • Realize that men worry about it too

Additional Resources

What Tools Should Be In Your Workshop

Presented By: Tim Wingfield

I sat in on Tim’s Care About Your Craft talk at IndyCodeCamp last year and was happy to see him speaking at KalamazooX.  In this session Tim lists a number of tools that he believes should be in every developer’s toolbox.  He challenged everyone to start using some of these tools.  Lucky for me, my dev team and I already use many of them.

Tools For The Team

  • Whiteboard/Giant 3M Post-it sheets
  • IM/Twitter
  • Wiki
  • Issue/Change Tracking software
  • Source Control
    • Subversion
    • git
  • Build Server
    • Cruise Control
    • Team City
    • Hudson

Tools For The Individual

  • Text Editor
    • Notepad++
    • TextMate
    • vi/vim/emacs
  • Command Shell
  • Scripting Language
    • Python
    • Ruby
    • perl
  • Your Brain
    • Care about your craft
    • Think about what you’re doing
    • Read often
    • Do critical analysis

Additional Resources

Stone Soup, or a Culture of Change

Presented By: James Bender

James focused on being a change agent in your organization.  Large, sweeping changes are scary but by changing things incrementally we can often get to the large change with less disruption.

“Change where you work or change where you work.”

Stone Soup

  1. Find low-hanging fruit
    • Unit Testing
    • Refactoring toward SOLID
    • Abstraction
    • Agile practices
  2. Make small but meaningful changes
  3. Support and simmer
    • People need time and help to adjust
    • As results are noticed future changes will be met with less resistence

Tips

  • Don’t judge
  • Know your tools
  • Only introduce changes you believe in
  • Add value
  • Know when to stop
  • Evangelize about the changes
  • Build a network of like-minded people
  • Realize it may be difficult to reach everyone
  • When all else fails, try bribery
  • Be patient

Treating the Community Like a Pile of Crap Makes it Stronger

Presented By: Brian H. Prince

As odd as the session title sounds Brian’s talk was one of the most engaging sessions of the day.  In his talk he compared the development community with working with a compost or manure pile.  Over time, the top layers get crusty and the pile needs to be turned to keep it fresh.  The same holds true for communities.

Brian observed that community leaders tend to get burned-out after around 2-3 years.  Once the burn-out sets in many leaders stop participating and there’s often no one to take their place.  Community leaders need to plan for their succession.  They need to discover, engage, and groom the next generation of leaders to get them involved and keep the community alive.

Churn the pile of crap to attract new flies and keep the pile fresh or watch it dry up and disappear.

Agile+UX: The Great Convergence of User Centered Design and Iterative Development

Presented By: John Hwang

I didn’t take many notes from this session.  As interesting as the topic was it moved really quickly and to me it seemed to really be trying to compress way too much information into such a short time-span.  I might be interested in hearing more about this in a more expanded time slot but it didn’t really seem right for KalamazooX.

Toward the end of this session I received the first of several phone calls regarding a family emergency (more on that later) so I was a bit distracted.

How to Work Effectively with a Designer/ How to Work Effectively with a Developer

Presented By: Amelia Marschall & Jeff McWherter

Amelia and Jeff discussed overcoming some of the difficulties that are often encountered when developers and designers need to work together on a project.  I didn’t get many notes from this session either due to the aforementioned family emergency but I still managed a few. 

Key Points

  • Know each other’s abilities
    • All designers and developers are not created equal
      • Some designers know CSS and HTML, some don’t
      • Some developers are decent designers, others aren’t
  • Set boundaries
  • Set a workflow
  • Create code that a designer can read
  • Create designs a developer can implement
  • Do things to make the other person’s life easier
    • Educate each other
    • Ask questions

Additional Resources

Does Your Code Tell a Story?

Presented By: Alan Stevens

This was the last session I was able to attend.  After travelling eight hours one-way from Knoxville, TN (wow!) to present for a whopping 30 minutes Alan understandably requested that attendees to put away all of their electronic devices.  This was the first time I’d heard him speak and I’m truly glad I was able to stay for this one.  It was one of the highlights of the day.

There’s a big difference between having 10 years of experience and having 1 year of experience 10 times.

Key Points

  • Beauty is the ultimate defense against complexity
  • Read alot, write alot
  • Beauty is the ultimate defense against complexity
  • Write shitty first drafts
  • Beauty is the ultimate defense against complexity

Missed Sessions

During the Agile+UX session I received a call from my mother.  When she left a voicemail I knew something was wrong.  My wife had either broken or dislocated her ankle getting out of the car and was in an incredible amount of pain, and being taken by ambulance to Bronson Methodist Hospital in Kalamazoo.  I had to leave the conference early and as a result I missed the final two sessions.

  • Unwritten Rules of Resumes
  • Have You Hugged Your Brand Today?

I was sorry to have to leave early and my apologies to the speakers but family emergencies take priority.  When I got to the hospital the nurses were taking X-Rays of her ankle.  Amazingly her ankle was not broken but she really had dislocated the ankle bones and had to undergo conscious sedation to put them back in place.  The procedure was successful so no surgery was required.  She’ll be wearing a partial plaster splint for a few weeks.

The ER staff at Bronson was great.  Everyone we worked with was very attentive and did everything they could to make sure that my wife was as comfortable as she could be.  Should we ever be in need of medical services while in Kalamazoo I know where I’ll be looking.

Luckily she wasn’t carrying our 5 month old at the time and both my mom and aunt were there to help her.  We both appreciate their help.

For the curious, I snapped a picture of the ankle before the procedure.

Change Log 

4/12/2010

After sleeping a few hours and driving to work I remembered two things I had intended to include.  I added a paraphrased quote to the notes for both Mike Woods’ and Alan Stevens’ sessions.  I also promoted a quote from Phil Japikse’s session from being a bullet point.

LINQPad: An Essential Tool For .NET

A few days ago I was reading through my Twitter feed on my phone when I read a post about a tool called LINQPad.  This was the first time I’d heard of it so I hopped over to the LINQPad web site to see what it was all about.  After a few minutes of browsing I made a mental note to download and try it when I got back to my laptop.  I’m glad I did.

I’ve been using LINQPad for a little less than a week now and it quickly found a place in my toolkit right next to Visual Studio.  In fact, if I have VS open chances are good that LINQPad is also open.  What could a tool named “LINQPad” do to get such good placement in my toolkit?  Isn’t it just for playing with and learning LINQ?  In short, no.  LINQPad is much more than its name implies.

Capabilities

LINQPad does offer great support for LINQ.  Full support for LINQ to Objects, LINQ to XML, and LINQ to SQL is available out of the box.  One of the most powerful features is LINQPad’s ability to connect to a SQL Server database and automatically build classes to represent the tables and columns allowing the database to be queried using LINQ to SQL rather than traditional SQL.  No setup beyond entering the connection information is necessary.  Entity Framework and WCF Data Services are also supported.  But that’s just LINQ!  Didn’t I say it’s more than its name implies?

I find that the real power of LINQPad comes from its ability to execute any C# or VB expression, statement, or program.  This capability has some implications for ad-hoc testing and prototyping.  Instead of littering your development folder(s) with simple single-use console applications just use LINQPad to prove-out a piece of code then copy/paste the code into your project.  You can even add references to existing assemblies to expose the functionality to your ad-hoc code.

I mentioned that LINQPad supports execution of any C# or VB expression, statement, or program but what exactly does that mean?  Depending on the selected language option LINQPad will behave a bit differently.

Expression

The expression option allows a single C#/VB expression.  This is useful for testing regular expressions, playing with string formatting options, or anything else that can be expressed with a single line of code.

Statement(s)

More often than not our ad-hoc code will need more than one line.  This is where the statement(s) option comes in.  I’ve found this useful for prototyping and solidifying the body of a method and for executing database queries.

Program

The Program option is the most robust of the three.  It allows an entire program complete with a Main() method and classes to be written within LINQPad.  The possibilities here are endless.

Using LINQPad for ad-hoc testing should supplement rather than replace formal unit testing.  Formal unit testing included with the project’s build process is still very important for on-going development.

Availability

LINQPad is not an open source project but it is offered free of charge.  An auto-completion add-on is available for a small fee.  The software can be downloaded as either a stand-alone executable or a low-impact installer from the LINQPad web site.  All that’s really needed is .NET 3.5.

Given the power for the price I highly recommend grabbing a copy and at least trying it out.  Consider giving the LINQPad Challenge a try.  What do you have to lose?

At Least One of Us Still Drives a MINI

When we were browsing Babies “R” Us for our baby registry what seems forever ago this bouncer really caught my eye because it looked just like my MINI. We added it to the registry and were fortunate enough to have someone buy it for Nadia.

Shortly after she was born we realized that the Prius was too small to haul the stroller and well, anything else. That meant that if we wanted to go anywhere we were going to need a bigger vehicle. A few days later I was trading in the MINI for a Hyundai Santa Fe.

Esther and I eventually traded vehicles. The Prius is a great car with all of the amenities but it’s nothing like the MINI. I get envious every time I see one on the road and there are plenty of them around here so it’s pretty much a daily occurrence. I guess for now I’ll just have to live vicariously through her for a while.

What is this?

Recently I’ve been updating one of our older utilities to .NET 4.  A few days ago I stumbled across this line of C#:

if(this == null) return null;

I was dumbfounded.  When would that ever evaluate to true?  Worse yet, why was it repeated in two other places?

Out of curiosity (read: late night boredom) I did some research to see if there’s ever a case where the condition would be met and found a good discussion over on Stack Overflow.  There apparently are a few cases where this == null could actually be true:

  1. Overload the == operator to explicitly return true when comparing to null.
  2. Pass this to a base constructor as part of a closure.

Neither of these cases applied to this code.  We weren’t overloading the == operator and we certainly weren’t using it in a closure let alone a closure being passed to a base constructor.  The second case has apparently been fixed for .NET 4 so it definitely wouldn’t apply with the changes I was making.

As part of the Stack Overflow discussion Eric Lippert provided an interesting comment about why the C# compiler doesn’t complain about checking for this == null.   He basically says that the compiler doesn’t complain because they didn’t think about it because it’s obviously wrong.  So for those wondering, yes, I eliminated all three instances of this code from the utility.

Kalamazoo X Sessions

The organizers of the Kalamazoo X Conference recently posted the session and speaker list.  All of the sessions sound interesting but the ones that have really grabbed my interest are:

I’ve previously attended two of Mike Wood’s presentations (one at Indy Code Camp and an nPlus1 event in Indianapolis) and really get a lot from them.  He has posted a series of articles about being a better developer that I admittedly haven’t read yet but will probably do so before April 10th.

I was also fortunate enough to hear Phil Japikse speak about Behavior Driven Development at the March IndyNDA meeting.  He shared tons of great information about methodologies and tools and I’m really looking forward to hearing more of his thoughts on testing.

I was really excited about this conference based on what I’d heard about last year’s event.  After seeing the session list I’m glad I registered.

IndyTechFest

Last year I made the mistake of missing IndyTechFest.  That’s not a mistake I care to repeat and one I certainly will not be making this year since my registration is already confirmed.

This year’s event includes forty sessions broken out into seven tracks.  The sessions are of interest to developers, architects, and DBAs and include topics such as Silverlight, WPF, Visual Studio, Windows and SQL Azure, Windows Phone 7 Series, Database Maintenance, SharePoint, Iron Ruby, and many, many more.  The list of speakers is equally impressive and is topped off with a keynote from Jesse Liberty, a Developer Community Program Manager for Silverlight.

Registration is limited to 500 attendees and with more than 400 spaces already spoken for time is running out!

I hope to see you there.

SOLID Principles

Today was nPlus1‘s sixth ever architecture summit.  This summit was held in Indianapolis, IN and addressed the SOLID principles.  The presenters were Mike Wood and Dan Rigsby.

The SOLID principles were originally defined by Robert Martin as a set of guidelines for writing better code.  As with any guidelines, these are not steadfast rules that must always be followed but proper application of these principles can make code more maintainable, flexible, and readable.  There is a plethora of information about these principles so rather than going into detail about each of them this article just includes a brief description of each one.

One argument against using some of these principles is that following them will result in more code.  Some may argue that having more classes and interfaces will ultimately make the system too difficult to understand.  The counterpoint to these arguments is that there are no more moving parts in a system with many small pieces than a system with a few large ones.  That is, if it’s doing the same thing it should be no more or less difficult to understand.  The trade-off to more code is a system that is more accepting of change when (not if) it comes.

Additional Resources

Kalamazoo X Conference

This past weekend I learned of the upcoming Kalamazoo X Conference, a one day conference in Kalamazoo, MI.  Instead of focusing on individual technologies or languages this conference places emphasis on “softer” skills such as communication, interface and graphic design, development processes, and architectural concerns.

According to the conference web site the conference will be held on April 10, 2010 but registration is not yet open and the venue hasn’t been announced.

I think it sounds like a great excuse to take Nadia up to visit her grandparents.  Anyone want to meet up?

More Information:

Conference Web Site: http://kalamazoox.org
Twitter: @kalamazoox