How to Refactor a Codebase?. Yes, that thing you wanted to do a… | by David Yu | Mar, 2022

Picture by Arnold Francisca on Unsplash

At this time I’ll do what others gained’t so tomorrow I can do what others can’t — Jerry Rice

  • To make our code maintainable sooner or later
  • To extend the readability of code
  • To scale back complexity
  • To enhance code’s efficiency
  • To assist future options to be simpler applied
  • Including feedback/paperwork could make the code simpler to grasp
  • Code is just not below lively modifications.
  • Code meets the present code commonplace
  • When correct specs exist, rewrite may make extra sense
  • The present code has practical bugs
  • When a brand new function is being added
  1. Meet with a couple of builders who’ve labored on the code that you’ll refactor
  2. Provide you with a step-by-step plan with the workforce
  3. Inform the opposite elements of the workforce in regards to the plan
  1. Take a look at One Factor at a Time in Isolation
  2. Comply with the AAA Rule: Organize, Act, Assert
  3. Write Exams That Reveal a Bug, Then Repair It
  4. Identify Your Exams Clearly and Don’t Be Afraid of Lengthy Names
  5. Make Every Take a look at Impartial
  6. Run take a look at usually

Some ideas for understanding what the code does:

  • Run the code
  • Run debugger with code
  • Discover the entry level
  • Visualize the connections
  • Speak to the customers
  • Speak to somebody who labored on the code earlier than

Retrace to supply

  1. take a look at the UI to see what appears to be like comparable
  2. use “Examine Factor” within the console to find some data that you possibly can use to seek for that code
  3. If they’re really two(or extra) completely different items of code, flip them right into a reusable part
  4. Each time doable, separate presentational part from practical
  1. Give attention to one endpoint at a time
  2. Seek for the endpoint key phrases to search out the entry code, e.g. “/consumer”
  3. If searching for a key phrase doesn’t work, search for the entry level of the backend service. Then perceive how the endpoint will get setup
  4. Discover different service/operate that the endpoint will depend on
  5. Take into consideration how you can cut back the steps to get to the present response(output of the endpoint)

Utilizing international seek for key phrases

Visualize every time doable

  1. Free: draw.io
  2. Not so free: Lucidchart

Measuring programming progress by traces of code is like measuring plane constructing progress by weight. — Invoice Gates

  • Organize → Perceive → Rename → Take away Redundancy
  • Perceive → Rename → Organize → Take away Redundancy

Exit early

Keep away from Nested Ternary

At all times code as if the man who finally ends up sustaining your code will likely be a violent psychopath who is aware of the place you reside. — John Woods

git commit -m 'renamed variables'
git commit -m 'renamed variables in profile web page'

More Posts