Earlier quoted context omitted.
> basic null check What's funny to me is that leftpad(null, 6, ' ') outputs " null".
Am I right that len(" null") here is 5, so it's working incorreclly?
NPM and Left-Pad: Have We Forgotten How to Program?
521–530 of 887 posts
Re: NPM and Left-Pad: Have We Forgotten How to Program?
#522Holy 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…
This comes up a lot when people discuss anything related to npm modules. It's easy to simply dismiss these trivial one-line modules as "insanity" and move on, but there's actually plenty of good reasons as to why many prefer to work with multiple small modules in this manner. This GitHub comment by Sindre Sorhus (author of over 600 modules on npm) is my favorite writeup on the topic: https://github.com/sindresorhus/a…
Re: NPM and Left-Pad: Have We Forgotten How to Program?
#523Earlier quoted context omitted.
Worse yet, the OS is compromised. This is why I hand roll all my encryption libraries. /s
Riiiight. Because cryptography is identical to an 12-line string padding function.
Re: NPM and Left-Pad: Have We Forgotten How to Program?
#524I 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. Write your own goddamn utility classes, people. Or learn how to suspend package releases, include them in your projects, and smoke test your releases.
Re: NPM and Left-Pad: Have We Forgotten How to Program?
#525 module.exports = leftpad;
function leftpad (str, len, ch) {
str = String(str);
var i = -1;
if (!ch && ch !== 0) ch = ' ';
len = len - str.length;
while (++i
Isn't that the least efficient way to do that function? Prepending a string has always been very expensive operation.Calculating needed length. Using repeat and just concatenating 2 strings would be faster.
Re: NPM and Left-Pad: Have We Forgotten How to Program?
#526Everything 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…
"Sometimes, the elegant implementation is just a function. Not a method. Not a class. Not a framework. Just a function." --John Carmack
Re: NPM and Left-Pad: Have We Forgotten How to Program?
#527Earlier quoted context omitted.
Small modules are easy to reason about They really aren't, when I'm reading is-positive-integer(x) and wonder if 0 is positive I need to hunt down the definition of positive through two packages and as many files. And it gets wrose if both your code and one of your dependencies required 'is-positive-integer' and I have to also figure out which version each part of the code base is using. If you had written (x > 0) I…
JS does not have an Integer type, so (x > 0) does not work. Now if you add all those checks necessary to see whether you're actually dealing with an integer here, you get to a point where you cannot be sure anymore whether there aren't any weird type coercion issues there and need to start writing tests. Suddenly your whole positive integer check took 1h to write and you still cannot be sure whether there's something…
JS does not have an Integer type, so (x > 0) does not work
It depends on what the surrounding code actually does wheter (x > 0) works or not. Depending on the version of is-positive-integer you are using a positive instance of the class Number may return true, false or cause an error.PS. never mind that the implementation of is-positive-integer is extremely inefficient.
Re: NPM and Left-Pad: Have We Forgotten How to Program?
#528Re: NPM and Left-Pad: Have We Forgotten How to Program?
#529Holy 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…
Author of "is-positive-integer" here. I will admit the implementation is pretty funny, but I move-out all single-purpose utils out of projects to modules for a bunch of reasons. DRY is the most obvious one, but one that may be less obvious is for better testing. I move out modules so I can write really nice tests for the independent of the projects I am using them in. Also, I tend to write projects w/ 100% test cover…
Re: NPM and Left-Pad: Have We Forgotten How to Program?
#530 function foo(arr) {
var str = "";
var leftpad = require("leftpad");
for(var i=0; i