19 ms·
Small modules are easy to reason about Yes they are, in the same way that a book in which every page consists of a single word is easier to understand than one
by userbinator 11y ago
Small modules are easy to reason about
Yes they are, in the same way that a book in which every page consists of a single word is easier to understand than one with more content per page.
By focusing on the small-scale complexity to such an extreme, you've managed to make the whole system much harder to understand, and understanding the big picture is vital to things like debugging and making systems which are efficient overall.
IMHO this hyperabstraction and hypermodularisation (I just made these terms up, but I think they should be used more) is a symptom of a community that has mainly abandoned real thought and replaced it with dogmatic cargo-cult adherence to "best practices" which they think will somehow magically make their software awesome if taken to extremes. It's easy to see how advice like "keep functions short" and "don't implement anything yourself" could lead to such absurdity when taken to their logical conclusions. The same mentality with "more OOP is better" is what lead to Enterprise Java.
Related article that explains this phenomenon in more detail:
http://countercomplex.blogspot.ca/2014/08/the-resource-leak-bug-of-our.html http://countercomplex.blogspot.ca/2014/08/the-resource-leak-...
- lewisl9029 11y ago> Yes they are, in the same way that a book in which every page consists of a single word is easier to understand than one with more content per page. A more apt metaphor would be separating a book into many small paragraphs that each serves a single purpose makes the book easier to understand. Regardless, the book metaphor misses a lot of the nuance. Of course taking the approach to an extreme would be detrimental. However, a vast majority of these small modules that are actually widely used consist of functions that may seem trivial at first sight, but actually contain a lot of corner cases and special considerations that a naive inline implementation could miss. Sure, there are also plenty of trivial one-line modules on npm that don't fit into a such a description, but those are simply side effects of the unprecedented popularity of the platform and its completely open nature, and shouldn't be used to infer any kind of general trend towards "hypermodularisation" because very few reasonable developers would ever import them into their projects.
- simula67 11y ago> A more apt metaphor would be separating a book into many small paragraphs that each serves a single purpose makes the book easier to understand No, that would not be an apt metaphor for the problem he is describing. > Regardless, the book metaphor misses a lot of the nuance. Not if you are trying to understand the point he is trying to make. Is there any cost to creating modules, uploading them to npm and using them in other projects ? Clearly there is, as is shown by the world-wide breakage from yesterday. This is probably only one of such failure modes. The point is, breaking everything into micro-modules can have benefits and costs. Ultimately, it is an engineering trade-off. Now, it is possible that npm modules are at the right level of abstraction, even though other module systems in the world are not this granular. If this is due to the special nature of JavaScript then the point must be argued from that perspective.
- lewisl9029 11y ago> No, that would not be an apt metaphor for the problem he is describing. That's because I don't agree that the problem he is describing exists, or at least not to the degree he's describing, which was full of hyperbole. > Is there any cost to creating modules, uploading them to npm and using them in other projects ? Clearly there is, as is shown by the world-wide breakage from yesterday. This is probably only one of such failure modes. This was a failure on npm's side by including a functionality that allows users to trivially remove packages from a package management system that is used by hundreds of other packages, something that most major package management systems have decided was a bad idea. > The point is, breaking everything into micro-modules can have benefits and costs. Ultimately, it is an engineering trade-off. Agreed. And I don't think nearly as many people are erring on the extreme side of this tradeoff to the degree that he's describing.
- deong 11y ago> This was a failure on npm's side by including a functionality that allows users to trivially remove packages from a package management system that is used by hundreds of other packages, something that most major package management systems have decided was a bad idea. That is emphatically not the problem. The author of those modules could have just as easily modified the code instead of deleting it: function leftpad(str, len, ch) { // NPM won't let me delete modules, so here you go return ""; } Now you'd have an even harder time figuring out what happened to your code that you did if the module just disappeared. What you're asking for is basically for the repository to adopt a policy of "all maintainers must be given free rein to get their modules correct and keep them maintained, but they shouldn't have the ability to do anything that causes problems downstream" which is impossible and frankly silly. The problem is the dependency, not the precise mechanism by which that dependency screws you when it goes bad.
- bluejekyll 11y agoPerhaps another reason for this is that Javascript is inherently unsafe. By relying on these small rigorously tested libraries they are avoiding the need to test their own code, and thus avoiding basic null check or conversion errors. Other languages handle this with compilers, may be strongly typed, and/or have features that don't allow nulls. Javascript doesn't exactly have that luxury. So maybe it makes sense in Javascript, where it wouldn't in other languages (though one could argue this is a flaw in the language design). edit: to be clear I'm not really defending the practice, but trying to give a little perspective.
- drauh 11y agoThe equivalent in C would then be replacing #include <math.h> and "-lm" with #include <sin.h> #include <cos.h> #include <tan.h> #include <sinh.h> … and "-lsin -lcos -ltan -lsinh …" Which is nuts no matter what language you are coding in.
- e12e 11y agoOh, but javascript is dynamically typed, so it doesn't matter if your sin-module works with a different kind of arbitrary-precision decimal number module than your geolocation module, your cosine module or your openg-draw-triangle or opengl-draw-circle modules... /sarcasm
- gaius 11y agoIt's not sarcasm if it's true!
- tfm 11y agoOT but apt to this community - That's what I thought, but after a lifetime of 'correcting' people, I looked up the definition of sarcasm. Turns out that the sarcastic-sounding truths I'd been deploying for decades were indeed by-the-book sarcasm rather than 'I can't believe it's not sarcasm'. Key quote from brilliant word-talking-guy Henry Fowler: "Sarcasm does not necessarily involve irony [but it often does] ... The essence of sarcasm is the intention of giving pain by (ironical or other) bitter words." So, we circle back to Node.js by way of pain and bitterness. Sounds about right.
- richmarr 11y agoSorry for the nitpick, but "hyperabstraction"? left-pad isn't even slightly abstract.
- userbinator 11y agoIt's not. The hyperabstraction is in how even tiny functions like this, isPositive, isArray, etc. are being abstracted and turned into individual modules.
- richmarr 11y agoAgain, maybe I'm nitpicking, but turning something into modules doesn't seem like abstraction... you could call it encapsulation, or modularisation, or maybe extraction. But abstraction? I don't see how that word is connected to what's happening. Maybe you can explain it.
- mangecoeur 11y agoAnd to add to the mess, until npm introduced deduplication every dependency recursively included it's own dependencies as sub folders, so you get a bajillion tiny dependencies over and over (and sometimes with different versions to boot). Frankly some of the comments I'm seeing really do reinforce his point: people really don't know how to program. I suspect this is it the flipside of Javascript being popular and accessible - people can churn out products without really knowing what they are doing...
- dang 11y ago> By focusing on the small-scale complexity to such an extreme, you've managed to make the whole system much harder to understand Well put. I've noticed a curious blind spot in how people account for complexity: we count the code that 'does' things much more than the code that glues those things together. This distorts our thinking about system complexity. A cost/benefit analysis that doesn't consider all the costs isn't worth much. An example is when people factor complex code into many small functions, then say it's much simpler because smaller functions are easier to understand. In fact this may or may not be true, and often isn't. To get a good answer you must consider the complexity you've added—in this case, that of the new function declarations and that of the calls to them—not just the complexity you've removed. But it's hard to consider what you don't see. Why is it so easy not to see things like this? I think it's our ideas about programming, especially our unquestioned assumptions. The complexity of glue code goes from being overlooked to positively invisible when it gets moved into things like configuration files. Those are no longer seen as part of the system at all. But of course they should be.
- lotsoflumens 11y agoI just saw this insanity a couple of days ago: https://youtu.be/l1Efy4RB_kw?t=343 https://youtu.be/l1Efy4RB_kw?t=343 He refactored a Java application into 1400 classes!