Derik Whittaker

Syndication

News


Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Sometimes I just feel dirty doing this job.....

Many times during our development duties we have to read through code segments to figure out the desired intent of a feature.  Today I was doing just this.  There is a new feature that I need to implement and to do so, I needed to walk through a bunch of code to determine where my changes may need to go.

Along the way looking though the code I found some less than efficient code (no, this is not a rant about WTF style code).  This code was doing stuff like checking the count of an array to ensure it was > 0 before it went into a for-each loop, along with some other useless stuff.

I made note of the code, but did not change it and I continued on my marry way.  Once I figured out where I needed to make my changes I went back to that code.  My original intent was to fix the code in which I found to be less than efficient.  But then I stopped, I did NOT make the changes.  Why you may ask, here is why

  • My tasks was NOT to change/modify/refactor the code in this giving class
    Changing this code would be a waste, my task was to do something else.  If I feel this code needed to be changed, I need to add it to the list for future work.

  • There are NO tests for this project so I could not assume my trivial changes would not break everything.
    It sucks having no tests and with the absence of test, I would not have felt comfortable changing this code without putting it though its paces and like I said before my task was not to fix this code, but to add a new feature.

  • Why change code that works just fine and is not causing bugs, simply because I feel it was less then efficient?
    As much as I don't like inefficient code, I have a hard time making changes to it if there is no real business sense.  Sure if it was running too slow, or chewing up memory I would make the change, but these are not doing that.

Anyway, I just always feel dirty when I come across code that needs to be fixed and I am not in the position to fix it.  Oh well, I am off to take a shower to get rid of that dirty feeling.

Till next time,


Posted 01-08-2008 12:14 PM by Derik Whittaker
Filed under: ,

[Advertisement]

Comments

Christopher Bennage wrote re: Sometimes I just feel dirty doing this job.....
on 01-08-2008 2:40 PM

You were strong, Derik.

Derik Whittaker wrote re: Sometimes I just feel dirty doing this job.....
on 01-08-2008 2:45 PM

@Chris,

Trust me, took everything I had to NOT change the code.  Besides, i needed the shower.

:)

Scott wrote re: Sometimes I just feel dirty doing this job.....
on 01-08-2008 4:06 PM

I'm on a project like that. Trust me, fixing bad code is a rabbit hole. Once you start down it, the task just keeps growing and growing. If it ain't broke...

Derik Whittaker wrote re: Sometimes I just feel dirty doing this job.....
on 01-08-2008 4:14 PM

Update

I can across some code that performs a foreach loop 7 times.  Each time it is looping through the EXACT same collection.  Why loop through 7 times, simple.  Because there are 7 different enum values and inside the foreach is an if check.  

This will have to change because it could be a HUGH performance hit.

I fear what Scott said, it is a rabbit hole

oh well :)

SDE Science Lover wrote re: Sometimes I just feel dirty doing this job.....
on 01-08-2008 8:32 PM

My initial thought was, "Write tests for this code you want to clean up." I suppose how comfortably you feel that you could adequately cover the codes functionality. I most often make the exact same choice you did.

Derik Whittaker wrote re: Sometimes I just feel dirty doing this job.....
on 01-08-2008 9:02 PM

@SDE,

If it were a system i was comfortable with i would write tests, but I only started with the client 2 weeks ago....

Plus, this code is so far down the rabbit hole it would take a while to get enough tests coverage to feel safe.  And I don't that kinda of time, sadly.

Wesley wrote re: Sometimes I just feel dirty doing this job.....
on 01-09-2008 6:07 AM

Funny I really know that feeling. Unfortunately it often is my own code BUT two years old.

Every day I learn to code better so... everyday I can say that I did something in the past, I will not do anymore because I learned a valuable lesson.

How come I learn everyday? Am I not skilled enough to even get started? Should I read more books, or attend more courses?

Unfortunately there is NOT ONE single book that teaches you how to wright code. NOT ONE.

Show me one book in which all the code samples have Trace.WriteLine or Debug.Assert calls. Show me one book that tells you to use resource files for your exception messages? And this are some very obvious ones.

So all we can do is follow the codesamples we have and learn from the books and slowly learn real life coding bit by bit everyday.

Cheers,

Wes

P.S. Don't fix if it ain't broken ;-)

Mathew Butler wrote re: Sometimes I just feel dirty doing this job.....
on 01-09-2008 6:59 AM

You don't say whether you raised an issue/bug report so that this might get fixed later.  OK, it's not a bug, but it is unnecessary work done that may impact performance - and you noted the issue that another programmer may not have seen.

Mathew Butler

Tom W wrote re: Sometimes I just feel dirty doing this job.....
on 01-09-2008 7:10 AM

Just flag it with a "TODO: Refactor" and move on! Let the original coder work out why it's flagged for refactoring. Heck if you're like me you probably have a billion better things to be doing...

Derik Whittaker wrote re: Sometimes I just feel dirty doing this job.....
on 01-09-2008 7:21 AM

@Mathew & @Tom

Actually the company has about a 100 page (yes, 100 page) doc with a bunch of crap that needs to be fixed.  There is a project planed for this, but it is not a top priority (may never be).  

This app is the poster child for a poorly code off shore project.

But hey, keeps me busy. :)

mkuczara wrote re: Sometimes I just feel dirty doing this job.....
on 01-09-2008 10:55 AM

Flag it TODO:change this loop, on next code review raise the problem, im glad im not the only one feeling dirty today.

jdn wrote re: Sometimes I just feel dirty doing this job.....
on 01-11-2008 10:24 PM

Tell me about it.  As you know, I'm at a client where everything is so fragile, that fixing a bug might break a report (written around the known bug), and so since the reports are what is seen, the bug needs to be kept in place.

Dave Schinkel wrote re: Sometimes I just feel dirty doing this job.....
on 10-17-2008 12:35 AM

I have a real hard time chewing on this personally sometimes when the code you speak of does relate to code you put in.... when it is code that affects my code.  If it's just code you find along the way that's non-related or does not touch your code, that's ok, leave it and refactor later.  

But if it's code that is interrelated to code that you have to put in, then you need to take action and fix -some- of the crumbling bricks (hacks) around it so that it does not fall on top of you and the code you are about to put in.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)