DEV Community

Owen Luke
Owen Luke

Posted on

1

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.

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)