Automated refactoring for C++

During the year that I  was on a Java project, I found Eclipse’s automated refactoring tools such a productivity boost.  I remember doing probably my first automated Extract Method and seeing it automatically deduce which parameters would need to be passed, and saying “No way.  No way!” And then you could rename methods (and it would update the dependencies); you could extract a local variable; you could do a quick fix… I would find myself giggling and sometimes laughing out loud – there were all these mundane, tedious and error-prone manual manipulations of source code that I was used to doing, being careful and manually checking everywhere to try not to miss something – and now that I could use the Refactor menu my mind was freed to think about the problem I needed to solve.  Wow!

Automated refactoring was such a productivity and energy boost.  I don’t want to go back to the way it was before.  So, now that I’m in C++,  I’m interested in finding an automated refactoring tool for C++ – preferably one that integrates with Visual Studio.

What’s Out There?

For C++ development, a quick Google search turned up devexpress‘s Refactor! for C++ and Whole Tomato Software‘s Visual Assist product, both of which integrate with Microsoft Visual Studio.  Refactor! for C++ is a free download, whereas Visual Assist costs $249 with $49 maintenance renewals (or $99 for a license that is not eligible for the renewals).

This post on refers to SlickEdit as an alternative.  Ah yes, apparently SlickEdit can do refactorings in C++ .  And it appears that some people around here already use it. Hmm!

For Tonight’s Program, the Screenshots Part Will Be Played By…

Here is the part where I would take a bunch of screen shots demonstrating the use of Extract Method… but Whole Tomato has a nice post about that on codeproject already.  Helpful to see the tool in action.

Out With a Whimper

And to add to the letdown of me not having my own screenshots… I haven’t come to a conclusion yet either.  I have SlickEdit, the trial version of Visual Assist X, and Refactor! for C++ installed.  Guess we’ll try ’em and see!

(Const) References

Refactoring Tools Shoot Out by Legalize Adulthood

All developers are equal, but some are more equal… (Maciek Talaska)

A couple of Stack Overflow exchanges pointing to Refactor and VAX

SlickEdit – Programmer’s Editor (

Are We There Yet? SlickEdit’s C++ Refactoring


Sometimes there’s an easier way

I was working to get snapshots of the Hibernate AnnotationConfiguration properties in effect when Hibernate local transactions are in use versus when a JTA transaction manager is in use, and halfway through I found there was a much easier way to capture my data.

What I did First

  1. While a debugging session was stopped at a breakpoint at line 732 of org.springframework.orm.hibernate3.LocalSessionFactoryBean (In buildSessionFactory() where the AnnotationConfiguration is done being built), I went to the Expressions view and selected the AnnotationConfiguration named “config”;
  2. Opened config’s properties field and manually expanded all 116 nodes, exposing their key/value pairs;
  3. Selected the 116 nodes-with-key/value-pairs and chose Copy Expressions from the context menu;
  4. Pasted into Notepad and manually removed the “[0…99]” and “[100…116]” lines;
  5. Saved the modified file as hibernate-annotation-config-jta.txt
  6. Ran the following commands:
    egrep --invert-match "\[" hibernate-annotation-config-jta.txt > keys-values.txt
    egrep key= keys-values.txt | sed 's/[ \t]*key= \"\(.*\)\".*$/\1/' > keys.txt
    egrep value= keys-values.txt | sed 's/[ \t]*value= \"\(.*\)\".*$/\1/' > values.txt
    paste --delimiter== keys.txt values.txt > keys-values-jta.txt

This worked — it got all 116 entries into key=value format, one key/value pair per line — and I prepared to do it again while running my test in Hibernate mode.

Then I noticed…

Then I saw another pane in the Expressions view I hadn’t really noticed before, on the right hand side.  When I clicked on one of the AnnotationConfig’s properties in the Expressions window (even without expanding that entry to show the key and value), I saw the entry in key=value format over in that right hand pane.  And… if I selected all 116 nodes in the left pane of the Expressions view, all 116 key=value pairs showed up in the right pane, ready for me to select and copy!

My new workflow, then, is:

  1. While a debugging session is stopped at a breakpoint at line 732 of org.springframework.orm.hibernate3.LocalSessionFactoryBean (In buildSessionFactory() where the AnnotationConfiguration is done being built), go to the Expressions view, select the AnnotationConfiguration named “config”, and within that select the properties field;
  2. Make sure the “Show Logical Structure” button is pressed;
  3. Expand the properties field so that you can see the individual [0], [1] [2]… entries
  4. Select all these entries:
  5. In the Expressions view’s right hand pane, Select All and copy.

Those are nicer steps than what I did first!  Eclipse comes through again!

Amazinger and amazinger

I keep having pleasant surprises at new ways the Eclipse IDE can help my productivity.  I wrote about Quick Fixes before; here’s today’s:

Did you know that you can type just the capital letters of a class, and then when you hit Ctrl+Space, Content Assist shows what names have those capitals?

For instance, suppose I want to add a Spring DefaultMessageListenerContainer reference to my class (admittedly odd, but it’s a big long name I don’t want to have to type):

  1. I type DMLC, …
  2. …hit Ctrl+Space…
  3. …and Enter…
  4. “DefaultMessageListener” appears, and I go on to type a field name:

(The title references Alice…)

The hidden assumption

The hidden assumption: that the level of work I’m doing when I am free to improve things is the same as when I lack such freedom and feel that my contribution to the company is not what it could be (with the accompanying loss of hope).

The assumption is that if we take out all the sprinklings* we meet our deadlines faster. But it’s those sprinklings that keep me going, otherwise it could take me a week just to put together a simple design doc! It’s another one of those upside-down things. How can more classes be simpler? And then in this case, how can spending fewer hours directly on a project make it quicker to complete?

Being able to defend and explain these things is a separate skill from being able to do them. I have more of the second, very little of the first.


*What I’m calling “Sprinklings” are the things we do each day to improve our craft.