DEV Community

Zhenyu Lin
Zhenyu Lin

Posted on

How I saved thousands of lines of code - Functional Hook Composition for Everything

https://github.com/opbi/toolchain

There're a large amount of semi-automatable codes in most production codebases, especially around input validation/null check, error/exception handling, observability anchors(log, metrics, tracing) and various other elements to thread functions together to achieve business goals stably. All those are essential for production code, while they are slowly corrupting the readability/maintainability of the codebase, incurring huge communication cost between teams due to a lack of common standards. Fortunately, without AI, it is still possible to automate some of those common programming actions with a standard.

With the power of function composition in Javascript, it becomes very simple to modularize those control mechanisms in the form of well-tested reusable decorators. This makes the core business logic functions extremely concise and easy to read/test/migrate.

I'm working on a new library to standardise a pattern to add reusable hooks to functions to configure their behaviour so that functions can be precisely about the core business logic. This would greatly improve the readability, testability and maintainability of a codebase.

It is currently at its very early stage while have been proofed in a production server. Any feedback or contributions would be welcomed.

Top comments (0)