Refactoring to Learn a New Code Base

When you join a team with a large existing code base, it can be intimidating. How long does it take to become familiar with a million lines of code? I don’t have the answer to that question, but based on my past experience it easily takes several years if not more. Meanwhile, the rest of the team is adding and changing code all the time. When I apply small, focused, systemic refactorings to a code base, I visit lots of code that may be unfamiliar to me. Visiting unfamiliar code and making the same kind of systematic change throughout can help me become more familiar with the code.

Read the rest of this entry »

SLC Software Craftsmanship: Rewrite or Refactor?

Tomorrow the Salt Lake City Software Craftsmanship group will be holding their 2nd meetup. The reading discussion topic for this month is Rewrite or Refactor?. Dinner will be served and there will be a programming exercise after the reading discussion. See you there!

Refactoring Test Results for CLion 140-1221.2

I ran through a bunch of refactorings in the latest early access program (EAP) build of JetBrains CLion using my refactoring test suite, now hosted on github.

Summary

Refactoring % Passing Passed Failed
Add/Remove Block Delimiters 46.16% 6 7
Change Signature 100% 11 0
Compress To/Expand From Ternary Expression 69.24% 9 4
Create Method Stub 54.55% 12 10
Create Setter Method 66.67% 20 10
Extract Function 73.69% 14 5
Extract Method 5% 1 19
Extract Parameter 40% 2 3
Flatten Conditional 100% 1 0
Inline Macro 83.34% 5 1
Inline Recent Assignment 0% 0 2
Inline Result 0% 0 5
Inline Variable 22.23% 2 7
Introduce Constant 30.77% 4 9
Introduce Local 66.67% 4 2
Move Method 29.73% 11 26
Remove Unused Parameters 100% 3 0
Rename 77.09% 74 22
Simplify Boolean Expression 100% 13 0
Split Initialization From Declaration 81.82% 9 2
Split Multi-Variable Declaration 100% 19 0

The overall score card looks quite promising, particularly for an early access build that isn’t guaranteed to work at all. The general impression I got was that the refactoring support is better than other tools I have tried. It did much better with pointers to functions, pointers to class members, and references to class members than other refactoring tools. It did a good job of recognizing the appropriate scope for identifiers and properly performed well on rename operations, even when combined with using statements.

Read the rest of this entry »

Adding Static Analysis to Your C++ GitHub Repository

Static analysis can be extremely useful for monitoring the quality of your code base. These tools analyze your source code and check for certain kinds of mistakes that can be detected purely based on how the code is written. In this post, I’ll show you how you can add two free static analysis tools to a free continuous integration build for your C++ github repository.

Read the rest of this entry »

DevExpress Discontinues C++ Refactoring Support

DevExpress announces that they will discontinue support for C++ refactoring in their CodeRush product.

Refactoring Test Results for VAX 10.8.2036.0 built 2014.05.22

I ran through three refactorings (Extract Function, Extract Method, Rename) in the latest version of Visual AssistX using my refactoring test suite and posted the results on the Whole Tomato support forums.

Summary

Refactoring % Passing Passed Failed
Extract Function 0% 0 18
Extract Method 45% 9 11
Rename 63.55% 61 35

Feel free to comment here on the test suite itself. I’ll probably move this to github to encourage more pull requests for improvements to the tests. I haven’t updated it for C++11 language features. Feel free to post in the Whole Tomato support forum thread for comments on Visual AssistX itself.

Read the rest of this entry »

C++ Now! 2014 Presentations Posted

Ray Fix is posting all the presentations of C++ Now! 2014

You can read my presentations here:

C++ Now! 2014 was a wonderful experience! I very much enjoyed talking with the attendees, both during the show and afterwards at restaurants and the bar. I hope to attend again next year.

Spring 2014 Utah Code Camp: March 15th, 2014

The Spring 2014 Utah Code Camp is coming up and I’ve got some proposed sessions. Utah Code Camps are by the developer community and for the developer community. Utah Code Camp is always free! Spring 2014 Utah Code Camp will be held on March 15th, 2014 at the University of Utah Spencer Fox Eccles Business Building.

Read the rest of this entry »

Refactoring: Sort Members by Visibility

You have a C++ class that shows readers its implementation details before it shows readers its public interface.

