3 ms·
There's nothing "revolutionary" about CommonJS. It's a packaging system that offers simple encapsulation (but so does Java/Kotlin/Scala or C#). There's somethin
by eropple 10y ago
There's nothing "revolutionary" about CommonJS. It's a packaging system that offers simple encapsulation (but so does Java/Kotlin/Scala or C#). There's something different about it, in that it allows concurrent use of different versions--but, frankly, to me that's a demerit, not a positive, 'cause I'd rather keep my dependencies squared away.
- some1else 10y agoI believe there was a way to package and deploy apps with multiple versions of the same deps in the Java world before NodeJS came to be. I remember a buddy candidly explaining those capabilities to me, back when Rails gems were still managed with rake tasks.
- eropple 10y agoOSGi, probably. Which is kind of hairy. But it's a difficult problem on the JVM.
- z3t4 10y agoNodeJS allows lexical (function) scoping of modules. I do not know any other language that allows this. Function scoping allows better decoupling when functions do not depend on the outer scope. And modules in NodeJS are truly modular as they contain all their dependencies, even libraries.
- eropple 10y agoThe former: I'd like to know how this is better than, say, assembly-level scoping in a PCL in C#. It's different, but I wouldn't call it better, and I wouldn't say that it enables better decoupling--just decoupling at a different level. The latter: as mentioned in my previous post, this is, to me, a misfeature. Transitive dependencies being encapsulated in a dependency increases the likelihood that those dependencies don't get fixed when bugs inevitably arise in those transitive dependencies. Do not want.
- z3t4 10y agoall variables in JS are private. Nodejs module require's are private in method scope. all modules in nodejs are open souece, when you find a bug you make a pull request. Popular modules are used by many, bugs tend to surface quickly. Semver versioning is used, so its usually safe to upgrade minor (bug fixes)
- eropple 10y agoI'm not sure if you were building a case towards something, but I definitely don't get where you're going. Variables being private or not-private is not particularly meaningful to encapsulation while exports are relying on underscore-conventions to protect your internal state. Modules being open-source or not is not particularly relevant to either question, nor is semver when your transitive dependencies don't upgrade and so you're pulling in hard-to-audit transitive dependencies that may have red flags (and if your answer is "it's open-source, do it yourself", you have a very interesting view of what a developer should be spending time on).
- z3t4 10y agoAll variables except those in the global scope are private, so you do not need underscore-conventions, simply do not declare the variable in the global scope! And when it comes to nodeJS modules, there are no global scope, all variables will be private unless explicitly exported. So instead of obj.__foo you just declare foo somewhere and it will not be possible to get or set it outside the module. Since all variables are private (function) scoped in JS you do not have to worry about shadowing (overwriting variables), especially when your functions don't have any outside couplings, witch is possible with (common JS) NodeJS modules as modules can be required from within functions or methods. They are just like any variable. I think I'll have to make a blog post to explain it in more detail. And I encourage you to do the same ... What do you mean by transitive dependencies ? I don't think there's a concept of transitive dependencies in NodeJS. If you spend one hour to fix a bug in a open source project, you have probably saved other people thousands of hours of work, money, or frustration. Software is special as it cost very little to copy code, so your one hour contribution can be copied many times creating a lot of value. It's like you would bake one cake once and it could be eaten many times, over and over again.