Let's Reconsider That
Aren't C++ Programmers People Too?
by Michael Feathers
August 23, 2003
The industry needs refactoring tools for C++. Now.
C++ programmers are people too, aren't they? You wouldn't think anyone thought so, the way the industry looks today. Java started its run in the late 90s and it rapidly became the lingua franca of programming. Over night, authors started using it for all of their examples in books and articles. Certainly this was response to the market, but Java is also a much more succinct language. If you are going to write about design, Java gives you a better chance of fitting a code snippet on a page. The net effect, however, is that if you look around for evidence of C++'s continued existence, it is pretty easy to miss it. And, if you are one of these invisible C++ programmers and you are aware of that tools are available for Java but not C++, well, you should be screaming. C++ was my first OO language and every time I go back to program in it I notice the lack of support.
A few weeks ago, I was working with a team whose code is split right down the middle. Half of the code is Java and the other half is C++. At the beginning of each iteration, the team members sign up for tasks. When someone walks into the room each morning you can pretty much tell whether they'll be working in C++ or Java. Their faces tell the story. The people who are going to be working in Java march in confidently and start up their Java-based IDE, then they go to get coffee while it loads (yes, there still are some issues in Java-land). When they get back with steaming cups in hand, they look around at the code, find the methods they need to change. They click a menu item and it shows them all of the places that send a particular message. Then they start going through the work of carving out a space to work with their code. They click the mouse around to extract interfaces and methods automatically so that they can get some tests in place for their changes. The C++ programmers come in and bring up vi or emacs (they load quickly so no coffee for the C++ guys) then they browse around the code manually and start to figure out where to make their changes. Figuring out what uses what is often a blind-alley search. When they are ready to break some dependencies, they sit there and try to manually peel off interfaces by introducing virtual functions. They create new header files and extract methods by hand, all the while hoping and praying that they aren't breaking anything. Without an automated tool to check their refactorings it is a nerve-wearing process and it's also several times slower. They know that the Java code is getting better, but it is hard to feel the progress on the C++ side. I don't think the lack of coffee has anything to do with it.
有一次，我拜访的一个C++团队居然不知道外面还有什么重构工具。过了一会儿，我正向一个团队展示一种测试技术。这个技术是和语言无关的，因此我使用了Java IDE。在我的编码课程上，我发现了一个我不喜欢的方法名，于是下拉菜单并点击rename（改名），当我输入新的名称后，Java IDE便替换了所有用到过的地方。不仅仅是一个文件的每一个地方，而是它被引用的每一个地方。团队的三个成员在看明白了我所做的一切后，喊道“NNNOOO WAAAAYYY!!!(没没没 门门！！）我想，如果我展示一个自动方法抽取（automated extract method 技术术语有待考证）的重构技术的话,我会彻底faint（昏倒）的。
Occasionally, some C++ teams I visit don't know what refactoring tools are out there. I was showing a team a testing technique a while back. The technique was language independent, so I pulled up a Java IDE. Over the course of my coding I found a method name that I didn't like. I pulled down a menu and hit rename. When I typed in the new name it was replaced every place it was used. Not every place in the file, every place it was used. Three of the team members recognized what they saw when I did it and they shouted "NNNOOO WAAAAAYYY!!!" I think I could have induced dead faints if I'd shown an automated extract method refactoring.
The sad thing is, it shouldn't be like this.
研究面向对象的自动重构技术是在90年代早期，Bill Opdyke和Ralph Johnson两人最先使用C++开始的。而后，John Brant和Don Roberts开发了第一个Smalltalk的重构浏览器，再后来，Martin Fowler写了一本《Refactoring》的书，正是这本书和Extreme Programming(极限编程）真正把重构技术推向实用(On the radar screen)。Java厂商匆忙在他们的IDE中建立重构工具。毕竟，Java是一种国际通用的商用语言，几乎每一个人都在用，对吧？
The first research into automated OO refactoring was done by Bill Opdyke and Ralph Johnson in the early 1990s, in C++. After that, John Brant and Don Roberts developed the first Smalltalk refactoring browser. Later, Martin Fowler wrote the book 'Refactoring.' That book and Extreme Programming really put refactoring on the radar screen. Java vendors scrambled to build refactoring tools into their IDEs. After all, it was the lingua franca, the language everyone is using, right?
In a few weeks, I'll be visiting another C++ team. This isn't atypical. There is a lot of C++ out there. More than anyone would imagine from looking at literature in "the industry." I wish I could tell them that someday there will be a refactoring tool for C++. For teams with large existing code bases it would be an immediate boost.