DEV Community

Cover image for If The Code Works, Don't Touch It !
Aimen Zairi
Aimen Zairi

Posted on • Originally published at

If The Code Works, Don't Touch It !

This is a repost with little modifications of a post originally in my blog.
If you don't want to read the post, you can also watch the video version of it :

The sentence “if the code works, don’t fix it” is sometimes taken as a rule by newbie developers. Though most of the times it works, i Personally think it is just an excuse from lazy developers.
What is even a bigger problem are people who learn frameworks without learning the basic concepts which causes them to write spaghetti code, and when they see this "Rule" they think it's something everyone does.

Why You Should Fix Your/The Code

  • Becomes more readable by other
  • Improve the code
  • having testable
  • having extensible code

When To Not Touch The Code

  • New To The Job
  • Not Experienced Enough With The Technology
  • A Part Of the Code That Won't Change Over Time
  • Usage Of Open/Close Principle ( Add New Features Without Removing The old Ones )

How To Fix

  • Read The Code Multiple Times Until You Understand It ( We All Know that our old code can only be understood by GOD but still give it a try )
  • Separate Logic From State / UI Management
  • Use Design Pattern To Turn The Logic Into Small Testable and Extensible Pieces.

Top comments (4)

jcfore21 profile image

Just always leave the code better than you found it. This is the best advice I've come across over my career. An echo of the boy scout rule.

passivetools profile image

It is always fun to go back to your old code and practice improving it. I'm still learning new programming tricks daily, which I go back to my old code and implement

samuelojes profile image


zaki_mer10 profile image
Merabet Zakaria