Live data from Hacker News

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

haneycodes.net

551–560 of 887 posts

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

#551
post #306

Earlier quoted context omitted.

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 cus…

It sounds like your problem with C/C++ tooling is that it's hard to support Windows. The reason for that is simply that microsoft bundles its own proprietary C++ toolchain with the platform-specific tools that Windows developers need. Windows developers don't want to install a second posix-like toolchain, and os x/bsd/linux developers don't want to install a Windows-like toolchain because in both cases the new toolch…

> It sounds like your problem with C/C++ tooling is that it's hard to support Windows

No, the problem is that there is no standardized way to deal with modules and libraries in C and C++. If it would be in the standard the cross-plattform support would be much better.

> the unix-like simplicity of the python and C (and perl?) toolchains.

For small C projects the make/autotools system might be "simple", but for larger projects? It is horrible.

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

#552
post #509

Earlier quoted context omitted.

author of over 600 modules and 1200 lines of javascript.

Wow, you were not kidding. I chose a random package of his [1], and indeed: a grand total of 1 LOC... This is madness. [1] https://github.com/sindresorhus/float-equal/blob/master/inde...

and it uses another 1LOC package. https://github.com/sindresorhus/number-epsilon/blob/master/i...

and no, the edge cases argument does not apply to either of them. Wow.

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

#553
I agree that some packages might be too much but I don't think `left-pad` is one of them.

I wrote my own left-pad for a project I'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.

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

#554

Earlier quoted context omitted.

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…

Two points: - Breaking out is-positive-integer hasn't reduced the number of paths to test. You have not gained anything, you've added overhead. - 100% test coverage is rarely a good thing. It is required for safety critical areas like avionics. I can guarantee that your JS code is not making into any safety critical environment!

> 100% test coverage is rarely a good thing

Do you mean rarely useful, or actively harmful?

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

#555

Going down the "lots of tiny modules" route is about these three things: a) No standard lib in JS b) JS is delivered over the internet to web pages in a time sensitive manner ... so we don't want to bundle huge "do everything" libs. Sometimes its convenient to just grab a tiny module that does one thing well. There isn't the same restriction on any other platform c) Npm makes it really easy to publish/consume modules…

I think b) is true only because JavaScript tooling cannot perform dead code elimination. Other languages have big grab-bag utility libraries like lodash that don't hinder performance because a linker or runtime can avoid loading unused portions.

Webpack 2 will support this: http://www.2ality.com/2015/12/webpack-tree-shaking.html

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

#556
post #420

Earlier quoted context omitted.

Perhaps another reason for this is that Javascript is inherently unsafe. By relying on these small rigorously tested libraries they are avoiding the need to test their own code, and thus avoiding basic null check or conversion errors. Other languages handle this with compilers, may be strongly typed, and/or have features that don't allow nulls. Javascript doesn't exactly have that luxury. So maybe it makes sense in J…

The equivalent in C would then be replacing #include and "-lm" with #include #include #include #include … and "-lsin -lcos -ltan -lsinh …" Which is nuts no matter what language you are coding in.

You can get approximate feeling if you get rid of a library and don't use -lm but instead unpack it to separate .o files and link against each.

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

#557
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'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.

Making this about is-positive-integer misses the point that this is a social/political problem not a technical one. A language ecosystem must address concerns of business continuity as first class concerns.

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

#559

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.

V8 internally uses cons-style strings for these operations, and only flattens the string when necessary for other operations.
Post reply on HN