Reorder the class members in order of decreasing visibility, preserving the relative order of the declarations within each visibility category.

Read the rest of this entry »

Utah Code Camp on March 27th, 2010

At this Spring’s Utah Code Camp on March 27th, 2010 I will be presenting the following sessions:

  • What’s New in XNA Game Studio 4.0
  • Developing for Windows Phone 7 Series
  • Red, Green, Refactor: Learn Test-Driven Development in Two Hours (with Zhon Johansen)

Check the Utah Code Camp website for more information.

Code Camps are always free.

C++ Refactoring Tools Test Suite Available

I created a test suite for C++ refactoring tools. You can download release 1.0 for yourself to see the tests. Results of the tests are included for ReFactor!Pro v9.1.10.

Read the rest of this entry »

Agile Code Reviews, Part 2

In my post on agile code reviews, I described how we were attacking our code through automated refactorings that we trusted to apply without tests. Mostly we applied a series of Extract Method refactorings to long methods in the process of performing a Compose Method refactoring on the long method. Eventually, your team will run out of situations where you can apply automated refactorings to improve the design of your code and you’ll have to start applying actual code changes. Several of the commenters on my previous post remarked that making changes without unit tests implies risk that can only be averted with sufficient manual testing and that such risk is better mitigated by automated tests. In this followup post, I’ll describe the results from our team at applying the decoupling techniques described by Michael Feathers to our legacy code so that we could backfill unit tests onto the legacy code in preparation for a design change we want to make.

Read the rest of this entry »

Refactoring: Split Module

You have a C module containing variables and functions that implement two different responsibilities.

Split the two responsibilities into two modules.

Read the rest of this entry »

Refactoring C++ Template Classes To Reduce Code Bloat

Test-Driven Development and Refactoring At Agile Roots 2009

I was a guest instructor at Zhon Johansen’s Test-Driven Development and Refactoring course at the recent Agile Roots Conference in Salt Lake City. Zhon and I did a dry-run rehearsal of this course for the Utah .NET User Group meeting in June. The streaming video for this tutorial is now available.

Read the rest of this entry »

Agile Code Reviews

Have you ever been tasked with doing classic “Fagan” style code reviews? They’re boring. They’re tedious. They take up lots of time and yield little, if any, results. At a previous employer, we did these kinds of code reviews. It consisted of printing out the source code to be reviewed, one copy per reviewer. Each of us reviewed the code alone, making notes to the printout. Then we’d gather in a conference room and discuss our findings while one person combined all our notes into a list of items to rework. That person would rework the code alone and then report back to the group the results. Whew! This is what the agile development world would call a “high ceremony process”. It has lots of formal steps and the associated paperwork. Is there a better way? In this post, I’ll discuss what we do at my current employer that makes code reviews a fun team activity.

Read the rest of this entry »

Technical Debt Resources

Brad Appleton has posted a great article on technical debt with lots of links to further resources on the subject. If you’re struggling with an aging code base and your managers just don’t understand why you can’t produce features as fast as you used to or at the same quality as before, then direct them to specific resources after reading this blog post. Using ‘debt’ as a metaphor is perfect for the cruft that inevitably finds its way into our code when talking to non-technical types.

Refactor early and often to avoid accumulating technical debt to the point that it cripples you!

Refactoring: Reverse Boolean

You have a boolean variable that represents a negative condition and you want the variable to represent a positive condition.

Replace all assignments to the variable with their logical inverse and replace all uses of the variable with its logical inverse.

Read the rest of this entry »

Refactoring Tools Shoot Out

Over the past few years, I’ve been using a number of refactoring add-ons for Visual Studio.  The three refactoring add-ins I have tried are: Refactor! Pro from DevExpress, Visual Assist X from Whole Tomato and ReSharper from JetBrains. In this post, I’ll review and compare these refactoring add-ons.

Read the rest of this entry »

Refactoring: Finding Dead Code

There’s a “dead code” code smell mentioned in Refactoring. The refactoring is to delete the code. OK, easy enough to do. Over the years, I’ve identified a few handy ways of identifying the dead code laying around in your code base. That way you can ferret it all out at once and get rid of it. This specific example is for C++, but you can apply the techniques to any language.

Read the rest of this entry »