C++ – Code standard refactoring on large codebase

crefactoring

My studio has a large codebase that has been developed over 10+ years. The coding standards that we started with were developed with few developers in house and long before we had to worry about any kind of standards related to C++.

Recently, we started a small R&D project in house and we updated our coding conventions to be more suitable for our environment. The R&D work is going to be integrated into existing project code. One major problem facing us is that we now have two standards for the two areas of work, and now the code bases will cross. I don't want two standards at the studio, and I'm actually quite happy to move forward with a single standard. (The 'how' of how we got into this situation isn't important — just that we are and I had hoped that we wouldn't be.)

The problem is refactoring existing code. I'm not very keen on having two code bases (one relatively small and one very large) looking different. I am interested in doing some refactoring of one of the existing codebases to make it conform to the other standard. The problem is, the smaller code base is (IMO) the more desireable standard.

I started looking around for a tool that could do large scale refactoring for me. I'm not interested in rearranging and tightening code. I'm interested in changing things like

class my_class {}
....
class my_class A;

to

class MyClass {}
....
class MyClass A;

Basically doing function/variable level renaming. I'd prefer not to use something like Visual Assist because that will take a long time. I have upwards of 10000 source/header files with hundreds of thousands of lines of code. Using VA one class at a time would be a time killer and not worth the effort.

I did run across Vera in another post on SO. That seems like it might do the job and do it well. I'd like to know if anyone has specific experience using Vera for the situation that I'm in, or has any other recommendations for tools that might get the job done. I think that it's important that this tool actually understand code structure so that we don't wind up just renaming variables in a search/replace manner because that will lead to subtle bugs if not done carefully.

EDIT: While my example shows I'm going from using _ between names to camelcase type notation, it might be more beneficial for us to move the other way. I'm really looking for a generic solution that will help with large scale renaming.

Thanks.

Best Answer

My process would be to rename each time someone touches a given module. Eventually, all modules would be refactored, but the incremental approach would result in less code breakage(assuming you have a complete set of tests. ;) )