Live data from Hacker News

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

haneycodes.net

161–170 of 887 posts

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

#162
post #9

Nearly everyone has had it drilled into them the "Don't reinvent the wheel." nonsense for better or worse. I use lodash in almost every javascript project I start, big or small because it makes my life easier. I'd rather use the lodash isArray than roll my own. https://lodash.com/docs#isArray

Do you support IE 8? If not, why not use the one provided by the language, Array.isArray() ?

The latest version of lodash (4.0.0) doesn't support IE 8, so you would need to polyfill isArray() yourself or use a pre-modern lodash version.

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

#163

Earlier quoted context omitted.

So many people use lodash as a drop-in standard addon library that I'm surprised people aren't just using the padding functions that are right in there... Some of the packages that broke yesterday even have lodash included as dependencies already!

Looking at the changelog, there have been more than 70 versions of Lodash in less than four years. The first was in April 2012. [1] _.padleft does not exist. It was added as part of version 3.0.0 January 26, last year and renamed to _.padstart in Version 4.0 on January 12, this year. So in less than a year "padleft" came and went away because all strings don't start on the left and someone decided that "left" means "…

Yes, I found a number of the stylistic changes made in Lodash 4.0 made it more complicated to upgrade than needed.

Dropping the this param with no period of deprecation? Pretty breaking change to make with no warning. Renaming first/rest to head/tail? Was it really worth it? Particularly when they go the opposite direction of replacing traditional functional names with more explanatory names by removing the foldr alias for reduceRight.

All this in a language that doesn't make it easy to do automated refactoring means that you basically break everything upgrading to Lodash 4.0 so you can't refactor parts to the newer style piece by piece.

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

#165
post #28

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. Small modules are not evidence of a problem, and they certainly aren't evidence of an inability to implement these things on the part of the people depending on them. Why would I implemen…

> Why would I implement left-pad myself when there is already a well-tested implementation that I can install? You call 4 basic assertions "well-tested"? https://github.com/azer/left-pad/blob/master/test.js

What if it was well-tested?

What if it was well-typed?

What if it was awesomely documented?

Would that be ok? I'm asking, because a lot of the discussion in this post comes a single simple function being a dependency.

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

#167
post #117

Have we forgotten how to program? Maybe we've forgotten how to /just/ program. Everyone bangs the drum so hard of "let github be your resume." Incentivizing putting every brain fart you ever had out into the universe instead of just keeping it to yourself. Just a thought.

The problem is not that we forgot how to program, the problem is that we never actually learned how to create a good programming language which avoids these problems.

Just look at the whole build system and module hell of C and C++...

I totally like the language C++ but I hate the tooling around it with a passion. As long as you only need stuff from stdlib then you are fine, but as soon as you want to create some custom library for use in your other projects? Which should compile on Linux and Windows? Either you use make and Visual Studio solutions or you have to fight with cmake... Just thinking about it makes me angry.

For this reason I just don't use C++ very often. It is way easier to just use Python because most stuff is just an 'import library' away and you can concentrate on your actual program instead of fighting against the build system.

But god forbid you actually try to ship your Python program to your customers...

Why do I as a programmer have to deal with all this crap? I want to focus on programming and not on library management amd writing make files. My CPU is idle 95% of the time so there is enough processing power which could solve these problems.

I have high hopes for Rust and it's integrated build/module system!

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

#168
post #26
post #7

Holy moly-- is-positive-integer/index.js: var passAll = require('101/pass-all') var isPositive = require('is-positive') var isInteger = require('is-integer') module.exports = passAll(isPositive, isInteger) I retract my previous statements that Javascript programmers are going down the same enterprise-y mess that Java programmers went down a decade ago. They've already taken it to an entirely different level of insani…

I think this is some sort of cargo cult UNIX minimalism - do one thing and one thing only.

require the ultimate

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

#169
So, I suppose you could do something like this instead.

    function leftPad(str, width, pad = ' ') {
      const actualWidth = Math.max(str.length, width);
      return `${pad[0].repeat(actualWidth - str.length)}${str}`;
    }
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't do any type-checking of course.

It also doesn'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's also a trick where you can say (new Array(desiredLength + 1)).join(' ') to make a string that is the appropriate length, but you've got OBOEs to worry about if you'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.

Javascript has all kinds of weird corner cases and lots of browser compatibility problems. The fact that someone's written a decent implementation of something that should have been standard in the String object means I don't have to worry about it.

Of course, I do 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's issues.

But if your take-away from this whole problem is "meh, javascript devs are lazy", you're missing the point.

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

#170
post #69

In the case of left-pad, 2538464 of its 2550569 downloads last month are attributed to dependents of the line-numbers package ( https://www.npmjs.com/package/line-numbers ). So it would appear that relatively few people directly rely on left-pad, which highlights the importance of vetting the dependencies of dependencies.

This is in the description of line-numbers: DEPRECATED. This is a rather silly package that I do not recommend using. It's easier to copy the ~20 lines of code of this package and customize that code, rather than downloading and learning how to use this package.

Committed five hours ago: https://github.com/lydell/line-numbers/commit/711f6ad0eb1771...

This mess appears to have convinced the author of that.

Post reply on HN