One criticism levelled against the javascript ecosystem is that programmers are becoming lazy with javascript. Another criticism is that a javascript function should not be a package.
There's a merit to having the individual functions have their own packages though. It adheres to Unix philosophy of "Write programs that do one thing and do it well"
And function being a package lends itself easily to be usable for scripting.
Take uuid and mkdirp package for example.
$ yarn init && yarn add uuid mkdirp
With package having only one function, uuid and mkdirp can be both API and command-line utility.
As API:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8zk6O86dYkDV-8gUirAgESUpka_djMVHdXRRcNsvq1_ZmabAriZErkYLBFWpbED8698RrWzedvbJ6kwksTh4mNrNuiy3GZWE8o2xJkaTQqiitRMV7Hc5ZVFRYpZ9KHQfzRN0bCyW4Evs6/s1600/as-api.png)
As command-line utility:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGgSHmOQ6T5LMYc4y6_JuOXePRIzTyIRytEN6s2p7GpoPT_U93axbUjqF5P3Aq7WRBikp4bVodqUFvYCR-4Ml62ZbNVazknT37KBsp_ZnX_LKPK9tdChL9Sp7EfVvpXZ_Kn4VGww3iHFkS/s1600/as-commandline.png)
How awesome is that?
If mkdirp (rmdir, mv, cat, ...) function is part of com.acme.fileSystem package, it'll be not intuitive to make the package a commandline utility as the package covers a lot of functionalities.
Happy Coding!
No comments:
Post a Comment