Posts Tagged ‘Programming Productivity’

For an accountant, programming productivity can be defined as lines of clean, simple, correct, well-documented code per day. Actually, searching the web you can find a bunch of good/bad definitions but, as for the majority of my posts, here I’m going to refer to my real experience, being as much pragmatic as I can, then I’m not very interested in analysing all the possible definitions.

I like thinking as an engineer and for me productivity is a measure of the efficiency of production. Following this short post, we can say productivity is the value of code produced divided by the time spent to write it:

Productivity = Value / Time

So, there are two ways of increasing productivity:

  • Increase the value
  • Decrease the time spent to obtain it

The first point is non-trivial and can lead to an extremely long, full-of-abstract-conclusions discussion. What is value for a programmer? It’s not easy to say. You can read articles and books, work and code a lot but you probably won’t get a sole answer. In this post I’m going to deal with the second issue, giving you some practical examples about saving coding time and, as the title suggests, I’ll consider a specific technology that is C++ on Visual Studio (both 2010 and 2012).

One of the most common rumors about C++ is about poor productivity. I’ve heard tons of people saying that a C++ developer can’t be as fast as a C# or Java one, and that refactoring tools are quite helpless. I think this is true to all appearances, if one doesn’t go beyond its IDE or editor. I think productivity is about discipline. From reducing the mouse usage and applying loads of shortcuts, to studying/elaborating practices to be faster (not only about pure coding).

The first simple thing you can do is to use keyboard as much as possible and further. Why using three clicks when a combination of two keys suffices? Consider a trivial example: setting the start-up project in a solution. Suppose we have a huge solution with about a hundred projects, with some executables (the main program and several test projects). Why do we have to:

  • found the project to run (t1)
  • right-click on it (t2)
  • locate the “Set as a start-up project” menu item (t3)
  • click (t4)

when we rather could:

  • found the project to run (ts1)
  • left-click on it (ts2)
  • press ALT+S+S (ts3)

t1 and ts1 (“s” stands for “shortcut”) are equal, the same applies to t2 and ts2, but ts3 is dramatically faster that t3 (+ t4) because it requires no mental effort, no reading time and no mouse-movement-and-click. You just have to remember a shortcut and this will be a kind of automatic gesture if you do it a couple of times.

I’m sure you already use shortcuts, anyhow setting them in Visual Studio is a trifle: just click on Tools, then Options and then Keyboard in the Environment section, as follows:

Another shortcut I can’t live without regards the pending changes tab and the compare with latest version feature. (if you use TFS, you know them). Basically I press:

  • CTRL+ALT+Home to show the Pending changes tab
  • I move among pending files with Up and Down keys
  • I press CTRL+ALT+PageUp to enter in the compare-with-latest-version mode

This way I don’t need to take my hands off the keyboard, being faster (thanks Gigi for this!).

Other shortcuts you shouldn’t miss are about compilation, such as solution building, project building, compile single file (Visual Studio should have them by default). They are helpful because, when adding or changing things, it is generally good to do sort of incremental compilation, maybe starting from a single file (if it is new) and then building the entire solution (or project, if the changes are very localized). Other related tips (or practices, if you prefer) such as “run all tests” and “make incremental check-ins” can help a lot your productivity but they are part of another story.

So, shortcuts are valuable allies, aren’t they? Practice. Customize your environment. What kind of actions can you perform faster by using shortcuts? Comprehend and, eventually, change your development process.

Ok, these themes are universal and they always apply, regardless of language and editor/IDE. Now, I’ll spend some words on a specific Visual Studio extension that can help your productivity: Visual Assist X. A standard license costs less than 300$ and I think it’s worth having a copy.

This tool not only has some standard refactoring features such as Extract method and Create from usage, but also C++ specific aids such as Add include. It goes without saying that you might (and should) bind each action to a custom shortcut. I’ve measured I’ve been significantly faster since I’ve started making use of Visual Assist X. That’s because it lets you focus on coding rather than some non-core aspects such as what file must be included (even if sometimes it’s worth including by hand for advanced stuff) or declaring a member-function in the header file while you’re writing it in the cpp file. It’s cool.

Other Visual Assist’s gems are some how-is-it-possible-visual-studio-does-not-have-them, like:

  • quick find references – find usages of functions and classes (Shift+ALT+F by default)
  • quick open file in solution (Shift+ALT+O by default)
  • quick find symbols (Shift+ALT+S by default)
  • quick swith between header and source (ALT+O by default)
  • quick methods listing (ALT+M by default)

Convince your boss to buy it!

Last (but not least) pearl is about snippets (that are very common in this kind of tools – for example in Resharper for C# development) that is heavily useful (in C++ as well as in other languages). A snippet is just a shortcut that triggers a text (parameterizable) replacement.

For instance, on my configuration, if you write:

once and then you press TAB you’ll get:

#pragma once

With this simple snippet (triggered by cout followed by TAB):

cout << $end$ << endl;

You’ll  generate:

cout << -->cursorHere<-- << endl;

More complicated:

lam then TAB:

[$capture$] ($params$) { $end$ }

and a small dialog will appear asking for $capture$ and $params$ (possibly empty) and then creates a lambda expression replacing $capture$ and $params$:

And you’ll get:

[&takeThisByRef, aValue]() { -->cursorHere<-- }

Have fun with snippets and, as usual, create those you (really) need.

In this post I showed some simple tricks to increase your productivity coding in C++ on Visual Studio. These are futile if you don’t discipline yourself, if you don’t practice and if you don’t explore your IDE and its possibile extensions/plugins. For example, some people don’t know the possibility to vertical-select text in Visual Studio:

Do you?