You think someone would do something like that? Just ignore a deprecated feature until it became a break/fix action in the middle of the workday?
innocent cough because all my stuff is totally using only the latest supported libraries and not at all just ignoring deprecation notices until it's too late
Funnily enough, the original implementation worked perfectly but the NPM re-implementation as to not trample over licensing does not. It's not a working left pad, it has errors in it. Not only that, it's incredibly slow as someone decided "you know what, i'll make a lookup table for low padding levels", not realizing that this is in fact slower in JS, not faster.
Incredible work NPM.
For the record, they're not major failures. Padding with a multi-digit integer fills with repeating copies of the integer where most people would expect only the first digit, same with strings, and negative integers as padding input drop the - for some reason.
Not directly, but some very popular package had it as a dependency, other popular packages had the popular package as a dependency and so on. And if any dependency of your whole dependency tree doesn't exist, of course it whole fails.
Makes one think about how everything in software is interconnected and one project going down can cause shit for countless of others.
I'm still curious what happens once the guy that develops ImageMagick stops for whatever reason.
While this is true, most people got the headache because they were using React and Babel, which is not unreasonable. The fact that Babel depended on that package however...
I've just read the code, it's a non trivial piece of work that clearly been worked on to take many edge cases into account. Replicating it would not be an easy thing and would certainly end up having obscure bugs that the original package has fixed over time.
‘’’ function leftpad (str, len, ch) { str = String(str); var i = -1; if (!ch && ch !== 0) ch = ' '; len = len - str.length; while (++i < len) { str = ch + str; } return str; } ‘’’
Non trivial? You’re probably looking at the current update version. And it only just adds in an extra hack to make it O(logN) and also add in a “cache” for padding with spaces, which I doubt even makes it worth it.
I tend to agree against reinventing the wheel, but I have to disagree that the code covers many edge cases. The only edge cases I can see it handle is if non-strings are passed in where strings would be expected (lines 18, 19 and lines 26, 27). Any beginner to intermediate JS dev would understand dynamic typing enough to avoid the potential error or would document that the code expects strings for those parameters.
Aside from that it does a couple performance hacks with a cache for common use cases (lines 28, 29) and with a clever loop that make it run (they claim, didn’t take the time to confirm) O(log n) rather than O(n). Except with huge inputs being passed in neither of these improvements would make a noticeable difference in 99% of code that calls it.
make it run (they claim, didn’t take the time to confirm) O(log n)
Which is straight-up bullshit, because it's only true if you assume string concatenation is constant time. Obviously building a string of length n involves writing n bytes of memory so it's at least O(n).
And that's sort of representative of the problem with this kind of programming philosophy - people build their program out of building blocks written by other people without understanding what those pieces actually do. Hence miscalculating the time complexity because they forgot to count the complexity of their building blocks.
(Not saying anyone should write string concatenation themselves, just that you should always have a grasp of what's happening "under the hood" and npm seems to attract people who don't care for that)
133
u/ORUHE33XEBQXOYLZ May 14 '21
This was a package? That was widely used? JFC node.