My Secret Life as a Spaghetti Coder
home | about | contact | privacy statement | getting started with cfrails
Since I do a lot of maintenance work, I get to see a lot of crapcode. Even better, I get to work in it. It's discouraging that I wrote a lot of it.

The smell isn't pleasant, but opportunities to do good things are abundant. Thus, it's easy to do something to beautify the code, to leave it in a better state as a result of refactoring. Moments where you think, "hey, that's cool" are anything but rare.

Ok, that's the positive spin. While I'm making my way through the muck, people within earshot (or just the building in general) will hear expletive after WTFing expletive. Usually, it's emanating from my general direction.

But when I'm done, I get to look back on it with a sense of accomplishment. It's an accomplishment that goes above and beyond the typical new feature or bug fix. That's what I'm doing now.

I was just working on an ordering system where the calculations in one file came out to be a couple of thousand lines of code. It was taking forever - like hacking through jungle with nothing but a dull machete. Most of the small changes I was making resulted in new bugs being introduced to the system. As the number of bugs increased, it started to feel like a jungle. After a while I gave up.

I gave up on my quick-n-dirty add-another-hack-to-a-bunch-of-hacks approach and decided it was time to do something positive for myself, the code, and future programmers who have to touch it.

Extract method (or in this case, extract-template) came to the rescue. Just by extracting related bits of functionality I was able to get the file into manageable, largely cohesive chunks. I didn't go to the extreme: I stopped when it was good enough, touching only those parts I was prepared to fix if I broke them, which meant limiting it to what I was doing there in the first place.

The code isn't incredible, but it's in better shape than it was before I went in. Now, the main calculation file is about 1200 lines, and the other 800 are broken out into different, cohesive files. Forget about reuse, this was just for literacy.

What did you do to improve your codebase today?

Hey! Why don't you make your life easier and subscribe to the full post or short blurb RSS feed? I'm so confident you'll love my smelly pasta plate wisdom that I'm offering a no-strings-attached, lifetime money back guarantee!


Comments
Leave a comment

http://www.amazon.com/Working-Effectively-Legacy-R...=cm_lmf_tit_2

have you read this cool book?

Posted by James Soh on May 07, 2008 at 05:01 AM UTC - 5 hrs

Working Effectively with Legacy Code (Robert C. Martin Series) (Paperback)
by Michael Feathers (Author)

Posted by James Soh on May 07, 2008 at 05:01 AM UTC - 5 hrs

I haven't read it yet James, but it is on my long list of books to read. I'll probably catch up on some of that after I've finally graduated this weekend.

Posted by Sammy Larbi on May 07, 2008 at 07:12 AM UTC - 5 hrs

Looks like my url-finding regex is broken. =)

Posted by Sammy Larbi on May 07, 2008 at 07:13 AM UTC - 5 hrs

Leave a comment

Leave this field empty
Your Name
Email (not displayed, more info?)
Website

Comment:

Subcribe to this comment thread
Remember my details
Google
Web CodeOdor.com

Me
Picture of me

Topics
.NET (21)
AI/Machine Learning (12)
C++ (4)
cfrails (22)
ColdFusion (80)
Customer Relations (15)
DRY (18)
DSLs (11)
Future Tech (4)
Games (5)
Groovy/Grails (7)
IDEs (8)
Java (41)
JavaScript (2)
Lisp (1)
Mac OS (1)
Miscellany (59)
OOAD (34)
Programming (97)
Programming Quotables (5)
Rails (18)
Ruby (50)
Save Your Job (40)
scriptaGulous (4)
Software Development Process (22)
TDD (39)
TDDing xorblog (6)
Tools (3)
Web Development (2)
YAGNI (10)

Resources
Agile Manifesto & Principles
Principles Of OOD
ColdFusion
CFUnit
Ruby
Ruby on Rails
JUnit

Reading List
InfoQ - Agile, Ruby, & more
Ray Camden - Cf Jedi Master
Ron Jeffries' XP Mag
Peter Bell's Application Generation
Others coming...

RSS 2.0: Full Post | Short Blurb
Subscribe by email:

Delivered by FeedBurner