DEV Community

Owen Luke
Owen Luke

Posted on

Why we should split long code into small functions or files?

As they said:

  • Unix Principle: "Do one thing and do it well".
  • Clean Code: "The first rule of functions is that they should be small".
  • Node.js Best Practices: "Ensure that each unit is kept small and simple".

Simply put, this can leads to MURDER which is a good thing (the answer comes from stackOverflow, by John Dibling):

  • M - Maintainability. Smaller, simpler functions are easier to maintain.
  • U - Understandability. Simpler functions are easier to understand.
  • R - Reuseability. Encourages code reuse by moving common operations to a separate function.
  • D - Debugability. It's easier to debug simple functions than complex ones.
  • E - Extensibility. Code reuse and maintainability lead to functions that are easier to refactor in 6 months.
  • R - Regression. Reuse and modularization lead to more effective regression testing.

Based on these principles, kdo was born as an open source project.

You can easily split long code into small functions or files, execute them via kdo, makes the code clear, easy to read and maintain.

Very simple and useful, right? Just try it now.

Oldest comments (0)