Let’s be honest, we have a lot of code, right? According to guys like Michael Feathers: "code you wrote yesterday is legacy code" and Jez Humble: "if you’re working with that code only test what you impact - don’t try to generate coverage."
So with all of the legacy out there who’s dealing with the underbelly of our software stacks, you know “the lowdown” where no one dares to go.
Seems to me we need to be a little like Captain Kirk. He wasn’t scared to go places where no one had been. A little unknown nerd history on the juggernaut legacy of Star Trek - Gene Roddenberry, the creator, wanted to build something that was an adventure while simultaneously conveying a moral point and political agenda. Kirk was one such character who could carry out that agenda.
Let’s pretend Captain Kirk was a night time hacker - what would that look like next to how the show played out:
Captain: Crew set out to do something routine
Coder: Kirk decides, “Hey let’s do a twitter mashup in one of my existing apps. I want to be able to tell all of the ladies how cool I am in my yellow an black stretchy outfit.”
Captain: Somewhere along the way they get a call: “Planet O’ ladies are in trouble, only Kirk can save them, please hurry.”
Coder: “Crap,” says Kirk, “I have to create OAuth hooks, and it looks like all of the models in this app use .net SOAP web services and there are no flippin tests!!!” “efffffffffffffff!, The boss is gonna kill me!” Kirk exclaims.
The Moral Dilemma
Captain: The Captain must decide, should I follow orders and go or should I do the “right” thing and save the ladies, errr um, the planet.
Coder: Scratching his head he thinks: “do I give up on the app, this legacy code is gonna kill me. Or do I rewrite it so that it actually looks and works like software.”
The Decision (this is where a lot of us go off the reservation)
Captain: “Think of the lady planet, they need me! I choose yes! I choose refractor, regardless of the dangers i’ll face.”
Coder: “Think of the ladies, they need my fashion tips! I choose refractor, regardless of the dangers i’ll face.”
Captain: He arrives, struggles with the bad guy aptly named SOAP (what, it’s my story) , looses his shirt (so that they can have a show that both the man and woman will watch), saves the planet, gets forgiven for getting off task, and there is much celebration.
Coder: He begins writing tests, refactor, test, refactor, kills the bad guy named SOAP, implements his twitter client, gets forgiven for a little scope bleed, builds a killer app, and all of the ladies rejoice because now they see that most of his fashion is based on a breakaway design.
As dangerous as it may seem we need to deal with the lowdown and be like Kirk.
the point: Go hunting occasionally - code smells are not hard to find and there will always be something to refactor.