Software Alchemy

15 July, 2009

You can’t turn lead into gold, but maybe you can turn rotten software into beautiful shiny code. My current topic is based on Search-based Software Refactoring. To summarise:

  • take working-but-nasty source code
  • calculate a score
  • automatically refactor it and see how the score changes
  • search for the changes that give the best score
  • return the (hopefully) cleaner code
What could possibly go wrong?

Search-based software refactoring

It might sound unlikely, but Mark and Mel have shown that this does work, provided you choose your scoring system carefully. What the original developers thought of the changes is, sadly, unrecorded…

So: I have a topic to work on, I passed all my exams, and demonstrating is but a distant threat on the horizon. Work is good 🙂



  1. Oooh, nice 🙂
    Can you use some form of GA to get it to “learn” what a good score looks like? Sort of a self adapting scoring system?

    • They tried GAs for the search, but surprisingly the more simple search techniques outperformed it. As for a learning system; possibly, but I don’t want to be the one that sits and trains it!

  2. Also… I just lost the game!

  3. I worry that Mark and Mel’s work is based on a flawed scoring system. The scoring system (from Bansiya and Davis 2002) is mathematical nonsense: it takes some class counts, method counts, declaration counts, hierarchy counts, and ratios; it multiplies them by some magic numbers pulled out of a hat; and then it adds the whole lot together. As any fule kno, you just can’t add inches to kilograms …

    Since the calculated score is not related mathematically to anything in the real world, its surviving claims to validity rest on experiments like this: 11 out of 13 coders agreed that the score roughly matched their own perception of code quality, for one example problem. So if you use this scoring system, you’ve gotta hope and pray that you’re not in the 15% who disagree. And if you’re not writing a compiler, like the subjects of the experiment? Best of luck to ya 😉

    Unfortunately, I don’t think this’ll be the last time academics vastly overstate the validity of their own work.

    Like many, I don’t believe that calculating a single ‘quality score’ for code is wise in the first place, since quality means different things to different people. But if anyone is interested, the work of Marinescu and friends is at least more mathematically sound. Their ‘Factor-Strategy’ model allows user-defined ‘weights’ to be applied to the different quality factors, to suit the job in hand.

  4. […] what’s your PhD about? First I was happily unsure. Then I was more sure and less happy. Then there was a fit of gloom and despair. This sort of thing is relatively normal, […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: