Episode 2: Ree-phact-o-ring

 

 

A usual day at the office. Zach WontDoIt, developer of ThreeTonsOfCode Ltd., has already consumed his first two gallons of coffee and is entering his "introspection" phase. He is mentally focusing on having yet another productive and creative day, and what better way to start such a day than exploring his always near-full mailbox that primarily contains important, urgent professional messages and attachments: "StockholmClubbing.pps", "AnIdiotWithASillyBear.wmv", "HolidayCalculator.xls"...

Hey, what's this? An email by ThreeTonsOfCode's chief developer, SelfProc LaimedGenius, (Selfy to friends)! 

________________________________________
From: SelfProc LaimedGenius [mailto:IGetAFatSalary@3tonsofcode.com] 
Sent: Monday, May 23, 2013 09:00 AM
To: 
zach@3tonsofcode.com
Subject: URGENT FUNCTIONALITY ENHANCEMENT

Hi Zach,

I'm attaching the code for project "WorkTillYouDrop". If you recall, we implemented this last year for the NoRoomServiceAtAll group of hotels. They wanted to manage and monitor expenses and stuff in detail. 

However, due to their merger with the NoServiceWhatsoever Group, they need some changes in the way they calculate their expenses. Please locate the relevant functionality and implement the following changes:

(a list of seemingly logical change requests follows)

This will have to be up and runnning ASAP. The more ASAP, the bigger my bonus. I'll buy you a drink, I promise. 

Selfy

ZWD: (Thinking) Ha! Piece of cake. I'll have it done in half an hour tops. Let's see that code.

(click, click, click, open? yes, click, click, hmmm...only ONE file named "EVERYTHING.VB"? click, click... )

ZWD: WHAT? 89333 lines of code?)

At this point, Zach had to furiously rush outside the office in order to buy blood pressure meds (and a bottle of Jack Daniels). While we wait for him to come back, let's have a look at a random snippet of the code he was given, just to get an idea what he's dealing with here.

'------------------------------------------------------------

'THIS IS FUNCTION CALCULATEREVENUE WHICH CALCULATES REVENUES

'------------------------------------------------------------

Friend Function CalculateRevenue( _

       ByVal strRevenue as int64, ByRef blnResult as int32) As Boolean

      

       '------------------------------------------

       ' HANDLE SITUATIONS AND DO THE RIGHT THING

       '------------------------------------------

       If m_str15a = "1" andalso m_str13b = "true" or m_int8c = -1 Then

             

              Try

                     'Return 10000

                     blnResult=Convert("10000", int32)

                    

                     'Return TRUE

                     Return (true)

                    

                     '-----------------------------------------------

                     ' ERROR HANDLING (EXCEPTION) WHEN ERRORS HAPPEN

                     '-----------------------------------------------

              Catch ex as Exception

              'If something goes wrong, throw error else don't

                     Throw New Exception ("Exception Occured")

              Finally

                     'Try something to fix problems. See code.

                     Try

                           'Call something - I don't remember what

                           SuperComponent.TryToAdjustEverything()

                     '-----------------------------------------------

                     ' ERROR HANDLING (EXCEPTION) WHEN ERRORS HAPPEN

                     ' INSIDE ERRORS THAT HAPPEN

                     '-----------------------------------------------

                     Catch Ex as Exception               

                           'If something goes wrong, give error

                           Throw New Exception ("BOOM!")

                     End Try

              End Try

       Else IF m_str67z = "none" Then

              'Make m_redVariable equal to 1

              m_redVariable = 1

              'If m_redVariable is not zero

              If m_redVariable<>0 Then

                     'Do nothing

                     'If m_redVariable is zero

              Else

                   'If nothing ok check those

                   If m_intAllOk = "no" andalso blnString = 546 Then

                    

                   'Call SuperComponent.DieWithSomething 

                   If SuperComponent.DieWithAnAwfulSound(m_objAlwaysOpenConnection) Then

                        'Call me recursively. Everything will be allright then

                         CalculateRevenue (-5, m_greenVariable)

                    End If

                    End If 'End inner if

              End If     'End outer if

       End If         'End outer-outer if

End Function


This is probably enough to give you an idea how the rest of the code goes. Zach gives it a glance upon his return and...

