Next step to Refactoring

You know how refactoring works. Don’t you ?

  • If the variable names are weirdly worded, change it to more descriptive.
  • Always keep the function short. If it is becoming longer, break it. Divided it into further small functions instead
  • Make sure there is minimal coupling between the modules. If not make it by moving the classes or function around or create another module.
  • Always document. If something is not documented because at the time of writing the code, the author might have assumed it to be obvious. Then understand the code and as soon as you understood it, document it.
  • Keep the variable declaration as close to the use of the variable as possible. This reduces future errors coming to your program.
  • If the condition inside if is more complex, then create a boolean variable explaining that condition and use that instead
  • and much more..

But hey, what is new in it ?

Hang on mate..coming to it ? But before that, tell me one thing

What is that ?

Did you find your code become wacky after editing it due to a bug or something ?

yeah..all the time

Right…happens to me too and I’m sure you also had same kind of problem.

Do you think while editing the code, you should think about whether that change leads to a good code! I don’t think so. Otherwise you would take 10 hours instead of 1 to fix the code.

Do the changes what it needs to be changed. After that, assuming you haven’t came across the same issue recently, it’s a mess. Well, How you will make it back to beautiful ?

  • Reread the code
  • Understand the overall idea of it.
  • Write the pseudo code for it.
  • Then you will have a clear idea, how to make it back to beautiful.

That’s it. Happy coding!