3 step framework to write better code

3 step framework to write better code

Often we spend too much time to write better code. Though the intention is good, It doesn't produce any result in most cases. Here's how we can approach writing better code,

Make it work

  • You're writing code, first step is focus on the basic requirements and make it work.
  • Make sure you're getting output for the most common use case.
  • No need to focus more on errors, validations, exception handling, edge cases, etc.

So now you will have a working code that you can use it to get some feedback.

Make it right

  • Now you have a working code that you can refactor and add meaningful variable names, functions, classes, etc.
  • Make it easy to read and understand
  • Handle errors, validations, exceptions
  • Make the code better by incorporating principles like SRP(Single Responsibility Principle), DRY(Don't Repeat Yourself) and design patterns

Now you will have a code that works and covers most of the features and easy to understand.

Make it fast

Now you have the code that is less error prone.

Follow YAGNI principle and try to find unnecessary code and business logics. Optimise the code for performance. ie. use less memory and execution time.

Conclusion

  • When you focus on all kinds of scenarios, It takes too much time to produce a working code.
  • Sometimes we spend too much time to think better variable names, function names, modular structure.
  • Instead focus on this 3 step process and quickly iterate and build better systems.

This process need to happen step by step, if code does not work who cares how beautiful the code is? if code does not work who cares how fast it is? if code does not produce result who cares how fast it is? if code does not produce correct result who cares how fast it is?

If you find this article helpful, please do like and comment on this article. If you have any suggestions or feedbacks, feel free to comment. Stay tuned for upcoming articles. Subscribe to the newsletter and Connect with me on twitter to get my future articles.

Did you find this article valuable?

Support Suresh Kumar by becoming a sponsor. Any amount is appreciated!