Saturday, 15 August 2009

Refactoring Progress #2

Ironically, one of the most irritating things about my existing code is the tendancy for it to have crept over 80 characters in length (on each line). According to the Object Pascal Style Guide (and to common sense), lines longer than 80 characters are verboten.

I'm still working on the UnitItem unit which contains the definitions for the TItemEnchantment, TItemArchetype and the TItem classes (which all do exactly what they say on the tin). Its taking longer than I thought because, frankly, the code is a mess. But already, I'm starting to see the difference both in terms of understanding and readibility, and even performance has improved slightly.


Mario Donick said...

Is "verboten" a valid English word? :D

Worthstream said...

The "(on each line)" note made me laugh ;)

Dave said...

Some of the code was...well...let's just say I must have been smoking something when I wrote it.

For example, the code to generate item names was split across three seperate functions (one for single name, one for long name and one for short name) taking up almost a thousand lines of code in total (most of which was repeated across the three functions and none of them were commented at all).

I've refactored that down to one function (that takes in two flags) with a total length of 112 lines (including lots of comments).

I've still got the large units to refactor, alas, so I reckon it'll take me another few weeks at least until I'm in position to restart new development.