ZWD: ....(gulp)....(lifts phone, dials Selfy's number)

ZWD: Selfy?

SPG: Hey Zach. Did you see it? It's nothing, isn't it? Piece of cake. Extremely easy. Walk in the...

ZWD: (takes a deep breath) WHO coded this?

SPG: (takes a deeper breath himself). Zaaaaach, we really don't need to dig up the past... what's done is done.

ZWD: WHO coded this Selfy? 

SPG: It... it doesn't matter! What matters is that we implement the requested changes...

ZWD: Ok Selfy, so does the comment line "TODO: (c) SelfProc "Supercoder" LaimedGenius - I don't know WTF is going on here" ring any bells?

SPG: Zach! We have all been there! We have all made tiny, insignificant, really not worth mentioning mistakes in the past! Can you please concentrate on the requested changes?

ZWD: We'll need refactoring. Lots of it. 

SPG: .....

ZWD: Outrageously much. Very. Much. Very.

SPG: .....

ZWD: Unbelievably and rudely much. Refactoring. Incredibly. Much.

SPG: .....

ZWD: .....

SPG: .....

ZWD: Refactoring is the process of rewriting code in a simpler and more maintenable form...

SPG: Zach, I MAY have been a bit of a clumsy coder in the past but I assure you I KNOW what REE-PHACT-O-RING is. Well...

ZWD: Refactoring.

SPG: Yeah, that's what I said, isn't it? Listen, we don't have much time on our hands so do the usual stuff and code some new functionality over the existing code.

ZWD: There is no "usual" approach here.

SPG: (Sounding even more certain about what he's saying than Rebecca Black is for the current day of the week, any day of the week) But there is a DEFINITE design pattern. 

ZWD: Of course. Probably it's called "wash coloreds at boiling temperature together with whites and see what happens!"

SPG: (angrily) Are you mocking me?

ZWD: (cough) of course not, Selfy, this is an... alias for the... Observer Strategy of Abstract Factory Decorators, that your code clearly follows. To the letter. 

SPG: Of course it does! It's a tried and tested Gang of Five Design Pattern. You should really study some more, Zach. Your lack of knowledge is disturbing.

ZWD: (Thinking) Why did I become a developer? Why? WHY?

ZWD: Of course...but Selfy? Can I propose a fix for this?

SPG: Yes?

ZWD: (cough). This will take a lot of effort.

SPG: Go on.

ZWD: Factories will have to be removed and replaced with Satisfactories.

SPG: Amazingly brilliant!

ZWD: Observers will have to take a more active role and be promoted to Executives.

SPG: Outstanding!

ZWD: Finally, Decorators will be replaced by  Gardeners. This is the only way we can make it. I'll need two months and free pizza at the end of each day. Double cheese. 

SPG: I'm so glad you see things positively! I think I've read something about Gardeners, it really is a groundbreaking pattern! I'll have management give you THREE months and a good bonus when you finish the project. Thank you very much for your motivation, Zach! 

ZWD: Always, ALWAYS at your service Selfy...

(hangs up) 

ZWD: Oh, mommy. Why did you bring me into this cruel world? Why?

 




Comments (5) -

Adam smith
Adam smith
7/26/2013 3:50:51 PM #

Really... found this several times.. problem is i usually cant convince ppl that things should be properly refactored. There is never enough time. And here we go to maintain code than can have some critical tasks working more or less the way we "observed" it working.

fertilegardens.co.uk
fertilegardens.co.uk
7/30/2013 10:58:07 AM #

Thank you for the great web developers post!

Jeff Humphreys
Jeff Humphreys
8/23/2013 6:01:35 AM #

I just do it. I just refactor. Asking permission is so old school. Of course, I've working in some pretty gamy shops, where people were so highly focused on their neck of the pond that they didn't have the time to notice what anybody else was doing.

Not refactoring is like choosing death, to live as the dead.

visit
visit
3/12/2014 7:55:31 AM #

Really  nice  design and style  and  superb   content material , nothing  else we  require : D.

Britt Aldrige
Britt Aldrige
5/13/2014 4:33:59 PM #

Hi there, just wanted to say, I loved this blog post. It was funny. Keep on posting!|

Add comment

biuquote
  • Comment
  • Preview
Loading

About

Three Tons Of Code is a blog with humorous fiction stories for software developers and people who work in IT in general. It has been noticed that some project managers will not like the blog's content so you'd better not stand next to them when they start throwing things at the computer screen.

See the "Webz" version for images and fun stuff from around the Internet: www.3tonsofcode.com/webz/

Psst! If you are a Project Manager (what are you doing here?) just give this a try. If you are a developer, though, give this to your Project Manager to play and enjoy weeks of undisturbed work :)
 

TeamworkPM