The Band-Aid Mentality of Fixing Bugs

When debugging applications, do you code it properly or do you procrastinate or rush through it just to get it done?

Written by Jonathan "JD" Danylko • Last Updated: • Develop •
Band-aid Programming

Developers know when they see a bad piece of code and that comes from experience. As you progress through your career, you'll see some...uhhh...ummm...interesting code. Most developers have egos and need to check them at the door if you want a quality software product.

What's a piece of "band-aid" code?

Band-aids are described when a coder decides to fix a defect quickly as opposed to fixing the defect correctly. The mentality is that they want it off their plate by fixing the problem as fast a possible, which leaves the defect as a quick fix and not a long term solution.

If there is a choice between fixing a piece of code with a workaround or breaking the code into two or three classes to make the code more understandable and manageable, most programmers will go with the workaround just to get it out of the way.

I understand that some defects are cut and dry (like a string not checking for a null), but some workarounds can get hairy and hard to deal with.

In the age of the Internet, I understand everyone is rushed and moving at the speed of thought, but your code should slow down, meaning that when your coding, take the time to optimize and leverage what you already wrote.

How do you detect "Band-Aid" code?

When experienced developers see a bad piece of code, most programmers start to develop an unnatural twitch (just kidding).

Seriously though, this is where the term refactoring comes into play. There are tons of papers and books out there that discuss exceptional techniques on how to refactor bad code.

The only advice I can give are two items:

  1. Read as much as you can (knowledge)
  2. Code as much as you can (experience)

I can't provide the experience to you, but I can refer some exceptional books that can assist you in your coding.

One such reference I would recommend for the .NET developers of the world is LosTechies.com's free ebook called 31 Days of Refactoring. Definitely a great read. Small bite-sized topics with examples of code to quickly digest and start using in your own code.

Other books I would recommend are listed below:

Along with the little bit of reading, here is a little bit of advice for "fresh" developers:

  1. "Rip the band-aid off!"
    Quit writing workarounds and refactor your code immediately. You'll be able to sleep better at night knowing your code is written properly.
     
  2. If you don't have the time to code it right, when will you?
    Of course, I understand that project managers, supervisors, and other managers are breathing down your neck for next week's deadline, but "manage the managers." Just tell them you are making the world a better place with cleaner and more manageable code. ;-) Take the time to "black box test" your code.
     
  3. DRY out!
    Don't Repeat Yourself! As I said above, leverage code you already wrote and tested. If the code is tested and solid, you won't need to go through bad code/good code phase because you know your routine works. Start building your libraries to have an impact on the finished product. As you build your own library, you'll start to see the power of already tested code...and the process of getting it done quicker.

Bottom-line: Always code as if the person maintaining your code is a violent axe-wielding psychopath who knows where you live (WARNING: Interesting Picture).

Love that quote!

Share your discussion below. How do you handle bad code? C'mon...be honest.

ASP.NET 8 Best Practices on Amazon

ASP.NET 8 Best Practices by Jonathan Danylko


Reviewed as a "comprehensive guide" and a "roadmap to excellence" with over 120 Best Practices for ASP.NET Core 8, Jonathan's first book by Packt Publishing explores proven techniques for every phase of the SDLC.

Learn industry-standard concepts to improve your coding, debugging, and deployment of ASP.NET Core websites.

Order now on Amazon.com button

Picture of Jonathan "JD" Danylko

Jonathan "JD" Danylko is an author, web architect, and entrepreneur who's been programming for over 30 years. He's developed websites for small, medium, and Fortune 500 companies since 1996.

He currently works at Insight Enterprises as an Architect.

When asked what he likes to do in his spare time, he replies, "I like to write and I like to code. I also like to write about code."

comments powered by Disqus