Refactoring: The Long Game

I recently gave the talk “Refactoring: The Long Game” at MavenLink, a local software firm. MavenLink works by doing strict test-driven development and pair programming all the time. MavenLink has an office in Salt Lake City and an office in San Francisco. It’s a really interesting place to work. MavenLink provided me with a recording of their meeting which I have uploaded to YouTube.

For about the first 40 minutes, I discuss larger term architectural concerns and goals while refactoring. After that discussion, I show a live example of refactoring some crufty code with IntelliJ which shows just how quickly you can transform code with the right automated tools at your fingertips.

Give Your Old Code Some New Love

If you’re not careful, entropy creeps its way into your code base. You take a shortcut or code something in a way that you know is sloppy and you say to yourself “I’ll come back to that later”, but later you’re faced with new feature requests or some other Imminent Disaster(tm) and you don’t go back and clean up the mess you made earlier. This is only natural in a code base and when the messes are few and far between, it is tolerable.

However, at some point the messes accumulate and you need to do something about it because the mess is preventing you from making forward progress in a reasonable manner. Entire books have been written about this situation such as “Working Effectively With Legacy Code” by Michael Feathers (see my review), “Refactoring: Improving the Design of Existing Code” by Martin Fowler and “Refactoring to Patterns” by Joshua Kerievsky. One could even consider “Domain-Driven Design: Tackling Complexity in the Heart of Software” by Eric Evans to be a book full of advice about how to avoid the accumulation of entropy in your code base. Still, sometimes you find yourself with too much entropy in your code base and it’s time to do something about it.

In this post, we’ll take a look at an open source project with a code base that is over 30 years old and has accumulated some “cruft” along the way. We’ll discuss various strategies for coping with the cruft and how to get rid of it in as safe a manner as possible. After all, we don’t want to introduce bugs while we clean up cruft.

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 »

Utah Fall Code Camp 2011

The Utah Fall Code Camp 2011 is coming up and I’ve proposed a number of talks and volunteered to present some that didn’t yet have speakers. If any of these sessions sound interesting to you, please visit the Utah Code Camp web site and vote for them.

  • Open Source Development Track: Recursive Descent Parsers with Boost.Spirit
  • Microsoft Development Track: Powering Managed Applications with the GPU and SlimDX
  • Architecture Track: High Performance C++, or How to Make Friends With the Cache

The following talks already existed but had no speaker yet, so I volunteered to give them:

  • Mobile Development Track: Push Notifications and Tiles for Windows Phone
  • Mobile Development Track: Game Development for the Windows Phone 7.5

Read the rest of this entry »

Max Iter’s Fractal Follies

Roger Alexander has been posting a series of fractint parameter sets on the fractint user’s list and to his blog “Max Iter’s Fractal Follies”. Similar to the images and RSS feed I created for Jim Muth’s Fractal of the Day series, I have created a feed of 1600×1200 high-resolution 3x antialiased images generated from the parameter sets. You can browse the images and subscribe to the RSS feed to enjoy Roger’s work. Thanks Roger!

Jim Muth’s Fractal of the Day RSS Feed Enhanced

I’ve enhanced the Fractal of the Day RSS feed to include Jim Muth’s musings and a thumbnail of the rendered image in the description. The musings and thumbnails were always included in the browsable parsets, but having them included in the feed is also desirable, particularly since I am scraping through the ten year backlog of parsets and creating images in a non-predictable order.

UltraFractal Parameters RSS Feed

UltraFractalThe UltraFractal mailing list often has parameter sets posted to it. However, due to the vagaries of internet email, there was often a variety of editing or careful copy/pasting you had to do in order to get the parameter set in a format that UltraFractal liked. I created a script that processes selected mail messages to extract out the UPR file in a form that UltraFractal likes. Its much more reliable than what I was doing by hand. The results of the script can be seen at the UltraFractal Parameters RSS feed.

Update: The public feed has been turned off. See the comments below.

Iterated Dynamics Moved From SourceForge To CodePlex

No SourceForgeOver the past few years, I’ve become increasingly disappointed with SourceForge for my open source projects. It used to be the first place I would suggest for hosting open source projects; now I would never recommend it. As a result, I’ve moved Iterated Dynamics to CodePlex.

Read the rest of this entry »

Big Fractals RSS Feed Created

2013_01_08-Candy_Drop_TreeJim Muth has been posting a “fractal of the day” FRACTINT parameter set for a number of years now. Its always nice to have a steady stream of fresh fractal images to browse and I really appreciate Jim’s effort in posting the parameter sets. However, its not always convenient for me to run FRACTINT (it is still a DOS program, after all) and render the image. So, a while back I started running a cron job on XMission’s shell that ran the X11 port of FRACTINT to render out the images. I render them at 4800×3600 to achieve 3x antialiasing for a target size of 1600×1200. This really gives a nice image, even though FRACTINT is still limited to the idea that coloring a pixel means creating an 8-bit index into a 256 entry color lookup table. The results are published on my XMission account and updated about once a day, depending on the computation time.

Recently I discovered a bug in xfractint that caused it to choke on any parameter set whose name contained a dash (-). I’ve worked around the problem and started handling the older parameter sets that previously failed in my nightly cron job. However, it was now getting hard to identify which images were newly added because they weren’t the ones with the most recent chronological date anymore. So I created an RSS feed that shows the images added in the last 30 days. It doesn’t seem possible to include item thumbnails in an RSS feed, so for now it is just a link to the final rendered image and the name and rating of the parameter set as decided by Jim Muth. If you want to browse by thumbnail, start at the main Fractal of the Day page.

Thanks for your hard work, Jim!

Refactoring: Convert C to C++

You have C source code.

Create a C++ source file containing the C source code, modified to adhere to the rules of C++.

Motivation

The C language provides limited scoping and encapsulation of data and functions. It has no objects, but legacy systems often involve a large body of procedural code that could benefit from object-oriented refactorings. In order to apply object-oriented refactorings the code must first be ported to C++. Then the C++ code can be refactored from procedural code and data into objects. The objects can be further refactored with standard object-oriented refactorings.

C++ is syntactically compatible with C, but introduces new reserved keywords that are not present in the C language, such as template, typename, class and so-on. Because these additional keywords are reserved in C++ but not in C, you may need to apply Rename Function, Rename Field or Rename Variable refactorings in order to eliminate errors arising from compiling the source with a C++ compiler instead of a C compiler.

C++ is link compatible with C when external data and functions are declared with “C” linkage via the extern "C" in the C++ code. Data and functions made available to C compilation unit from a C++ compilation unit must also be declared extern "C" in order to be visible to the C code.

Read the rest of this entry »

FractInt for Windows (beta 5)

Download FractInt for Windows Beta 5

The legacy code I’ve been working on lately is FractInt.  FractInt’s most recent release is a source base that compiles in three ways: DOS (FRACTINT), Win16 (WinFract) and lunix/X11 (xfractint).  The DOS code has gone about as far as any DOS program should go, and then some.  The Win16 and X11 code has lagged behind the DOS code in some areas, mostly because people didn’t want to translate the 16-bit x86 assembly code for other environments.

Read the rest of this entry »