• Share this article:

Screenshot of the Week: C++ Refactoring

Tuesday, April 28, 2015 - 11:08 by Wayne Beaton

My son has just finished up his first year of software development at college. In a demonstration of what I consider cruel and unusual punishment, his first programming language is C++ and his first development environment is Visual C++. I have to assume that the version of Visual C++ that the college unleashed on these unsuspecting students is some sort of reduced-functionality version, because it seems to lack certain functionality that I consider pretty basic, like refactoring.

I learned C years ago, and did some honest-to-goodness work using it, but never did take the time to learn C++, so I used this as an opportunity to close that gap. Naturally, I decided to learn C++ using the Eclipse C/C++ Development Tools (CDT).

The CDT provides some excellent refactoring support.

Renaming a C++ method

Renaming a C++ method

Keep the just-sorting-this-stuff-out nature of the work when considering the code in the screenshot.

This screenshot shows the first stage of the Rename refactoring. As expected, this changes the name of the method (function), the declaration in the header file, and any code that calls it. There are many other refactorings available, including ones that extract constants, fields, and functions. Note the Call Hierarchy view on the bottom view stack: use this view to find out how your function interacts with the world (calls and callers). There’s all sorts of cool stuff available.

The Eclipse CDT project has participated in every simultaneous release we’ve done and so it’s no surprise that they’re an important part of the Eclipse Mars Release. Help us test Eclipse Mars by downloading and testing a milestone build.

Epilogue: To my son’s instructors’ credit, they did avoid complex memory management issues, and did get the students to produce some pretty cool and very playable games featuring two-dimensional graphics. Those students that survive the programme are probably going to do well…

Caveat: I never really took the time necessary to properly research the functionalities provided by Visual C++ or spend any significant time using it. I have to assume that it’s very functional once you get comfortable with it.