DEV Community

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

Posted on β€’ Originally published at zairiaimen.com

26 7

If The Code Works, Don't Touch It !

This is a repost with little modifications of a post originally in my blog.
zairiaimen.com
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.
πŸ‘‹ While you are here

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (4)

Collapse
 
jcfore21 profile image
jcfore21 β€’

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.

Collapse
 
passivetools profile image
PassiveTools β€’

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

Collapse
 
samuelojes profile image
DGAME β€’

πŸ˜‚πŸ’―β€οΈ

Collapse
 
zaki_mer10 profile image
Merabet Zakaria β€’

πŸŽ©πŸŽ©πŸ’―

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay