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.

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay