TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

NPM and Left-Pad: Have We Forgotten How to Program?

1725 点作者 df07大约 9 年前

176 条评论

runin2k1大约 9 年前
Holy moly-- is-positive-integer&#x2F;index.js:<p><pre><code> var passAll = require(&#x27;101&#x2F;pass-all&#x27;) var isPositive = require(&#x27;is-positive&#x27;) var isInteger = require(&#x27;is-integer&#x27;) module.exports = passAll(isPositive, isInteger) </code></pre> I retract my previous statements that Javascript programmers are going down the same enterprise-y mess that Java programmers went down a decade ago.<p>They&#x27;ve already taken it to an entirely different level of insanity.
评论 #11349502 未加载
评论 #11350142 未加载
评论 #11349106 未加载
评论 #11349109 未加载
评论 #11349995 未加载
评论 #11349292 未加载
评论 #11350612 未加载
评论 #11350407 未加载
评论 #11349116 未加载
评论 #11349050 未加载
评论 #11349117 未加载
评论 #11348989 未加载
评论 #11349042 未加载
评论 #11350520 未加载
评论 #11353989 未加载
评论 #11351953 未加载
评论 #11352045 未加载
评论 #11349864 未加载
评论 #11358928 未加载
评论 #11351989 未加载
评论 #11350506 未加载
评论 #11351915 未加载
评论 #11351833 未加载
评论 #11349019 未加载
评论 #11350761 未加载
评论 #11349132 未加载
atjoslin大约 9 年前
Counter-argument:<p>A good micro-module removes complexity. It has one simple purpose, is tested, and you can read the code yourself in less than 30 seconds to know what&#x27;s happening.<p>Take left-pad, for example. Super simple function, 1 minute to write, right? Yes.<p>But check out this PR that fixes an edge case: <a href="https:&#x2F;&#x2F;github.com&#x2F;azer&#x2F;left-pad&#x2F;pull&#x2F;1" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;azer&#x2F;left-pad&#x2F;pull&#x2F;1</a><p>The fact of the matter is: every line of code I write myself is a commitment: more to keep in mind, more to test, more to worry about.<p>If I can read left-pad&#x27;s code in 30 seconds, know it&#x27;s more likely to handle edge cases, and not have to write it myself, I&#x27;m happy.<p>The fault in this left-pad drama is not &quot;people using micro-modules&quot;. The fault is in npm itself: all of this drama happened only because npm is mutable. We should focus on fixing that.
评论 #11349151 未加载
评论 #11349504 未加载
评论 #11349261 未加载
评论 #11349008 未加载
评论 #11349033 未加载
评论 #11350319 未加载
评论 #11351277 未加载
评论 #11348980 未加载
评论 #11350679 未加载
评论 #11349172 未加载
评论 #11349034 未加载
评论 #11351988 未加载
评论 #11349179 未加载
评论 #11349251 未加载
nly大约 9 年前
Nobody has forgotten. These people never knew to begin with.<p>NPM&#x2F;JS has subsumed the class of programmer who would have previously felt at home inside PHPs battery-included ecosystem. Before that, a similar set of devs would have felt at home with Visual Basic. Seriously, go visit the comments section on archived copies of the PHP documentation. You&#x27;ll find code of a similar nature. If PHP had had a module system 10+ years ago you would have seen this phenomenon then. Instead it was copy and paste.<p>This isn&#x27;t elitism, it&#x27;s just the way it is. The cost of a low barrier to entry in to a software ecosystem is taking in those who don&#x27;t yet have software engineering experience.<p>Nobody should be surprised that NPM, which I believe has more packages than any other platform, is 90% garbage. There are only so many problems to solve and so few who can solve them well, in any language. Put 100 programmers in a room, each with 10 years experience, and you&#x27;ll be lucky to find 1 who has written a good library. Writing libraries is really hard.
评论 #11349789 未加载
评论 #11350660 未加载
评论 #11350400 未加载
评论 #11351372 未加载
评论 #11349569 未加载
Wintamute大约 9 年前
Going down the &quot;lots of tiny modules&quot; route is about these three things:<p>a) No standard lib in JS<p>b) JS is delivered over the internet to web pages in a time sensitive manner ... so we don&#x27;t want to bundle huge &quot;do everything&quot; libs. Sometimes its convenient to just grab a tiny module that does one thing well. There isn&#x27;t the same restriction on any other platform<p>c) Npm makes it really easy to publish&#x2F;consume modules<p>d) And because of c) the community is going &quot;all in&quot; with the approach. It&#x27;s a sort of experiment. I think that&#x27;s cool ... if the benefits can be reaped, while the pitfalls understood and avoided then JS development will be in an interesting and unique place. Problems like today can help because they highlight the issues, and the community can optimise to avoid them.<p>Everyone likes to bash the JS community around, we know that. And this sort of snafu gives a good opportunity. But there many JS developers working happily every day with their lots of tiny modules and being hugely productive. These are diverse people from varied technical backgrounds getting stuff done. We&#x27;re investigating an approach and seeing how far we can take it.<p>We don&#x27;t use tiny modules because we&#x27;re lazy or can&#x27;t program, we use them because we&#x27;re interested in a grand experiment of distributing coding effort across the community.<p>I can&#x27;t necessarily defend some of the micro modules being cited as ridiculous in this thread, but you can&#x27;t judge an entire approach by the most extreme examples.
评论 #11349696 未加载
评论 #11352006 未加载
NathanKP大约 9 年前
I don&#x27;t see anything wrong with using a pre-made left pad function. Why waste time and lines of code implementing something so trivial when there is already a solution available?<p>However, I agree it is ridiculous to have a dedicated module for that one function. For most nontrivial projects I just include lodash, which contains tons and tons of handy utility functions that save time and provide efficient, fast implementations of solutions for common tasks.<p>Lodash includes `padStart` by the way (<a href="https:&#x2F;&#x2F;lodash.com&#x2F;docs#padStart" rel="nofollow">https:&#x2F;&#x2F;lodash.com&#x2F;docs#padStart</a>).
评论 #11349097 未加载
评论 #11349148 未加载
评论 #11349054 未加载
评论 #11349005 未加载
评论 #11349164 未加载
评论 #11349105 未加载
评论 #11351678 未加载
评论 #11352684 未加载
评论 #11351193 未加载
adambard大约 9 年前
I think it speaks to just how lacking the baseline Javascript standard library is. The libraries that come with node help, but all of this stuff seems like it should be built-in, or at least available in some sort of prelude-like standard addon library. The lack of either leads to all these (apparently ephemeral) dependencies for really simple functions like these.<p>That said, I work with Java, Clojure and Python mostly so I may be more used to having a huge standard library to lean on than is typical.
评论 #11348984 未加载
评论 #11350003 未加载
评论 #11349111 未加载
评论 #11349737 未加载
mastazi大约 9 年前
Usually, dependency hell doesn&#x27;t bite you, until it does. Try to rebuild that thousand-dependencies app in three years from now and you&#x27;ll see ;-)<p>I recently had to rebuild a large RoR app from circa 2011 and it took me longer to solve dependencies issues than to familiarise myself with the code base.<p>Excessive dependencies are a huge anti-pattern and, in our respective developers communities, we should try to circulate the idea that, while it&#x27;s silly to reinvent the wheel, it&#x27;s even worse to add unnecessary dependencies.
评论 #11350037 未加载
评论 #11349119 未加载
评论 #11348993 未加载
评论 #11349002 未加载
评论 #11351880 未加载
larkinrichards大约 9 年前
I wanted to write this post after the left-pad debacle but I&#x27;ve been beaten to it.<p>I think we got to this state because everyone was optimizing js code for load time-- include only what you need, use closure compiler when it matters, etc. For front end development, this makes perfect sense.<p>Somewhere along the line, front end developers forgot about closure compiler, decided lodash was too big, and decided to do manual tree shaking by breaking code into modules. The close-contact between nodejs and front end javascript resulted in this silly idea transiting out of front-end land and into back-end land.<p>Long time developers easily recognize the stupidity of this, but since they don&#x27;t typically work in nodejs projects they weren&#x27;t around to prevent it from happening.<p>New developers: listen to your elders. Don&#x27;t get all defensive about how this promised land of function-as-a-module is hyper-efficient and the be-all end-all of programming efficiency. It&#x27;s not. Often times, you already know you&#x27;re handing a string, you don&#x27;t need to vary the character that you&#x27;re using for padding and you know how many characters to pad. Write a for loop; it&#x27;s easy.<p>Note that this is exactly the sort of question I ask in coding interviews: I expect a candidate to demonstrate their ability to solve a simple problems in a simple manner; I&#x27;m not going to ask for a binary search. Separately, I&#x27;ll ask a candidate to break down a bigger problem into smaller problems. In my experience, a good programmer is someone who finds simple solutions to complex problems.<p>Note: rails is similarly pushing back against developers that have too many dependencies:<p><a href="https:&#x2F;&#x2F;www.mikeperham.com&#x2F;2016&#x2F;02&#x2F;09&#x2F;kill-your-dependencies&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.mikeperham.com&#x2F;2016&#x2F;02&#x2F;09&#x2F;kill-your-dependencies...</a>
darawk大约 9 年前
Everything in this article is categorically wrong and antithetical to every principle of good programming ever articulated. The only problem here, as others have already noted, is that NPM allows people to delete published packages.<p>Small modules are not evidence of a problem, and they certainly aren&#x27;t evidence of an inability to implement these things on the part of the people depending on them. Why would I implement left-pad myself when there is already a well-tested implementation that I can install? Building up an ecosystem of tiny abstractions, bit by bit, iteratively and evolutionarily, is how we get robust, well-designed complex systems. We don&#x27;t get there by everyone reinventing the left-pad function to sate some misplaced appetite for self-reliance.<p>The author seems to make some arbitrary distinction between things that are &#x27;large enough&#x27; to be packaged and &#x27;pure functions&#x27; which are &#x27;too small&#x27; to be their own modules, and I just couldn&#x27;t disagree more. Tiny, pure functions are <i>ideal</i> modules. They facilitate the greatest degree of re-use, most clearly articulate what they ought to be used for, and stateless things are, in general, more composable than stateful things. There is no better unit of re-use than a tiny, pure function.
评论 #11349247 未加载
评论 #11349337 未加载
评论 #11349231 未加载
评论 #11350213 未加载
panic大约 9 年前
<i>Functions are too small to make into a package and dependency. Pure functions don’t have cohesion; they are random snippets of code and nothing more. Who really wants a “cosine” dependency? We’d all really like a “trigonometry” dependency instead which encompasses many “tricky” functions that we don’t want to have to write ourselves.</i><p>This is a pretty weak argument. What is &quot;cohesion&quot; and why do we care that modules have it? Joe Armstrong, one of the creators of Erlang, has argued the opposite (<a href="http:&#x2F;&#x2F;erlang.org&#x2F;pipermail&#x2F;erlang-questions&#x2F;2011-May&#x2F;058768" rel="nofollow">http:&#x2F;&#x2F;erlang.org&#x2F;pipermail&#x2F;erlang-questions&#x2F;2011-May&#x2F;058768</a>): that lots of small, individual-function modules are better than a &quot;misc&quot; module that grows endlessly and may overlap with other people&#x27;s &quot;misc&quot; modules.<p>Calling a function instead of writing the code yourself doesn&#x27;t mean you&#x27;ve forgotten how to program! The real problem here is the cost and risks associated with dependencies in general (both of which are actually lower for single-function modules), and the broken package removal policies of npm.
评论 #11349816 未加载
评论 #11351101 未加载
haddr大约 9 年前
While in general I agree with the article I must admit that I also strongly DISAGREE with the overall message. Especially with this: &quot;Finally, stringing APIs together and calling it programming doesn’t make it programming.&quot;<p>Stringing APIs together is what actually programming is. This is building software and for instance when i use .toString() method I can easily forget how it is done, focus on other high level things and don&#x27;t care about dependencies, as long as everything works fine.<p>Let&#x27;s admit that the main problem here is with broken npm, rather than packages themselves. If someone has written the &quot;leftpad&quot; function, it is so I don&#x27;t have to write it again, and I can save probably 15-40 min programming and checking some corner cases.<p>Also please note that javascript can be really tricky down in the details. So if there&#x27;s anything that can help, it&#x27;s better that it exists, rather than not.
评论 #11351023 未加载
peferron大约 9 年前
The funniest thing about this entire debacle is the thousand of self-assured programmers coming out to show the JS&#x2F;NPM world how it&#x27;s done, only to have their short, simple, no-nonsense functions fail miserably on some edge cases they didn&#x27;t think about.<p>This discussion about the &quot;isarray&quot; package is probably my favorite: <a href="https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;programming&#x2F;comments&#x2F;4bjss2&#x2F;an_11_line_npm_package_called_leftpad_with_only&#x2F;d1ae85b" rel="nofollow">https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;programming&#x2F;comments&#x2F;4bjss2&#x2F;an_11_l...</a>
pjlegato大约 9 年前
Yes, or more accurately a large new generation of coders is entering the workforce who know how to code only in a superficial sense and think this is a good thing.<p>Programming, and especially startup programming, is being taken over by people who are primarily technicians rather than engineers. They want to assemble prefab components in standardized ways rather than invent new things. They are plumbers who know how to install from a menu of standard components, rather than civil engineers desigining purpose built one-off aqueducts.<p>It is the inverse of the &quot;not invented here syndrome.&quot; The technician-programmer is trained to minimize time spent thinking about or working on a problem, and to minimize the amount of in-house code that exists. The goal is to seek quick fix solutions in the form of copy&#x2F;paste from StackOverflow, libraries, and external dependencies to the greatest extent possible.<p>In house coding should, they believe, ideally be limited to duct-taping together prebuilt 3rd party libraries and services. Those who want to reinvent the wheel are pompous showboating wankers (they believe); creating your own code when you don&#x27;t absolutely <i>have</i> to is a self-indulgent waste of time for impractical people who just like to show off their hotshot skills and don&#x27;t care about <i>getting things done</i>. Move fast and break things and all that.<p>This began with stuff like PHP but really got going with Rails, which preached convention over configuration as a religion, and supplied a standardized framework into which you could easily fit any generic CRUD app that shuttles data between HTML forms and a database (but is painful if you want to deviate from that template in any way.) Note that Rails doesn&#x27;t use foreign keys and treats the relational database as little more than a glorified persistent hash table.<p>This set the stage for Node.js (why bother learning more than 1 programming language?) and NoSQL (why bother learning how database schemas work?)
评论 #11351831 未加载
评论 #11350178 未加载
评论 #11359062 未加载
评论 #11350675 未加载
mooreds大约 9 年前
Relevant:<p>&#x27;&quot;The Excel development team will never accept it,&quot; he said. &quot;You know their motto? &#x27;Find the dependencies -- and eliminate them.&#x27; They&#x27;ll never go for something with so many dependencies.&quot;<p>In-ter-est-ing. I hadn&#x27;t known that. I guess that explained why Excel had its own C compiler.&#x27;<p><a href="http:&#x2F;&#x2F;www.joelonsoftware.com&#x2F;articles&#x2F;fog0000000007.html" rel="nofollow">http:&#x2F;&#x2F;www.joelonsoftware.com&#x2F;articles&#x2F;fog0000000007.html</a>
评论 #11349579 未加载
评论 #11354046 未加载
pkrumins大约 9 年前
Yes, we have.<p>The entire Javascript ecosystem is a huge catastrophe. It will collapse any time soon. It&#x27;s complex, fragmented and no one really likes it. There are a dozen different tools to get started. No one even understands how to get started easily. There are no fundamental tools. Everything is changing every week. You can&#x27;t just build a product and then rebuild it even a month later. Nothing works anymore a month later - your dependencies have changed their APIs, your tools have different flags that do different things, there are new data models that you never needed and shouldn&#x27;t even care about.<p>The developers are in high stress. Devops engineers are in even higher stress because they get to see what developers don&#x27;t.<p>It&#x27;s a huge mess and my advice to &quot;prefer core-language solutions to small abstractions to small helper libraries to general libraries to frameworks&quot; (<a href="http:&#x2F;&#x2F;bit.ly&#x2F;1UlQzcH" rel="nofollow">http:&#x2F;&#x2F;bit.ly&#x2F;1UlQzcH</a>) hasn&#x27;t been more relevant than today.<p>Software should be developed using least amount of complexity, dependencies, effort and using fundamental tools that have been and will be here for the next 20 years. Cut those dependencies, you don&#x27;t need them. They&#x27;re here today and won&#x27;t be here tomorrow.
pfooti大约 9 年前
So, I suppose you could do something like this instead.<p><pre><code> function leftPad(str, width, pad = &#x27; &#x27;) { const actualWidth = Math.max(str.length, width); return `${pad[0].repeat(actualWidth - str.length)}${str}`; } </code></pre> And that would do a leftPad pretty well, and be reasonably robust to stuff like the required width being less than the string width, the padding character being multiple characters long, and so forth. It doesn&#x27;t do any type-checking of course.<p>It also doesn&#x27;t work on older browsers - both string.repeat and template strings are new. You could fake it with string addition, but addition behaves oddly in the case your arguments are numerical, whereas template strings handle that. There&#x27;s also a trick where you can say (new Array(desiredLength + 1)).join(&#x27; &#x27;) to make a string that is the appropriate length, but you&#x27;ve got OBOEs to worry about if you&#x27;re not paying attention (Array.join puts the character between the elements, so you need an n+1 array for an n-length string). Also, at least on some browsers, Array.join is pretty cruddy, and you really ought to construct the string with an old-fashioned for loop.<p>Javascript has all kinds of weird corner cases and lots of browser compatibility problems. The fact that someone&#x27;s written a decent implementation of something that <i>should have been</i> standard in the String object means I don&#x27;t have to worry about it.<p>Of course, I <i>do</i> have to worry about stuff like losing access to left-pad when someone throws an npm tantrum, or dealing with future build issues if npm becomes untrustworthy. A cryptographically sound package manager seems like a reasonable want, especially after this week&#x27;s issues.<p>But if your take-away from this whole problem is &quot;meh, javascript devs are lazy&quot;, you&#x27;re missing the point.
tschellenbach大约 9 年前
In a way this shows what a great job NPM did at making it easy to publish packages. It&#x27;s so easy that people decide to package up extremely easy functions.<p>As a python developer I would never publish a small package, simply due to the overhead of setting up a PIP package.
评论 #11349150 未加载
评论 #11349707 未加载
haberman大约 9 年前
&gt; In my opinion, if you cannot write a left-pad, is-positive-integer, or isArray function in 5 minutes flat (including the time you spend Googling), then you don’t actually know how to code.<p>Spoken like someone who writes functions in 5 minutes that I find bugs in later.<p>Just because a problem is simple to describe informally doesn&#x27;t mean it is simple to implement without bugs.
评论 #11352898 未加载
terryf大约 9 年前
So, apparently some guys managed to build a system where it is very easy to re-use small parts of other people&#x27;s code and now the author is complaining that &quot;too much code re-use is happening&quot; ?<p>I&#x27;m fairly old, so I remember the complaints a decade or two ago that people had where &quot;We can compose hardware from IC&#x27;s and you don&#x27;t have to know what&#x27;s going on inside and it&#x27;s all standard and just works! Why can we not do that with software?!?! (of course that ended up with things like CORBA and DCOM, which was all wrong)&quot;<p>aaaand here we are in a situation where code re-use <i>is actually happening on a wide scale</i> and now you&#x27;re complainig about that?<p>28k lines in an empty project? ha, how many lines of code does the preprocessor generate for #include &lt;stdio.h&gt; I haven&#x27;t actually measured, but I bet it isn&#x27;t that far off from 28k lines.
评论 #11351048 未加载
qewrffewqwfqew大约 9 年前
The elephant in the room here is Javascript. No other scripting language has been so bloody awful in the past that a five-line module that saves you typing `array.prototype.forEach.call` or something that papers over the language&#x27;s awful idea of equality comparison with three functions has been &quot;useful&quot; or &quot;more than five minutes coding without references&quot;.<p>Granted, these modules don&#x27;t do such useful things, but that&#x27;s the environment their creators were immersed in.
评论 #11350740 未加载
jgrahamc大约 9 年前
<i>What concerns me here is that so many packages took on a dependency for a simple left padding string function, rather than taking 2 minutes to write such a basic function themselves.</i><p>It takes more than two minutes. That little module has a test suite, if you&#x27;re including it then you have some assurance it does what it says it does. If you write it you&#x27;ve got to worry about whether it works or not.
评论 #11350136 未加载
spo81rty大约 9 年前
As a dot net developer I avoid adding packages and references at all costs due to all of these same reasons. Usually for something simple like this left pad example, I just copy the code and put it in to my project in some sort of class of helper functions or extension methods.<p>Seems like a lot of these basic Javascript functions need to be built in to javascript&#x2F;node itself or consolidated down to a single package of common core functions that extend Javascript. Like padding, is array, etc. As others mentioned, these are fundamental things in other languages.
xupybd大约 9 年前
Have we forgotten how to program? No, we have changed the way we program. We leverage the work of others to solve ever more complex problems. When we do this we get more than just the simple functionality we require. We get all the testing that comes from a package being used by thousands of projects. We get updates when people find a better faster way. We get to lower the number of lines of code we have to maintain.<p>Yes, these are simple tasks but do we gain anything doing these simple tasks ourselves? I find there is a finite amount of focus I have when programming, and I&#x27;d rather spend that solving the bigger problem.<p>This reminds me of a discussion I overheard between two professors when I was an undergrad. Prof 1 &quot;This new language makes it so much easier to x, y and z&quot; Prof 2 &quot;Yes but what&#x27;s the point, I can do all these things in Java&quot; Prof 1 &quot;I could do all these things in NAND gates, but I&#x27;ll get more work done if I have this tool.&quot;
xdissent大约 9 年前
In the case of left-pad, 2538464 of its 2550569 downloads last month are attributed to dependents of the line-numbers package (<a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;line-numbers" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;line-numbers</a>). So it would appear that relatively few people directly rely on left-pad, which highlights the importance of vetting the dependencies of dependencies.
评论 #11349140 未加载
评论 #11349660 未加载
buckbova大约 9 年前
Nearly everyone has had it drilled into them the &quot;Don&#x27;t reinvent the wheel.&quot; nonsense for better or worse.<p>I use lodash in almost every javascript project I start, big or small because it makes my life easier.<p>I&#x27;d rather use the lodash isArray than roll my own.<p><a href="https:&#x2F;&#x2F;lodash.com&#x2F;docs#isArray" rel="nofollow">https:&#x2F;&#x2F;lodash.com&#x2F;docs#isArray</a>
评论 #11349180 未加载
评论 #11349085 未加载
nick32m大约 9 年前
What&#x27;s the problem of writing a function with a few lines of code and exports as a module?<p>I think it&#x27;s totally fine. Like other people said, it&#x27;s the mindset we borrow from Unix, do one thing and do one thing well. The function would be well tested, and could be reusable.<p>I don&#x27;t understand why so many people just require lodash into their project (when they start project) while they only use one or only minimum set of the functions. I mean lodash is a very great library with clean and well tested code, but it&#x27;s also quite bulky like a big utility lib, and for me most of the time I only need one or two of the functions I would just go to npm and find a module just do that thing.
评论 #11349548 未加载
gardano大约 9 年前
When I was prevented from upgrading Xcode&#x2F;Swift for a project last year because of podfile dependencies, that cemented in my mind that every time I include a dependency, I&#x27;m putting myself at risk.<p>If I can spend half a day writing the code myself, I will -- because I know it will prevent headaches down the road. Yes, yes, I know any code I write adds the probability of bugs down the road. But at least the roadblock would be of my own doing, and not dependent on if&#x2F;when the package maintainer upgrades their stuff.
supermatt大约 9 年前
There are lots of useful titbits often left out of a languages corelib.<p>Back in the day we would have built up various pieces of library code, which we would have utilised rather than continually guessing best practices. For example, the isArray method cited may be trivial but is also non obvious. We&#x27;d probably have something like that in our library of useful snippets.<p>Sometimes we may have shared the code on forums and the like and people would copy and paste the code, sometimes into their own libraries. We would locate them by browsing known locations or inefficiently querying search engines<p>Now we utilise a central resource and simple tools to have a global library of code. Instead of searching far and wide we query a handful of tools that effectively does the copying and pasting for us.<p>How that can be considered a bad thing is beyond me. It&#x27;s not a question of knowing how to code, it&#x27;s a question of using your time effectively.<p>Granted, there is the problem of so-called modules being removed and dependencies breaking. This can be alleviated by vendoring your modules, a simple task with most dependency management tools.<p>Personally I think that published modules should persistent indefinitely based on the license the code utilises, although I&#x27;m not clear on the actual legalities of the recent npm issue (although if it&#x27;s due to a trademark complaint, I don&#x27;t see how it would ever be enforceable for completely unrelated code in any slightly sane country).
newobj大约 9 年前
Have we forgotten how to program?<p>Maybe we&#x27;ve forgotten how to &#x2F;just&#x2F; program. Everyone bangs the drum so hard of &quot;let github be your resume.&quot; Incentivizing putting every brain fart you ever had out into the universe instead of just keeping it to yourself.<p>Just a thought.
评论 #11349369 未加载
lmm大约 9 年前
If your package manager is so cumbersome that it makes a 14-line package not worth it, get a better package manager.<p>We haven&#x27;t forgotten how to program. We&#x27;ve got better at it.
评论 #11349453 未加载
adamwong246大约 9 年前
&quot;There are no small parts, only small actors&quot;. - Constantin Stanislavski<p>If there&#x27;s a flaw to this debacle, it&#x27;s that packages can be un-published. That is some grade A+ BS.<p>But no, there is no such thing as a package too small. Coding is hard. Collaboration should be default-on, not default-off.
joeandaverde大约 9 年前
I completely agree with the author.<p>The loudest people in the Node community have been evangelizing this practice for as long as I can remember. This shouldn&#x27;t come as a surprise.<p>The argument, &quot;If I didn&#x27;t write it I don&#x27;t have to think about it&quot; is ludicrous. I just have to point at the left-pad incident disprove the premise of this argument.<p>The analogy of building things with a bunch of npm lego blocks is laughable. Those responsible for advocating the use of trivial functions by acquiring module dependencies are leading the masses astray.<p>&quot;But, If I find that there&#x27;s a bug in a module I can AUTOMATICALLY fix it everywhere!&quot;<p>No.<p>You still need to assess how the change to that module impacts any code that depends on it. Just by updating a module and posting a &quot;minor&quot; bug fix can lead to other bugs that RELIED on the behavior as it was originally written.<p>It&#x27;s simple, write your own trivial functions. Test them. Maintain them.<p>P.S.<p>Another module that can easily be in-lined to every code base you own. (3 million downloads this week).<p><a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;escape-string-regexp" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;escape-string-regexp</a>
评论 #11351129 未加载
sauere大约 9 年前
&gt; There’s a package called isArray that has 880,000 downloads a day, and 18 million downloads in February of 2016. It has 72 dependent NPM packages. Here’s it’s entire 1 line of code: return toString.call(arr) == &#x27;[object Array]&#x27;;<p>How anyone can deal with JavaScript for more than 5 minutes is absolutely beyond me
评论 #11349243 未加载
asragab大约 9 年前
This was probably grotesquely naive of me, but I literally had no idea how jenga-tower like the javascript ecosystem was. Eye opener!
nnq大约 9 年前
...maybe it&#x27;s time a committee of <i>really smart people</i> sit and sip through all the most used modules below N lines of code or smth, and just write an opensource JS-stdlib, hopefully merging in top 30% most used methods of Lodash too? Node&#x2F;NPM is a great example of why <i>too much democracy and decentralization is bad</i>. Just gather some experts and have them <i>centrally plan</i> a &quot;standard library&quot; then impose it as &quot;industry standard&quot; have a recommended &quot;no fragmentation policy&quot; like &quot;no forking&quot; and &quot;use it all or not at all&quot;, the hell with your web app&#x27;s need for &quot;performance&quot;... even a few hundred Ks of code will not hurt anyone nowadays ff sake...<p>I even consider PHP a &quot;more sane&quot; language because you at least have most of the useful utility functions in a global namespace and everyone uses them. Of course, the real ideal on this is Python&#x27;s solution: a nice set of standard libraries that you know are baked in, but most of them you still import explicitly - hence it&#x27;s pretty easy to write even large Python applications that have a small and comprehensible number of dependencies!<p>(And more generally: our strike for &quot;more efficiency&quot; in programming is stupid imho! I&#x27;d always take a less efficient solution, even &quot;less safe&#x2F;tested&quot;, if it&#x27;s more &quot;understandable&quot; and &quot;explainable&quot; and sometimes, paradoxically, making things a bit more monolithic and centrally planned makes then orders of magnitude easier to reason about for our tiny ape brains...)
评论 #11351625 未加载
评论 #11351189 未加载
tomohawk大约 9 年前
Rob Pike: &quot;A little copying is better than a little dependency&quot;
评论 #11349514 未加载
chukye大约 9 年前
Man, I have to quote: `In my opinion, if you cannot write a left-pad, is-positive-integer, or isArray function in 5 minutes flat (including the time you spend Googling), then you don’t actually know how to code.`<p>You would be surprised of how many developer these days have &#x27;afraid&#x27; to write such functions, or how lazy they are, they found this thing and just add to a project, then push to some google list and the project got a lot of followers, and in the next day the project has changed about 90%. I saw this happen over and over again in this ecosystem, this is insane dude.<p>A lesson I learn is: you _need_ to read every module source code before add to any project, the NPM ecosystem has so many &quot;shits&quot; out there. You cannot trust in <i>any</i> npm module, recently I tried to trust in a module that has more than 5k stars, but I found a such ugly bug on that, that I feel my soul die, and I swear I hear the angels cry, thats not how open source supposed to be.<p>These days, seems that people dont care about the &#x27;bug free&#x27; as long as it work a half way.
评论 #11352919 未加载
noiv大约 9 年前
The Python community has a proper response: <a href="https:&#x2F;&#x2F;pypi.python.org&#x2F;pypi&#x2F;left-pad&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pypi.python.org&#x2F;pypi&#x2F;left-pad&#x2F;</a> &#x2F;s
评论 #11351825 未加载
Alex3917大约 9 年前
So any developer could make this in five minutes, but for some reason they can&#x27;t verify whether or not it works? That doesn&#x27;t make sense.<p>In reality it <i>could</i> take an hour to get this working properly, but it <i>does</i> take only a couple minutes to verify that the solution here is correct. There are certainly good reasons for not adding extra dependencies to your project, but trading a known amount of time to check that an existing project does what you want for an unknown amount of time to redo it yourself is probably not a great bet.
imh大约 9 年前
Unzipped, the source code for GNU coreutils is 30MB (zipped 4MB). This is a great example of a collection of single purpose functions you should never rewrite yourself. There&#x27;s only one dependency if you want to use them because they&#x27;re packaged together. With normal desktop code, 30MB doesn&#x27;t really matter and you can link only what you need. Can you do that with the usual Javascript package managers&#x2F;bundlers, or would you need to send the whole 30MB package to the client to use one function from it?
mr_justin大约 9 年前
It&#x27;s not that anyone has forgotten, it&#x27;s that a lot of people never learned how to in the first place. Every programmer community is riddled with these problems but the NPM world seems to be the worst. The ruby gem &quot;american_date&quot; annoys me to no end. It&#x27;s just a highly-specific implementation of Time#strptime. Gah
partycoder大约 9 年前
node is can be a good idea. But people don&#x27;t take JavaScript programming seriously. Most libraries objectively suck.<p>Google, authors of V8 and #1 subject matter experts on V8, have published coding standard. Does someone use it in the node community? No. Everyone loves &quot;standard&quot;, a lousy standard that allows everyone put a badge on their github page while still having a code base full of vomit.<p>JSDoc. A great solution for documentation. You would expect major libraries to adopt it, or a similar thing. But again, no. Major libraries such as busboy do not use them. The documentation resembles a napkin.<p>Then everything else: input validation, error handling, consistency... etc. Take &quot;request&quot; for instance, one of the most widely used libraries. The state machine it implements is inconsistent. You abort a request and get a timeout, you can abort a request without starting it and get an exception. Issues that will drive you insane while debugging.<p>Express, one of the most widely used web frameworks on node.js. Do this on a route: setTimeout(function(){ throw new Error(); });. Great, now you have broken out of the error handling context. Great job.<p>Node libraries suck all across the board. It&#x27;s the PHP of the 21st century. There are exceptions, like: lodash, bluebird, and others.
nikolay大约 9 年前
We have. I spent some time optimizing [0] a String.repeat function over at Stackoverflow and I was surprised that many developers today don&#x27;t know what they are doing, including core team members [1]. Specifically,<p><pre><code> function repeatString(str, len) { return Array.apply(null, { length: len + 1 }).join(str).slice(0, len) } </code></pre> [0]: <a href="http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;202605&#x2F;repeat-string-javascript&#x2F;36173160#36173160" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;202605&#x2F;repeat-string-java...</a><p>[1]: <a href="http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;202605&#x2F;repeat-string-javascript&#x2F;35319469#35319469" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;202605&#x2F;repeat-string-java...</a>
评论 #11349302 未加载
评论 #11349384 未加载
mtalantikite大约 9 年前
One of the things I&#x27;ve enjoyed the most while programming in Go for the past couple years is the standard library and how much the Go community emphasizes keeping external dependencies to a minimum. For most projects I find myself using few if any external packages.<p>Now of course there are times you&#x27;ll want to reach for a library, say for something like an http router, and up until recently the dependency management side of Go has been lacking. But when a pattern or library arises that many find useful the core team is open to pulling that in to the standard library if a strong enough case is made, for example in the context package (<a href="https:&#x2F;&#x2F;github.com&#x2F;golang&#x2F;go&#x2F;issues&#x2F;14660" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;golang&#x2F;go&#x2F;issues&#x2F;14660</a>).
88e282102ae2e5b大约 9 年前
To me, this looks like a symptom not of bad programmers but of a terrible standard library.
评论 #11352049 未加载
namuol大约 9 年前
Formula for a top HN article:<p>1. Make an observation about a popular thing. 2. Blindly extrapolate. 3. Make one or more broad, controversial statements. 4. (Optional) Nuance.
sebak大约 9 年前
The main reason there is a fetish for these micropackages is a fetish for github stars. The formula seems to be: Overly generic + Simple + Javascript = Lots of stars.<p>That being said, there is something to be said for using these micropackages. Left padding a string is easy, but you might just have forgotten about that one edge case where in browser X and language Y you have to do things different. It&#x27;s not really the case here, but things that seem simple at first often turn out to be hard because of some edge cases. One might hope these edge cases are solved if they use a library.
fredbot大约 9 年前
I call this kind of attitude the &quot;Tea Party&quot; of JavaScript development. The reason why we currently have JavaScript tooling fatigue is exactly because Tea Party developers insist on writing everything themselves instead of trying to build a better abstraction. The lesson here isn&#x27;t not fewer dependencies: it&#x27;s managing dependencies. NPM should not allow someone to arbitrarily remove modules that other&#x27;s may be depending on. It&#x27;s like building a bridge and them deciding to remove it after a whole city now depends on it.
评论 #11349676 未加载
overgard大约 9 年前
Here&#x27;s the funny thing that gets forgotten: in a lot of commercial software, 3rd party dependencies need to go through legal to get properly vetted and attributed and so on. This also usually requires an engineer (to be able to answer things like if it&#x27;s dynamically linked or not, etc.).<p>As staid and corporate as it might sound initially, it&#x27;s a very smart thing to do. One screw-up with licenses could be catastrophic. Are you all really checking that carefully?<p>I can&#x27;t even imagine how any sort of proper legal checks could be done with a trillion micro libraries.
robodale大约 9 年前
I&#x27;m content and happy not knowing what the fuck this is all about. Pad left? Are you kidding me? If your tower og babel fell because of your reliance on some script kiddie&#x27;s toy project, I am happy and content knowing you get what you deserve. Law of leaky abstractions, motherfucker.
rycfan大约 9 年前
If I engage in as much hyperbole as the author, where does &quot;write it yourself&quot; stop? If I&#x27;m working on a team of two, should we each write our own left-pad? How about a team of three? Four? Five? Fifty? At a certain point, it makes sense for that to be written once for the project. We spent 30 years in software engineering trying to figure out how to get code re-use, and now that&#x27;s it common and widespread, we want to go back to NIH?
评论 #11350876 未加载
评论 #11351794 未加载
meric大约 9 年前
NPM modules can be used on browsers. On browsers, space is a premium.<p>Why would you want to install a 500kb dependency that has only one function you need, when you can install a 10kb dependency that has it?<p>Would you want each of your five 20kb dependencies to re-implement the same 5kb function, increasing the code you must send to the client by 20%, or would it be more optimal for each of those dependency to use the same 5kb function?<p>The author rants about practices of developers from different programming environment, without experience, without figuring how things came to be. If he did give an effort to think from the perspective from Node.JS developers he’d have addressed the previous two points.<p>This is like going to a friend’s house and complaining everything is put in the wrong place. It would have been wise to immerse in Node.JS conventions and observe for a while before making comment.<p><i>EDIT: Reply to scrollaway:</i><p>I&#x27;ve also understated the problem.<p>Let&#x27;s look at the problem in the current Node.js environment, it&#x27;s not uncommon for a web app to have 20 dependencies, each of those have 10, and each of those 10 have 5. That&#x27;s a total of 20 times 10 times 5 = 1000 dependencies in total.<p>Let&#x27;s say you were to remove a 10 line library function that&#x27;s &quot;standard library-like&quot;, used by 15% of those dependencies, and have each of the existing dependencies re-implement that in each of those dependencies that uses it.<p>15% times 1000 times 10 lines is 1500 lines of code.<p>So if you&#x27;re going to troll a solid argument by nitpicking, do it properly and get the details right.
评论 #11350901 未加载
评论 #11349672 未加载
kerkeslager大约 9 年前
A lot of the discussion here really isn&#x27;t talking about the problem at hand.<p>From the perspective of Babelify users, a major bug was introduced into software they depended on. I don&#x27;t know how much money in developer time was lost due to this but it would almost certainly be in the thousands of dollars.<p>And it could have been a lot worse. It could have been something more complicated than left-pad. The author could have introduced a vulnerability or outright malicious code, or been hacked and done the same, and millions of people would have downloaded it and run it.<p>Arguably, small modules are good if you control them. Maybe they are more composable, maybe they enable better testing, maybe they encourage code reuse. I am not going to argue for our against small modules.<p>But none of the positives of small modules matter if an unknown developer who you have no reason to trust can change or unpublish the module out from under you. It&#x27;s irresponsible as developers to risk our employers&#x27; and clients&#x27; businesses in this way for a function we could write in five minutes.
spion大约 9 年前
Its interesting how everyone used this as a chance to attack the small modules approach. This approach definitely has downsides, but the problem caused by leftPad being unpublished wasn&#x27;t one of them.<p>If jdalton declared a jihad on arrays tomorrow and decided to pull all array related functions from lodash, we would have the exact same problem.<p>If kriskowal decided that Q must mirror built in Promise and published a version that does this tomorrow, we would again have the exact same problem.<p>There is only one connection between this problem and the small module approach. As the size of a module decreases, the number of dependencies increases and so does the number of authors that produced your dependencies. With the number of authors increasing, the chances that some author decides to go rouge or protest for some reason also significantly increases.<p>Therefore, its irresponsible to use this approach with a package manager that allows an old, established module with many dependents to be unpublished so easily by the original author.
评论 #11352186 未加载
sebringj大约 9 年前
This is a non-issue and taking focus away from the real issue. The issue is the security hole that NPM opens up when a namespace can be grabbed up by anyone if the original developer pulls out.
评论 #11349135 未加载
评论 #11349219 未加载
omaranto大约 9 年前
This culture of tiny one-function modules sounds like Joe Armtrong&#x27;s proposal about the &quot;Key-Value database of all functions&quot;.<p><a href="http:&#x2F;&#x2F;erlang.org&#x2F;pipermail&#x2F;erlang-questions&#x2F;2011-May&#x2F;058768.html" rel="nofollow">http:&#x2F;&#x2F;erlang.org&#x2F;pipermail&#x2F;erlang-questions&#x2F;2011-May&#x2F;058768...</a>
rimunroe大约 9 年前
I&#x27;m not really sure whether or not I should to add my voice to the din, but I feel like this whole thing is more a problem with npm and what it allows vs. what it encourages (and the rather paltry standard libraries in Node &amp; browsers), rather than a problem with developers feeling entitled to not have to write their sorters and padding functions.<p>npm actively encourages structuring projects as many tiny individual modules and dealing with the resultant dependency trees and deduplication. Both of these things (along with the ease of publication) combine to encourage people to share their packages.<p>They make it incredibly easy to consume code from other people, but but at the same time provide a similarly low-barrier mechanism to retroactively change published code. That combination seems like a <i>way</i> more deserving topic of criticism than the unending refrain of &quot;developers these days are so lazy&quot;.
jeffdavis大约 9 年前
Joe Armstrong had an interesting related comment here:<p><a href="http:&#x2F;&#x2F;erlang.org&#x2F;pipermail&#x2F;erlang-questions&#x2F;2011-May&#x2F;058768.html" rel="nofollow">http:&#x2F;&#x2F;erlang.org&#x2F;pipermail&#x2F;erlang-questions&#x2F;2011-May&#x2F;058768...</a><p>Maybe the unit of modularity should be a single function and we can do away with modules?
UK-AL大约 9 年前
I find NPM packaging ridiculous. Awhile I go I used NPM on windows, where the folder hierarchy became so deep it broke windows file handling. I could not delete the modules folder. I had install a npm package which allowed me to delete it. I think this is fixed in new versions by flattening the hierarchy, but still.
评论 #11349733 未加载
gdulli大约 9 年前
There&#x27;s so much wrong here, it can&#x27;t even all be seen at once. The part we can perceive is only a projection from a higher dimension into our three-dimensional space.
kevin_thibedeau大约 9 年前
The insanity is that JavaScript doesn&#x27;t have a standard string library. More a case of forgetting how to design a programming language than how to program.
评论 #11351056 未加载
memracom大约 9 年前
Agreed. Most development groups should be building a local collection of utilities that contains all of these snippets, and most importantly, some documentation of what they do and some unit tests to demonstrate that they are correct.<p>No need to have global dependencies on small snippets that really should be in a core library anyway. C has libc, Java and C# have the creator&#x27;s (Oracle or Microsoft) standard set of libraries, Python has the &quot;batteries included&quot; stuff in all the different distros. And so on. All of these snippets rightly belong elsewhere, not in packages.<p>And even if you did get them added to the right libraries, I guarantee you that you will not get rid of the need for a collection of small, and somewhat random, in-house functions, classes and libraries.
thrillgore大约 9 年前
I started out really thinking Kik was wrong to sue this guy but like with all things, the longer this goes on the less sympathetic I grow.<p>Write your own goddamn utility classes, people. Or learn how to suspend package releases, include them in your projects, and smoke test your releases.
评论 #11351303 未加载
dreta大约 9 年前
After reading this, i don’t think i’m capable of ever complain about OOP again. Whenever you think you’ve seen it all, web developers always manage to come up with something worse. The only thing more depressing than this is the comment section below the article.
dc2大约 9 年前
For a less sensational review of this situation, NPM published a post-mortem:<p><a href="http:&#x2F;&#x2F;blog.npmjs.org&#x2F;post&#x2F;141577284765&#x2F;kik-left-pad-and-npm" rel="nofollow">http:&#x2F;&#x2F;blog.npmjs.org&#x2F;post&#x2F;141577284765&#x2F;kik-left-pad-and-npm</a>
pklausler大约 9 年前
Insight from this story: If it is important that a thing be done correctly, it should not be made so easy to do that it will end up being done by people who shouldn&#x27;t be allowed to do it.<p>I may have just invented a rule for choosing programming language and systems there.
j-diaz大约 9 年前
Another explanation for the flourishing of these one function modules may be the fact that some people feel a kind of high&#x2F;achievement from being able to say they have a published module out there. A sort of bragging rights if you will.
评论 #11354746 未加载
Animats大约 9 年前
It beats the alternative - pulling in some huge package with lots of little functions, all of which end up in the output. At least you&#x27;re not loading huge amounts of unreachable code into the running system.<p>In languages with linkers, the better linkers would discard all unreachable functions. Then came DLLs. Use one function in a DLL&#x2F;.so, and the whole thing has to be loaded. Go and Rust are usually statically linked, reflecting the fact that pulling in big DLLs was usually a lose. You rarely have two different programs on the same machine using the same DLLs, except for some standard low-level ones such as the C library.
cel1ne大约 9 年前
I know the discussion revolves around the amount of dependencies, but I want to add a comment about semver, which has a part in this mess:<p>In my opinion it will not be done right in 80% of cases.<p>Every breaking change requires updating the major versions, but developer are hesitating to go from 1.0.0 to 6.0.0 in a month.<p>The way out is staying in the 0.x range therefore abandoning semver alltogether.<p>A nice write up about how packages are not following semver in java-land:<p><a href="http:&#x2F;&#x2F;avandeursen.com&#x2F;2014&#x2F;10&#x2F;09&#x2F;semantic-versioning-in-maven-central-breaking-changes&#x2F;" rel="nofollow">http:&#x2F;&#x2F;avandeursen.com&#x2F;2014&#x2F;10&#x2F;09&#x2F;semantic-versioning-in-mav...</a>
kf5jak大约 9 年前
I wouldn&#x27;t even think of looking for a package that does something as simple as the ones mentioned. If I need to pad a string, my first thought would be to create a new function, not look for a package...
blainesch大约 9 年前
I think we missed the point here. The fact that it&#x27;s 11 lines is meaningless, this could have been babel itself.
duncanawoods大约 9 年前
The problem with shared hyper-modularisation is that it assumes the name of a function is unambiguous with only one valid implementation. If that were true, it should be encouraged but given it isn&#x27;t, the practice will crushed by ambiguity and unintended consequences.<p>My app might well have an is-positive-integer function but it will include a range of context dependent choices about e.g. floating point, infinities, zero, null, &quot;9&quot;, &quot;9 &quot;, &quot;09&quot;, boxed numbers, string representations exceeding js max int, etc. etc.
joshstrange大约 9 年前
I can&#x27;t take this author seriously at all, one of his most egregious cases is the is-positive-integer library which until today had around 30 downloads in the last month.... No one was really using this and furthermore of course you can find bad&#x2F;iffy code on NPM for the same reason you can find bad&#x2F;iffy code on github. ANYONE can publish code. I could write a similar module for any other library, publish it to their repo, then scream LOOK! python is stupid and python devs are stupid.<p>I firmly believe that building on what has already been done allows for much safer code written at a quicker pace. Why should we constantly repeat ourselves? Also by using npm modules we can abstract logic and prevent someone on the team from going in and modifying it for their own use. It is a documented&#x2F;constant function that we can use knowing exactly what it does. Is it a better world where everyone just copies code out other&#x27;s repos and then has to include the licence&#x2F;docs&#x2F;tests along with it? It&#x27;s much easier to just pull in the repo which contains everything and make it trivial to see where a function came from.<p>People are blowing this whole thing way out of proportion just because it makes a good headline &quot;11 lines of code broke node&quot;... You can all try to shame people who build on what&#x27;s come before and chant &quot;Not invented here&quot; but I&#x27;ll opt to build on what is proven to work instead of rewriting everything. At the end of the day that&#x27;s what ships products.
HarrietJones大约 9 年前
This isn&#x27;t forgetting to program, it&#x27;s a deliberate choice as to how library code needs to be organised. We can disagree about choices made, but let&#x27;s not assume other people aren&#x27;t able to code as well as we think we can code.<p>That being said, I think this is a perfect example of where a good concept (small, tightly scoped modules) is applied dogmatically at the cost of the codebase. It&#x27;s the node.js equivalent of AbstractRequestFactoryFactoryFactory stuff you see in Java, and the Mock Messes you see in Ruby.
stevewilhelm大约 9 年前
&gt; What concerns me here is that so many packages took on a dependency for a simple left padding string function<p>Clearly to mitigate such a tightly coupled dependency, Left-Pad should be a micro-service. :-\
spotman大约 9 年前
Every single dependency you import should make you nervous. You would look at it like hiring someone. You are letting go of some responsibility. You are letting go of some control. The end result might be better than you could do in-house, but it might not. But you are already <i>hoping</i> that it&#x27;s better, and giving up <i>control</i>.<p>Save these for the things you can not do in house, like NaCL. Don&#x27;t write that yourself.<p>But string padding, sorry. Any developer worth their salt would laugh at adding a dependency for this. It&#x27;s irresponsible, and comes across as amateur hour.<p>This is a simple case of optimizing for responsibility. The inexperienced programmer does not know how to do this, because they have not spent enough time being responsible, and having to deal with the fallout of managing responsibility poorly.<p>An experienced programmer carefully manages responsibility. A simple function, that is easy to understand, easy to test, and easy to reason about, is something that makes more sense to either pull all the way into your codebase, or write yourself.<p>Years of doing this means that managing dependencies should never be just slap it into your packaging system and start using the function. If you are on the line for making the wheels turn for a large scale platform that is directly connected to a monetary transaction of some nature, you will quickly find yourself preferring to remain responsible for everything that you possibly can control. There is certainly enough that you can&#x27;t control to keep you on your toes.
erikpukinskis大约 9 年前
I think this is the fundamental thing people don&#x27;t understand about NPM and JavaScript, and the web in general:<p>Nothing is included. And that&#x27;s a feature. The web is not trying to be the kitchen sink. That&#x27;s iOS. They provide high level APIs for <i>everything</i>. And as a result, the platform is architecturally only as vibrant as Apple can make it.<p>Now maybe you&#x27;re happy with Apple, maybe you love the iOS APIs. But if you don&#x27;t, you&#x27;re stuck. There&#x27;s not a rich bed of alternative view layers that you can draw from to build your own vision of how software should work.<p>Node and the web browser strive to be <i>lowest common denominators</i>. They provide just the very basics: a document format, a very simple programming language, and an http server. The rest is up to you.<p>That&#x27;s pretty scary, and so the JavaScript world has dabbled in frameworks. In the end all-inclusive frameworks are antithetical to the spirit I&#x27;m talking about, so things trend towards small modules that do one thing pretty well. People go overboard sometimes. I would argue left-pad should just be a copy-pasted snippet rather than module. But that&#x27;s not a sickness in the community, it&#x27;s just developers feeling out how far to go.<p>If you like every application to look the same, and you don&#x27;t mind being chained to enormous and restrictive standard libraries and frameworks, then you will hate JavaScript. If you like writing software from scratch, forming opinions about all of the different parts of the system, and allowing each application to be built out of different parts, out of the right parts, then you should give JavaScript a closer look.
评论 #11350963 未加载
评论 #11351472 未加载
gsmethells大约 9 年前
The fact that anyone has to even think about code size is the real problem.<p>Yes, downloading a giant JS lib for one function is insane, hence the ton of tiny dependencies.<p>However, it is equally insane that basic SDK expectations found in every other language has yet to come to be pre-implemented by the JS engine in the web browser itself. Some basic code ought to already be on the localhost the moment your app arrives.
tobltobs大约 9 年前
Need more of this WTF stuff? Have a look at the docker registry&#x2F;repository&#x2F;hub and those pearls of wisdom of the new DevOps guilde.
plugnburn大约 9 年前
Have to put a little clarity over my &quot;so sad yet so true&quot;.<p>When the developers of such a serious library as React start to depend on a third-party one-function module made by some Dick-from-a-mountain (a russian idiom that means a random person who did nothing significant but tries to show out in all possible means), that means React developers are even more to blame than that Dick-from-a-mountain himself.<p>If you make any really popular piece of software, you absolutely <i>must</i> have a failover plan. No excuses for not having it.<p>But what&#x27;s even sadder is that this issue had spawned a new wave of pseudo-elitist attacks on the entire JS dev community. Calm down guys, things like that could have happened for <i>any</i> language that has a widely-used centralized package system (Perl&#x27;s CPAN, Python&#x27;s pip, Ruby&#x27;s gems etc).<p>Let me repeat that again: languages don&#x27;t make software bad, people do. Just don&#x27;t let such Dicks-from-a-mountain rule over your own modules with elementary stuff like leftpad, and you&#x27;ll be safe.
markbnj大约 9 年前
This is literally one of the funniest things I&#x27;ve heard about in months. Look for my new python library isDict, coming soon.
nv-vn大约 9 年前
Here&#x27;s a proposal (that I&#x27;m sure others have come up with in the past) -- why not create one big, community backed &quot;batteries included&quot;-type module that would implement all the small, commonly used functions. This could combine all these ridiculously small libraries and greatly reduce the number of necessary dependencies for a package. Extending the standard library should be just that: standardized. If the entire community focused on one project like that they could just as easily write the same code (but with smaller package.jsons, less require()s, and less time spent learning new libraries&#x2F;searching for the right libraries. In fact, it would be great if something like that could be packaged as a standard node module so you&#x27;d get the same sort of quality assurance as you get with official projects.
评论 #11349459 未加载
fieryeagle大约 9 年前
&lt;rant&gt; The problem here is JS developers have baked in the notion of having NPM as the alternative to Google + StackOverflow + own thoughts. It&#x27;s really a no-brainer (literally) to just slap another package than to bother thinking about what a piece of code does, the edge cases and pitfalls. Move fast and break things, right?<p>Sure there was some argument about Unix philosophy, small module doing one thing and does it very well. Did anyone bother considering the quality of most NPM packages? Quality is not reflected with passed Travis CI or extensive community testing and feedbacks. Not at all. Look at the those packages on apt-get. They are modular and robust. They do what they were supposed to do.<p>Now take a long hard look at the state of NPM. What do we have? People clamoring for reusability and whatnots. Most of them don&#x27;t even know what they&#x27;re talking about, just reciting the latest hip statement from the Internet. Being mature about development means accountability for what you do, not pushing shit around that you don&#x27;t even have knowledge off. As a self-proclaimed polyglot, I love JavaScript as a language but not the ecosystem. It&#x27;s like watching a dog chasing its tails:<p>- Endless loops of discussion that help stroke the egos but not improve anything else.<p>- Craps for resume&#x2F;repository padding, not for actual developers to use.<p>- Bandwagon mentality that just pushes the latest fad along, and the herd towards the cliff.<p>The notion that JS developers are kids playing grown-up, has been reinforced with this NPM incident. If we want to discard that notion slowly, we need to be more mature developers. It&#x27;s that simple. Here&#x27;s what I think we could do: - Have a clear idea on what dependency you need. Browser, IDE, terminal etc are dependencies. Basic type checking is not. - Be better craftsmen. Roll and maintain your own toolboxes. Only share a working hammer, not a broken nail or a wood chip. - Note that for each package you publish, thousands more hours would be spent on learning, adapting, using and reporting mistakes. Collectively, the current community wastes so much time with finding the right things to use. Often times, we learn much more by playing with code, even posting on StackOverflow. That&#x27;s hands-on, `npm i` is not. - Own the code better. The idea that teams like Babel and React devs with all the brilliant developers choose to put their eggs in a private corp&#x27;s whims is just scary. You can&#x27;t hope to build robust software while playing Jenga tower.
grillorafael大约 9 年前
I agree that some packages might be too much but I don&#x27;t think `left-pad` is one of them.<p>I wrote my own left-pad for a project I&#x27;m working now and I had to revisit a few times for tiny problems and lack of time to write tests. I would definitely use `left-pad` module if I knew the existence at that time.
zalzal大约 9 年前
Separate from the discussion of whether super small modules and hundreds or thousands of deps are a good idea, is the point of operational stability.<p>Putting on your devops hat, whatever your dependencies, from a reliability and reproducibility point of view, you should control your reliance on unexpected decisions of npm or third-party developers. A lot of the panic with npm issues comes from people blindly using the npm registry and then seeing breakages, with no safety net. I hate to say &quot;I told you so&quot; but this is an issue we worried about a lot when considering Node productionization last year: <a href="https:&#x2F;&#x2F;medium.com&#x2F;@ojoshe&#x2F;fast-reproducible-node-builds-c02bca056739" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;@ojoshe&#x2F;fast-reproducible-node-builds-c02...</a>
vu3rdd大约 9 年前
I am posting the article &quot;No silver bullets&quot; again, in the wake of the npm fiasco. I think it is an essential reading for every programmer, every year!<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=11350728" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=11350728</a>
innocentoldguy大约 9 年前
This problem speaks volumes about the myriad shortcomings of the JavaScript standard library, in my opinion.
grumblestumble大约 9 年前
Couple of things:<p>* If you&#x27;re in favor of the micro-module approach, you shouldn&#x27;t be relying directly on NPM, and should have something like Sinopia in place. After all, external code isn&#x27;t the only thing you&#x27;re vendoring, right?<p>* Micro modules are fine - but your application code should depend on a privately published utils module whose entry point is a prebuilt distribution of all your external micro-modules exposed through a facade. Your utils module deps are all installed as dev dependencies to avoid the Fractal Nightmare.<p>* Yay, now you have your own &#x27;standard library&#x27; which still manages to leverage the NPM philosophy of distributed code. And if some twit decides to throw a tantrum, it will only impact future builds of your custom std lib - and you&#x27;ll know about it at build time.
lucb1e大约 9 年前
Yeah look at all these modern languages that do so much for you, like .empty() on an array -- have we forgotten how to do simple comparisons?! You could just take a second to consider the properties of an empty array, namely it contains no items (.count() == 0).<p>My point being, if something is a completely reusable and basic feature, a dependency is totally just. I remember a few years ago when I and all devs I knew (which weren&#x27;t many, I was maybe 17) had our own libraries to include in all personal projects we made. It contained features we had to look up once and from then on just automated and imported, stuff like password hashing or input checking. This went out of style as single-programmer programs are going out of style, but the little useful features are still there.
joantune大约 9 年前
One can argue that modules are good, but them depending blindly on newer versions like that was bad dependency management.<p>I say this because I strongly believe that reinventing the wheel is unnecessary and can bring more problems than not.<p>There are many examples, and I could come up with a made up one, but here&#x27;s a very real bug that I debugged from another programmer not so long ago:<p>So, he came up with a JNI for SPSS&#x27;s C library, applied it correctly, and got haunted for lots of months with an unsolvable bug. The problem? he miswrote the final copy of the file, and sometimes, some bytes where copied twice.<p>He tried to solve this problem for a long time (and eventually lived with it because SPSS was still resilient to this)<p>Is this concrete example of a &#x27;module&#x27; ridiculously short? yes, but my logic still holds IMO.
morgante大约 9 年前
This shows the beauty and success of npm in making it very easy and cheap to publish small modules.<p>It&#x27;s not that we can&#x27;t write a left pad function ourselves. It&#x27;s that we might easily miss an edge case or make a mistake in doing so.<p>The author seems to be hung up on a preconceived idea of what a package &quot;should&quot; be without actually offering a compelling argument for why a single short function can&#x27;t be a module.<p>Yes, every dependency you introduce is a liability. But so is every line of code you write. I&#x27;d much rather take the risk on a shared library which can be audited and battle tested by the entire community.<p>If a function is so easy to write, it&#x27;s trivial to check out the module&#x27;s code, review it does the right thing, and then lock the dependency.
AdamN大约 9 年前
One should think of these requires as like .h files and the underlying code as something like a .c file. They&#x27;re public definitions with potentially changing underlying code.<p>It&#x27;s good to have small packages. Don&#x27;t forget that the underlying ECMA script is changing so the implementation of these &#x27;libraries&#x27; are (or will be) different over time from what they used to be. If somebody finds a faster way to do the method, then it will be done.<p>Finally, anybody who has used js in the real world understands how many corner cases there are and how difficult it is to make durable methods (i.e. how to know if an array is empty - which requires like 4 different conditions).
gladimdim大约 9 年前
On DigitalOcean instance I cannot even use browserify+minify+babel6 cause npm process is killed by host (it consumes &gt; 512Mb of RAM). So I have to manually run browserify + babel then minify. Still it produces 500kb of bundle.js :D
svs大约 9 年前
The problem is not of small modules. The problem is lack of dependability. If the language patrons stand behind a set of modules and guarantee continuity and availability, it really doesn&#x27;t matter what is in them and the world can continue regardless of how insane the module or the whims of any one author. This is not about the technical merits of having or not having a stdlib. The module in question could have been anything.<p>Making this about is-positive-integer misses the point that this is a social&#x2F;political problem not a technical one. A language ecosystem must address concerns of business continuity as first class concerns.
ocdtrekkie大约 9 年前
My current programming project, my goal has been to do as much in-app as possible. Does that mean I&#x27;m more likely to have bugs in my own code? Yes. But I&#x27;ve learned a ton doing it, and I know that my code doesn&#x27;t have a giant monster of bloat hidden behind some random dependency somewhere. And yeah, that means when I wanted to handle email, I learned a heck of a lot about how programs handle email. Did it take more time? Yup. Education is time well spent.<p>I&#x27;ve got two dependencies besides the basic framework my project is built on: A scheduling engine, and a database interface. I eventually hope to factor out both.
评论 #11349003 未加载
评论 #11349004 未加载
nostrademons大约 9 年前
Somehow, someone always forgets that engineering is about trade-offs, and so every few years we can an indignant series of articles about how <i>stupid</i> and <i>ignorant</i> today&#x27;s programmers are and how we should all go back to the same processes that they called stupid and ignorant 4-5 years ago.<p>Relying on reimplementation, copy-paste, npm shrinkwrap, or various other ways of importing third-party code into your repository results in the following advantages:<p>1. You know exactly what goes into your product, and can audit everything for security, performance, or coding standards.<p>2. You often end up importing less, as third-party modules may have functionality that you don&#x27;t need but other clients do.<p>3. You can modify the resulting code to add showstopper functionality, even if upstream doesn&#x27;t want to.<p>4. You aren&#x27;t subject to the whims of someone removing your dependency from the Internet or replacing it with a version that does something you don&#x27;t want.<p>Relying on lots of little libraries installed via package manager gives you the following advantages:<p>1. You can easily install &amp; try out modules that other people have written, letting you test out new features on users more quickly.<p>2. You can share code with other modules that have the same dependencies, often reducing the overall size of your system. This is important when there&#x27;s a cost (eg. download size) to your total bundle.<p>3. You have less code for your engineers to read &amp; maintain.<p>4. You can easily track licensing &amp; contact information for your dependencies.<p>5. You automatically get any new features released by your upstream dependencies.<p>6. You automatically get <i>security updates</i> and performance enhancements released by your upstream dependencies.<p>The last is nothing to scoff at: imagine if the headline, instead of &#x27;left-pad breaks the Internet!&#x27;, had been a security vulnerability in left-pad which literally broke the Internet. Imagine how hard that would be to fix if everyone had copy&#x2F;pasted the code or re-implemented it. This is not an academic scenario either: remember &quot;Nearly all binary searches and mergesorts are broken&quot;, published by the guy who wrote the broken binary search implementation in the Java standard libraries?<p><a href="http:&#x2F;&#x2F;googleresearch.blogspot.com&#x2F;2006&#x2F;06&#x2F;extra-extra-read-all-about-it-nearly.html" rel="nofollow">http:&#x2F;&#x2F;googleresearch.blogspot.com&#x2F;2006&#x2F;06&#x2F;extra-extra-read-...</a><p><i>Always</i> copying your dependencies into your source tree is not the answer to this, no more than <i>always</i> relying on npm modules was the answer to updating your dependencies. They both have pluses and minuses, and if you really want to be a good programmer, you need to weigh both of them. For my projects, I tend to use whatever libraries I need when building them out (via npm, if possible), and then periodically <i>audit the dependencies</i> to make sure I&#x27;m still using them and they wouldn&#x27;t be better off incorporated directly into the project. I wish more products did this, but I don&#x27;t control what other programmers do.
评论 #11352551 未加载
smitherfield大约 9 年前
Without addressing the wisdom or lack thereof of including dependencies for small functions, perhaps the problem of disappearing&#x2F;changing small dependencies could be solved with an option along the lines of<p><pre><code> npm install &lt;small-dependency&gt; &lt;destination&gt; --save-inline </code></pre> Which would just copy the dependency verbatim to &lt;destination&gt;. Maybe have a &quot;&lt;dependency&gt; is 100kb. Are you sure you wish to copy the entire source to &lt;destination&gt; instead of using a &#x27;require&#x27; reference? y&#x2F;n&quot; prompt for the inevitable silly types who&#x27;d do it with Angular.
rsp1984大约 9 年前
Dependencies are one side of the problem. Unavailability of binaries and dogmatic use of dynamic linkage are the other side.<p>When I installed a simple lines-of-code counting tool through Macports the other day I accidentally opened the door to dependency hell as gigabytes of not even remotely related stuff started to build [1].<p>Without a doubt something is going very wrong with Free Software and package managers. On the other hand, never look a gift horse in the mouth so I may not even be the right guy to complain here.<p>[1] <a href="http:&#x2F;&#x2F;pastebin.com&#x2F;cAZgbaFN" rel="nofollow">http:&#x2F;&#x2F;pastebin.com&#x2F;cAZgbaFN</a>
andrewingram大约 9 年前
This is from a client-side web dev perspective:<p>I&#x27;m hoping that proper support for ES6 modules to enable tree-shaking bundle builds (in the short term), and HTTP2 with client support for modules (in the long term), will allow us to head towards a world where we converge around a handful of large utility libraries.<p>In theory, tiny dependencies was supposed to allow us to only include code we actually needed in our bundled code. Bu the reality is that everyone uses different tiny dependencies for solving the same problem. So you end up with enormous bundles made up of different solutions to the same tiny problems.
Artoemius大约 9 年前
It&#x27;s not that we have forgotten how to program. It&#x27;s that everybody and their dog is now a programmer.<p>Professional racers don&#x27;t need an automatic transmission, but it&#x27;s quite helpful for an unprofessional driver.
ycmbntrthrwaway大约 9 年前
What would happen to all those NPM projects if GitHub is destroyed? I don&#x27;t think it will close anytime soon, but lets say, a meteor shower hits GitHub data center or something along the lines of this.
评论 #11349515 未加载
评论 #11349190 未加载
评论 #11349192 未加载
doctorstupid大约 9 年前
Smart people created software that lowered the barriers of entry to making software. It was inevitable that not-so-smart people would eventually be writing software that others would build upon.
raz32dust大约 9 年前
The author brings up an excellent point, but I disagree with the solution. We should of course reuse existing, well-tested code if it available, even for simple things like left-padding. The real issue here is that there is a module for left-pad alone. If it were something like StringUtils module with a bunch of commonly used string functionality, it would have been great.<p>What is it about the node community that triggered this misunderstanding of package management and code reuse?
Shivetya大约 9 年前
Hell, the java programmers I work with seem to never use each others simple functions and instead recreate the will every single time.<p>As for the issue with such a short piece of code being reused by many, why score on number of lines? If it works and is a useful function is more important to me. I am not familiar with bundling within the usage the article covers but we tend to bundle like functions together and the compiler drops unused ones
blablabla123大约 9 年前
I guess this is the way one is supposed to use node, preventing one to write non-DRY code. (Golang takes the exact opposite approach, having it&#x27;s own drawbacks of course.) However, when using React, I kind of trust that the maintainers don&#x27;t include packages than require 12 star projects, and if, that they fork this stuff themselves.<p>BTW, isn&#x27;t that a Facebook project, so aren&#x27;t they supposed to use a CI? ;P
iamleppert大约 9 年前
I couldn&#x27;t agree more. I&#x27;ve been using the new ES6 style module syntax for a few days now because a co-worker forced me to, so he would use my library.<p>I&#x27;m not convinced its worth it compared to the simplicity of commonjs and module.exports. You have to pull in babel, which has over 40k files to do all this.<p>Why are people destroying the beautiful simplicity that is javascript? Can those people please go back to java?
评论 #11350109 未加载
ZeWaren大约 9 年前
Regardless of whether micro-modules are good or bad, I think that if you are the owner&#x2F;manager of a project, you should be able, given its full flat list of dependencies, to explain why each one of them is useful for you.<p>Every project I&#x27;ve seen that uses npm always required 100s or 1000s of dependencies.<p>If building or running your project requires something and you can&#x27;t explain why, I think there&#x27;s a problem.
alistproducer2大约 9 年前
On the one hand, I ,love how the JS community is constantly coming up with new [versions of old] things. Even though most of it is creative waste, it&#x27;s still creative and out of that churn we get some pretty awesome apps and tools.<p>On the other hand, there&#x27;s a lot of bad practices disguised as &quot;simple&quot; and &quot;efficient.&quot; Using NPM for one line functions is a great example of this.
hughw大约 9 年前
Of course I would never create a dependency on a small module like left-pad. I would simply copy the function wholesale into the body of my code!
StreamBright大约 9 年前
So funny, just few weeks back I had an argument with somebody about writing a simple functions vs. importing libs when you need less then 5% of the functionality. I am more convinced than ever that it is better off to have the least amount of external dependencies. Of course I would not want to rewrite a 2M+ LOC library with very complex code, but left pad is not one of those use cases.
city41大约 9 年前
I&#x27;d just like to point out that React does not have a dependency on left-pad. React has no dependencies at all[0]. devDependencies have no impact on third party consumers.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;facebook&#x2F;react&#x2F;blob&#x2F;master&#x2F;package.json" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;facebook&#x2F;react&#x2F;blob&#x2F;master&#x2F;package.json</a>
romualdr大约 9 年前
The author missed the point about modularity in Javascript.<p>Small packages done right, well tested = maintenable, reusable, stable code.<p>The problem does NOT comes from packages. The problem comes from un-publishing public packages and centralized repository server.<p>I have a java project with a lot of dependencies. Does it mean it&#x27;s bad ? No, but if maven repos are closing tomorrow, my project will not build as well.
gitaarik大约 9 年前
Why was it removed anyway? I agree that the ability to unpublish something is the real problem, but I wonder why the author actually unpublished it. I wonder if the author knew about all the projects that depend(ed) on it. Maybe he&#x2F;she actually did it as an evil experiment, though a very interesting and eye-opening experiment. Does anyone know?
评论 #11357192 未加载
robodale大约 9 年前
I&#x27;m content and happy not knowing what the fuck this is all about. Pad left? Are you kidding me? If your tower og babel fell because of your reliance on some script kiddie&#x27;s toy project, I am happy and content knowing you get what you deserve. Law of leaky abstractions, motherfucker. Spolsky...do you read it?
j-diaz大约 9 年前
Maybe some people just want to claim they have a published module. Making them feel some sort of achievement or glory.
评论 #11352381 未加载
jwongbeee大约 9 年前
Look at these left pads...<p><a href="https:&#x2F;&#x2F;github.com&#x2F;search?utf8=%E2%9C%93&amp;q=left+pad" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;search?utf8=%E2%9C%93&amp;q=left+pad</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;nameoverflow&#x2F;left-pads" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;nameoverflow&#x2F;left-pads</a>
salehd大约 9 年前
Well it has always been like this. In early 2000s most developers I knew would simply copy-paste code from all over the Internet.<p>Nowadays you use NPM search instead of Google search<p>The fact is that lazy programmers are lazy. The methods change but the principle remains the same. In 90s people typed in code from magazines and books.
dustingetz大约 9 年前
If the code is open source, what difference does it make if the code is in my module or someone else&#x27;s?
progrocks9大约 9 年前
I just removed the tilde and caret of all my dependencies (in my package.json) and maybe that&#x27;s the way to go. Seal a local version of your packages and don&#x27;t update unless is completely needed. But I&#x27;m still worried about the fragility of the package environment.
jmount大约 9 年前
For more fun, my commentary on leftpad code: <a href="http:&#x2F;&#x2F;www.win-vector.com&#x2F;blog&#x2F;2016&#x2F;03&#x2F;more-on-npm-leftpad&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.win-vector.com&#x2F;blog&#x2F;2016&#x2F;03&#x2F;more-on-npm-leftpad&#x2F;</a>
thkim大约 9 年前
The core issue here is that there is no included standard package in Javascript. It happened because Javascript did not have authoritative implementation when it first began. Next ECMA should require to pack some batteries in to avoid this micro-module hell.
spullara大约 9 年前
It seems to me that the JavaScript VMs should get together and start including standard library. That would also give the benefit that those would be highly optimized. They can keep it small at first and focus on number and string manipulation.
return0大约 9 年前
Packaging is the new programming.
jasonbelmonti大约 9 年前
Clearly this is insane - but what the solution?<p>Part of the problem, in my opinion, is that packages are not subject to any review process. These dependency chains get out of hand because they are rarely top-of-mind.
plugnburn大约 9 年前
By the way, ES6 syntax (works in modern foxes and chromes):<p>leftpad = (str, len, pd = &#x27; &#x27;) =&gt; Array(len &gt; str.length ? 1+len-str.length : 0).join(pd) + str<p>WTF are you talking about? <i>Making this into a module?!</i>
jammycakes大约 9 年前
Here&#x27;s a quick rule of thumb. If it&#x27;s the kind of function you would ask a candidate to write at the start of a job interview, you shouldn&#x27;t be importing a separate module to do it.
评论 #11352424 未加载
digitalpacman大约 9 年前
.... isn&#x27;t this a problem with node, and not developers? Wouldn&#x27;t you say this is a symptom of a systemic problem of the framework that it is lacking common features that everyone needs?
spajus大约 9 年前
That&#x27;s what you get when you let JavaScript into the server side.
z3t4大约 9 年前
<p><pre><code> function foo(arr) { var str = &quot;&quot;; var leftpad = require(&quot;leftpad&quot;); for(var i=0; i&lt;arr.length; i++) str += leftpad(arr[i]); return str; }</code></pre>
ajuc大约 9 年前
What&#x27;s wrong with reusing small fragments of code?<p>The usual complains about many dependencies are mostly void (it&#x27;s not bloat if you only depend on single functions you actually use).
IvanK_net大约 9 年前
When am I developing some large project for a long time, sometimes I find, that I have reimplemented the same function at several places (few years between implementations).
TickleSteve大约 9 年前
&quot;Small modules are easy to reason about&quot;<p>No... &quot;<i>appropriately sized</i> modules are easy to reason about&quot;<p>In this case... &quot;Appropriate&quot; has gone out of the window!
po1nter大约 9 年前
Everyone keeps mentioning the lack of a standard library for JavaScript as an excuse for this shit show. IMO this is just a futile attempt to mask incompetence.
评论 #11356387 未加载
polynomial大约 9 年前
What actually happens when you try to update a required package, but it is gone from upstream? Is there no way to keep the existing package you already have?
benedictchen大约 9 年前
I find it interesting that blaming code reuse is a valid thing, but blaming a lack of test coverage and CI build testing is not.<p>The problem is the lack of a test culture.
sordina大约 9 年前
Check out the work on Morte for a more reasoned approach for how to take micro-modularization to it&#x27;s natural (or insane) conclusion.
plugnburn大约 9 年前
So sad yet so true.<p>We haven&#x27;t. React developers probably have.
qaq大约 9 年前
It&#x27;s up to you how to go about it on server side you for example can go with express or hapi (minimal external dependencies).
losvedir大约 9 年前
There&#x27;s nuance to the discussion that both sides are missing. People argue forcefully whether these small modules are good or bad, but I&#x27;m not seeing much evidence that they understand the other side.<p>First: why small modules are bad. Lots of dependencies complicate your build, and you end up with the dreaded diamond dependency issue. Failures in a dependency become more likely to affect you. It gets you in the habit of using prebuilt modules even if maybe it&#x27;s not quite what you need and it would have been better to write yourself. With `npm` specifically, we&#x27;ve seen how its mutability can break the build, though that&#x27;s about `npm` and not the idea necessarily.<p>I think most software developers&#x27; gut responses are that something is wrong and crazy in the npm ecosystem.<p>That said, there are benefits that this blog post and others aren&#x27;t mentioning, related to the javascript situation specifically.<p>The first one is that javascript is a surprisingly difficult language to get <i>right</i>. Sure, the final solution is only a few lines, but <i>which</i> lines are hard. You have to navigate the mindfield that are is V8 in nodejs, v8 in chrome, spidermonkey, chakra, etc. I&#x27;ve had code work in Chrome before but blow up in IE, and it&#x27;s really hard to track down and test.<p>The comments in the blog post are illustrative:<p>One line of code package:<p><pre><code> return toString.call(arr) == &#x27;[object Array]&#x27;; </code></pre> Crazy right? And my first stab probably wouldn&#x27;t have been to implement it that way. Why not:<p><pre><code> (testvar.constructor === Array) </code></pre> that a commenter suggested, which should be faster? Well another commenter said:<p><pre><code> The constructor comparison will fail if the array comes from a different context (window). </code></pre> I&#x27;ve run into issues before with cross-browser compatibility stuff, and it&#x27;s frustrating and hard to test. If there&#x27;s some de facto standard package that implements it for you, hopefully the community can iron out edge cases.<p>The other thing that people don&#x27;t bring up, is that there&#x27;s not much JS standard library, and in the browser context you have to send all your code to the front end.<p>So maybe you write these 11 lines yourself, and then another package writes these 11 lines, and another... it adds up. But if everyone uses the same package, the code only gets sent once and they all share it.<p>Lastly, people talk about how `sin` should be a part of a &quot;trigonometry&quot; package and not by itself. Well, again you&#x27;re faced with sending a bunch of unnecessary code to the frontend. With webpack2 and tree shaking, or e.g. Google&#x27;s Closure compiler, it can strip out dead code and so this issue will go away in the future, but we&#x27;re not quite there yet. So package authors still bundle all these things separately.<p>So pros and cons.
bliti大约 9 年前
It suddenly feels like the 90s all over again.
评论 #11352116 未加载
lifeisstillgood大约 9 年前
Surely there is a need to standardise on a set of well-maintained &quot;batteries included&quot; packages.
评论 #11352302 未加载
niklabh大约 9 年前
npm had the solution one year ago (namespacing) <a href="https:&#x2F;&#x2F;docs.npmjs.com&#x2F;getting-started&#x2F;scoped-packages" rel="nofollow">https:&#x2F;&#x2F;docs.npmjs.com&#x2F;getting-started&#x2F;scoped-packages</a> if only developer can embrace the &quot;change&quot;
collinmanderson大约 9 年前
I&#x27;m generally not a big fan of IPFS, but IPFS seems like the perfect solution to this problem.
Nr47大约 9 年前
when you go out for food or order in, do you ask yourself &quot;have I forgotten how to cook?&quot;<p>Sure in some ways NPM has packages that don&#x27;t deserve the title of a package, but isn&#x27;t the convenience of not having to reinvent every code worth it?
grav大约 9 年前
Isn&#x27;t the problem that there is a lack of a good standard library in Javascript?
z3t4大约 9 年前
This is why one guy can now compete with say Google or Microsoft, because that guy uses code written and managed by more engineers then both Google and Microsoft have combined. Instead of paying hundreds of dollars to said companies, you can just NPM install &quot;what you need&quot;.
评论 #11351454 未加载
sorpaas大约 9 年前
IMHO, this is all due to lack of a standard library in the Javascript world.
memracom大约 9 年前
Seems that we need a tool to crawl all the repos that a developer owns and report lines of code in each package that they wrote. If there are lots of small packages, then this is not the kind of person you want to hire, except maybe to do PR.<p>Real developers do not do stuff like this.
MattHeard大约 9 年前
&gt; Even if correct, is it the most optimal solution possible?<p>&quot;most optimal&quot;?
forgotmypassw大约 9 年前
JavaScript was a mistake.
vdnkh大约 9 年前
I don&#x27;t have an issue with modules or the Unix philosophy, I have an issue with using NPM for all these tiny modules. Hint: you can make your own modules, store them within the project, and add them to your package.json to be required anywhere.
zongitsrinzler大约 9 年前
It&#x27;s not about programming, it&#x27;s about fast progression.
danielrhodes大约 9 年前
It does seem pretty insane, but how many of these are polyfills?
justin_vanw大约 9 年前
Forgotten? Most people who develop on Node.js never knew...
democracy大约 9 年前
Re-usability is a good concept but can be overused easily.
anonymousguy大约 9 年前
This is acceptable because web developers expect a certain level of coddling. Many developers are quick to defend this insanity because they simply cannot see their own level of entitlement.
ankurdhama大约 9 年前
What&#x27;s next? A hello-world package and Node tutorial about hello world program being include this package as dependency and call the exported function.
tonetheman大约 9 年前
All the comments here have answered the question quite well. Yes we have forgotten how to program and we want to argue about it.
frozenport大约 9 年前
I don&#x27;t see nobody criticizing &#x27;std::min()&#x27;. Perhaps what we really need is a &#x27;std&#x27; for js?
评论 #11352162 未加载
fiatjaf大约 9 年前
No saner alternative presented.
facepalm大约 9 年前
What I don&#x27;t get about Left-Pad, shouldn&#x27;t they have used Arrays.join for better perormance?
评论 #11351867 未加载
shitgoose大约 9 年前
here is one of the comments to original post:<p>&quot;Immutability at the centralized authority level and more decentralization of package distribution is the solution, not &#x27;write more functions yourself&#x27;.&quot;<p>what the fuck does that mean?? they just don&#x27;t give up, do they... Fucking retards.
dschiptsov大约 9 年前
I remember how I have been downvoted to oblivion for comparing JavaScript madness with Java EE &quot;packer&#x27;s&quot; paradise years ago.<p>The Programmer&#x27;s Stone first essay is actual as it never been before.<p>Actually, it is a common pattern. When some activity becomes popular due to very low barrier to enter it will end up in a such kind of mess. It seems like nowadays everyone is either a programmer or a scientist and researcher.<p>This is the quality of their software and research.<p>There has been a reason why good schools taught <i>principles</i> (algorithms and data structures) not particulars (objects and classes). But since MIT and Berkeley dropped Scheme-based courses in favor of &quot;pragmatic&quot; Python (thank god not JavaScript) based courses we are heading to a disaster. Java madness taught us nothing.<p>History is full of examples where assault by mediocrity ruined the whole branches of philosophy, arts and crafts. Instead we have fastfood, mass media, social media and now this <i>mass coding</i>, which combines worst from mass and social.<p>Just try to compare things like Smalltalk or Plan9 or R4RS Scheme or Zeta LISP of Symbolics or with this stuff.
dschiptsov大约 9 年前
This is, finally, the &quot;Fractal Of Bad Design&quot; moment for JavaScript.
评论 #11351512 未加载
smokeyj大约 9 年前
What&#x27;s with these kids and their &quot;calculators&quot;. Back in my day we used a slide rule and we liked it!<p>But seriously this is stupid. Programming shouldn&#x27;t be the goal. Just because you can write a function doesn&#x27;t mean you should. Every line of code you write is overhead that must be tested and maintained. I guarantee that if the author chose to hand roll code instead of using packages he&#x27;d have a lot more bugs. But he wouldn&#x27;t know that until he hit some mundane edge case scenario in production.
评论 #11351525 未加载
smegel大约 9 年前
&gt; What concerns me here is that so many packages took on a dependency for a simple left padding string function, rather than taking 2 minutes to write such a basic function themselves.<p>Wait -- code reuse is bad now??
评论 #11350189 未加载
venomsnake大约 9 年前
<p><pre><code> module.exports = leftpad; function leftpad (str, len, ch) { str = String(str); var i = -1; if (!ch &amp;&amp; ch !== 0) ch = &#x27; &#x27;; len = len - str.length; while (++i &lt; len) { str = ch + str; } return str; } </code></pre> Isn&#x27;t that the least efficient way to do that function? Prepending a string has always been very expensive operation.<p>Calculating needed length. Using repeat and just concatenating 2 strings would be faster.
评论 #11351515 未加载
serge2k大约 9 年前
&gt; if you cannot write a left-pad, is-positive-integer, or isArray function in 5 minutes flat (including the time you spend Googling), then you don’t actually know how to code.<p>I&#x27;d probably get 2 of those wrong in some weird way, but I blame javascript. I mean without Google of course.
lintiwen大约 9 年前
I see two kinds of programmers here.<p>Good programmers understand the risks of making your system depend on something you don&#x27;t have control really well; They know how keeping system complexity low is like an good investment which makes your life later easier (low maintaining costs).<p>Bad programmers stacks up technical debts such as including unnecessary dependencies until the system no longer works.
评论 #11350036 未加载
评论 #11350197 未加载
irascible大约 9 年前
Ahh job security :D
irascible大约 9 年前
Ahhh job security :D
jsprogrammer大约 9 年前
This post is too dismissive and confuses some topics.<p>&quot;Packages&quot;, &quot;modules&quot;, &quot;functions&quot;, and other words can mean different things within different contexts. Well-known and tested functions <i>are</i> useful. Putting them in a &quot;package&quot; is just a consequence of how node&#x2F;npm work. There should certainly be a much, much better implementation of code sharing, but sharing and using well-known, singular functions should be <i>exactly</i> what we are going for.
CodeOtter大约 9 年前
npm install goldmansachs
c3t0大约 9 年前
<i>Functions Are Not Packages</i><p>Cracked me up :D
tn13大约 9 年前
I don&#x27;t think it is bad at all. For a lot of project where saving even a minute matters.
tiglionabbit大约 9 年前
This is just more evidence that the unit of code is a function, not a module.<p>Eventually, given a pure enough language, every &quot;package&quot; could contain only a single function, and every function in a project could be published as an independently reusable unit.
评论 #11349012 未加载