38

Kdo makes the code clear, easy to read and maintain. Try it now!

 4 years ago
source link: https://www.tuicool.com/articles/jIRFBvn
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

YRZreae.png!web

Kdo

Kdo makes the code clear, easy to read and maintain. You can easily split long code into several small functions (why we should do this) via object or files, execute them via kdo. Kdo requires Node.js 7.6+ for async/await.

meInMrm.jpg!web

vmIviir.jpg!web

Kdo itself spreads the code into multiple small functions and files too. Noapi (a light API framework for Node.js, easily define apis and test cases, easily I/O) is a good usage of Kdo, it is recommended to read its source code.

Installation

npm i kdo --save

Test:

git clone https://github.com/hiowenluke/kdo
cd kdo
npm test

Examples

See examples to learn more.

Why

Why we should split long code into several small functions?

As " Node.js Best Practices " said:

vMfmaeR.png!web The worst large applications pitfall is maintaining a huge code base with hundreds of dependencies - such a monolith slows down developers as they try to incorporate new features. Instead, partition your code into components, each gets its own folder or a dedicated codebase, and ensure that each unit is kept small and simple .

Otherwise: When developers who code new features struggle to realize the impact of their change and fear to break other dependent components - deployments become slower and riskier. It's also considered harder to scale-out when all the business units are not separated. EzU7nma.png!web

MURDER rule

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.

More good articles

License

MIT

Copyright (c) 2019, Owen Luke


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK