News for hackers. Stuff that matters.
Re:Yarn – A new package manager for JavaScript by bandrami on Tuesday October 11, 2016 @12:53PM (#12686134)
This may come off as a troll, but it's an honest question. I'm not a javascript guy. It's not a language I deal with at all. Why on God's green earth does it need as much tooling as it seems to have? Are people really making projects with dozens (hundreds? more?) of dependent libraries? Are there aspects of the language or runtime that reward multiple layers of configuration management? In short, what the hell is up with this ecosystem?
Re:Yarn – A new package manager for JavaScript by mambodog on Tuesday October 11, 2016 @01:13PM (#12686328)
Basically I think it comes down to:

1. In the browser we have less control over the environment the code runs in, requiring tooling to achieve a stable, normalised environment which we can improve at our own pace, rather than the rate at which browsers are updated.

2. JS has become very widely used very quickly, which means that there have been lots of hastily built things, which have been replaced by better things (and for every 'better thing' there are many alternatives which fell by the wayside), and a larger pool of people to build them.

3. It's easier than ever to build new tools (or any kind of app, for that matter), because the npm ecosystem makes it trivial to combine existing smaller pieces of code into new combinations.

Re:Yarn – A new package manager for JavaScript by Klathmon on Tuesday October 11, 2016 @01:27PM (#12686471)
Your number 3 is the one that really drives it home for me. It's the unix philosophy taken to the extreme, and (at least in my experience) it's working very well.

It does take some getting used to, but when you stop looking for one big tool that can solve 5 semi-related problems, and start looking for 5 little tools that each solve one of the problems, things get much more clear.

And yes, I know that this kind of reliance on dependencies can cause issues, but from my experience, those issues don't seem to bite that often, and many of them can be resolved with even more tooling.

Re:Yarn – A new package manager for JavaScript by swang on Tuesday October 11, 2016 @01:34PM (#12686545)
browser incompatibility is the biggest issue (if not the only issue). this is almost a non-issue if you're just writing node related programs. but if you need to support in the browser, now you have edge, chrome, firefox, and safari at minimum. then some have to continue supporting ie10/ie11, or even worse, ie7+.

don't forget about mobile devices, with ios having such a difficult-to-write-anything-new version of mobile safari.

i'm writing a new app for myself, so i don't have to worry about any backwards compatibility issues, except it needs to work on my iphone, which uses mobile safari webviews, which means i have to either use shims or restrict myself back to es5, non-html5 features (or work around their html5 limitations).

example: you cannot cache audio files to play using <audio> tags in mobile safari. safari just refetches it from your server (also has to recreate the audio object, which causes a lag in the audio being played). technically you _can_ cache if you convert all your audio files to base64 and use the webaudio api. i'm probably going to have to go this route because i'd like the app to be offline usable.

so rather than spend time on my app, i now have to write out a build step for converting audio to base64. then test that it works fine in ios and desktop browsers (at least chrome, firefox). it all just keeps adding up.

Re:Yarn – A new package manager for JavaScript by ubercore on Tuesday October 11, 2016 @01:08PM (#12686277)
I came to the Javascript world late, starting with React. I think its tooling has gotten out of hand, but there are a couple of reasons it's not a _total_ disaster in my mind:

* Partly, there are a larger number of Javascript developers that haven't been exposed to other ecosystems, and end up reinventing some wheels

* More importantly though, I think the pace of innovation in the javascript ecosystem is actually good in a way, because other more mature languages (I'm not talking about age of the language, just maturity of the tooling and ecosystem) have gone through the same growing pains, it just took a lot longer. It's easy to forget, coming from the Python world for instance, the pains of easy_install and distutils vs seuptools, etc etc. I still find Java dependency management a bit of a pain, because I don't know it very well.

We're just watching a sped up version of a language maturing, and it's painful as individual developers trying to keep up, but I don't think it's as negative as HN often makes it.

Re:Yarn – A new package manager for JavaScript by grayrest on Tuesday October 11, 2016 @01:47PM (#12686694)
> Are people really making projects with dozens (hundreds? more?) of dependent libraries?

Yes.

> Are there aspects of the language or runtime that reward multiple layers of configuration management?

A significant fraction of the node community likes to split their project into really, really small packages and treat them as if they're independent even if they come from the same source repo and tend to get used together. As an example, the popular collection processing library Lodash publishes a package for each method and people actually do depend on individual methods.

There are two major rationales for this. The first is that JS is a dynamic language and in dynamic languages, smaller chunks of code are easier to reason about than larger ones. The second is that the JS community as a whole cares more about artifact size than pretty much any other community. Having smaller packages allows you to produce a smaller payload without having to rely on techniques like tree shaking.

I find micro packages maddening but people give me their code for free and it mostly works so I don't complain about it that much.

Re:Yarn – A new package manager for JavaScript by erikpukinskis on Tuesday October 11, 2016 @02:28PM (#12687158)
What do you find maddening about micro packages? I hate depending on a giant stack of frameworks (slowing installs, builds, adding behavior surface area) when I just need a function or two, so micro packages are a joy for me.
Re:Yarn – A new package manager for JavaScript by tigershark on Tuesday October 11, 2016 @03:34PM (#12687773)
Reading the article it seems to me that this micro packages approach is what slows down everything. I never, ever have seen all these problems in even not-so-state-of-the-art dependency managers like maven or nuget. Seriously up to now it was impossible to have a build server isolated from the internet if you didn't want to check-in all the dependencies??? Simply crazy. I really can't understand how people can even think to use a dependency manager system that doesn't satisfy the essential requirement of having your CI server sandboxed.
Re:Yarn – A new package manager for JavaScript by Lazare on Tuesday October 11, 2016 @07:35PM (#12689378)
> this micro packages approach is what slows down everything

Not really. The npm client is just flaky, very slow, buggy, has some major design flaws in its v2 incarnation, and has a completely different set of major design flaws in its v3 incarnation.

The core architecture works fine for small packages.

> Seriously up to now it was impossible to have a build server isolated from the internet if you didn't want to check-in all the dependencies

Of course not, although I admit the linked article implied it was if you didn't read closely. There's a wide number of solutions, including running a private registry, or a copy of the public registry, or a local cacheing proxy of the public repository, or a custom npm client that hits a local cache, etc. Some of the solutions work quite well, and in fact yarn itself is just a re-implementation of some existing solutions.

> I really can't understand how people can even think to use a dependency manager system that doesn't satisfy the essential requirement of having your CI server sandboxed.

As the article noted, Facebook was sandboxing their CI server and using NPM; they just didn't like the existing solutions. (Nor should they; they were a bit naff.) But that doesn't mean (nor is anyone claiming) that there were no existing solutions. Yarn looks great, but it's an extremely incremental change.

Re:Yarn – A new package manager for JavaScript by erikpukinskis on Saturday October 15, 2016 @10:36PM (#12716588)
Javascript is very easy to work with if you just stick to micro packages. What slows it down is that the language has been forked to an incompatible spec (ES6) so there is essentially a hard fork in pool of libraries. To deal with this—and calm anxieties around lack of inheritance, trauma over having to type function over and over, etc—layers of pre-processing have been added: JSX, SASS, asset compilation, compatibility layers, framework booting. This pipeline distances developers from the DOM and other low-level protocols, increases the surface area of the build process, and frequently disables debugging and introspection tools. In addition megaframeworks like Angular, Ember, and React add mandatory layers of indirection and runtime dependencies between each snippet of code, introducing behavioral complexity and confusion from non-deterministic builds.

All of this is why people are excited about Yarn, but to me it's a band-aid on several architectural mistakes.

Just say no to frameworks. Just say no to ES6 and transcompilation. Just say no to asset pipelines. Viva la JavaScript. Viva la Netscape. Viva la Node.

Re:Yarn – A new package manager for JavaScript by happyslobro on Tuesday October 11, 2016 @04:08PM (#12688078)
Where would a CI server retrieve dependencies from, if not either over the network, or from within the repository? Do you keep a module / library cache on the CI server itself? In other words, what do supply as input to your CI process, besides a Git URL?
Re:Yarn – A new package manager for JavaScript by tigershark on Tuesday October 11, 2016 @04:28PM (#12688234)
In a local nexus/nuget repository in the intranet, for sure I'm not allowing internet access directly from a CI server. And apart from the obvious and scary security concerns it is also much faster.
Re:Yarn – A new package manager for JavaScript by happyslobro on Tuesday October 11, 2016 @04:39PM (#12688338)
Got it. You can also set up an NPM repository like that, but I don't think that that is commonly done by small dev teams. This does lead to hilarity like the left-pad clusterfork.
Re:Yarn – A new package manager for JavaScript by joepie91_ on Tuesday October 11, 2016 @04:28PM (#12688237)
> Reading the article it seems to me that this micro packages approach is what slows down everything.

It really isn't. The NPM client is just really, really poorly written, with no parallelization to speak of.

Re:Yarn – A new package manager for JavaScript by untog on Tuesday October 11, 2016 @04:12PM (#12688110)
But a huge list of micro packages slows installs, too. It shouldn't, but NPM doesn't seem very good at parallelising operations.
Re:Yarn – A new package manager for JavaScript by pcsanwald on Tuesday October 11, 2016 @01:32PM (#12686527)
I have no idea if you're familiar with the java ecosystem, but I am, so I'll use that as an example:

Node libraries are typically several orders of magnitude smaller and more single purpose than java libraries. Java libraries like Guava and Spring are typically quite large. A practical example is from unit testing: In Java, you might use JUnit+Mockito for your test dependencies. In Node, to get similar functionality, I have the following deps: Mocha, Sinon, Sinon-As-Promised, Chai, Chai-Moment, Chai, Chai-Things, Chai-Shallow-Deep-Equal, Chai-Datetime, Sinon-Express-Mock, Supertest.

Many Javascript applications both client and server functionality, and there is different tooling for both. Webpack is currently popular for building stuff that will run in the browser, whereas server side stuff is different.

It's a much newer technology than java and there is quite a lot of churn around tooling in general as the nature of the way applications are built change.

Re:Yarn – A new package manager for JavaScript by crucialfelix on Wednesday October 12, 2016 @02:53PM (#12695542)
> It's a much newer technology than java

Strangely enough both Java and JavaScript were first released in May 1995. Server side JavaScript was released the same year just after the browser version.

Though I get that you are referring to the js eco systems (commonjs, npm) compared to the much more mature Java ecosystem.

Re:Yarn – A new package manager for JavaScript by tigershark on Tuesday October 11, 2016 @05:20PM (#12688611)
Why is that? In the Java ecosystem there is Spock framework that gives you everything required for testing, you don't even need junit+mockito. In which scenario would be better to use 11 different libraries for doing the same thing as a well written framework?
Re:Yarn – A new package manager for JavaScript by l1ambda on Tuesday October 11, 2016 @05:43PM (#12688761)
In this case, I would argue it is not better. Many JS devs have moved onto simpler, greener pastures. https://github.com/substack/tape is what I prefer. Small little library. Its API has everything I need and nothing I don't. Those other test libraries listed are pretty much overkill.

Similar with http://mithril.js.org/ over React, Angular and Ember. A single drop-in library with 13 functions in it's API. The library itself is a single, understandable source code file. Mithril is pretty much the exact opposite of Angular and Ember.

A lot of front end devs are eschewing frameworks completely. With modern DOM and web APIs, you can do a lot with "just" vanillajs.

Re:Yarn – A new package manager for JavaScript by pcsanwald on Tuesday October 11, 2016 @06:45PM (#12689131)
But, this is exactly what I'm saying. you start with a small, focused library that contains everything you need, which is usually fairly minimal, so that library is small. but then, along the way, you find yourself wanting, so you add a library that adds support for that specific thing.

I didn't add sinon-as-promised for fun, I added it for in-memory sequelize integration tests. same for all the other libraries I mentioned.

My point is that by keeping libraries small, you will end up with either more dependencies, or a lot more hand-rolled code. Neither of these things are inherently bad or good, and I'm not defending them. What I am trying to do is explain to the commenter why the node ecosystem seems to have such an emphasis on package management and the tooling around that.

Re:Yarn – A new package manager for JavaScript by tigershark on Tuesday October 11, 2016 @06:28PM (#12689049)
From the readme I can't really see how to write extensive unit tests with that thing.. If I need to test something I want only one tool that works perfectly and does all the Stubbing, Mocking, verification, data driven test and behaviour driven test. I still haven't found in any language/ecosystem anything comparable to Spock in completeness, readability and ease of use. Honestly I can't really see how to do BDD with tape.
Re:Yarn – A new package manager for JavaScript by shados on Wednesday October 12, 2016 @12:05AM (#12690363)
its not that hard. That being said, the current all in one turnkey testing framework for javascript is Jest, and that will pretty much do it all in one tool.
Re:Yarn – A new package manager for JavaScript by rickhanlonii on Tuesday October 11, 2016 @10:14PM (#12689995)
The benefit of what's happening in JS is that a lot of libraries are reasonably compartmentalized for a specific purpose.

As an example: you _could_ have one SpockJS framework that gives you React + Redux + ReactRedux, but instead each of these libraries are separate so you can use them without each other. This allows you to, say, move from React to Angular without changing the state of your application.

With everything moving so quickly in JS, this separation turns out to be valuable enough to tolerate a lot of packages and dependencies. It also makes it easier for communities to exist for solutions to specific problems, which at least in theory results in better solutions.

It's not necessarily better, just a different approach.

Re:Yarn – A new package manager for JavaScript by tigershark on Wednesday October 12, 2016 @04:27AM (#12691201)
For testing it doesn't make any sense. I want a coherent and expressive framework that does everything. If I'm doing BDD I know that I will need everything from the start. And from the little that I have seen about jest..well it seems really a jest. I can't really think to do any serious BDD with that.
Re:Yarn – A new package manager for JavaScript by rickhanlonii on Wednesday October 12, 2016 @10:30AM (#12693161)
Even for testing I think it make sense. If you want to switch from Mocha to Jest and still use Chai for your assertions, you can.

Like I said, it's not better just different.

Re:Yarn – A new package manager for JavaScript by imtringued on Wednesday October 12, 2016 @04:45AM (#12691276)
I guess you could call it "diversification" of dependencies. If one dependency stops being maintained or is not the best approach you can jump to another one.
Re:Yarn – A new package manager for JavaScript by ed312 on Tuesday October 11, 2016 @01:00PM (#12686214)
A very limited standard library with no native (well, just approved but not ratified) support for importing/libraries. Coupled with inconsistent implementations and you end up need more layers of abstraction.
Re:Yarn – A new package manager for JavaScript by paradite on Tuesday October 11, 2016 @02:27PM (#12687136)
Let's consider Microsoft Office. It is a massive software and such as massive software requires a lot of (internal) dependencies and toolings.

Now imagine Office 365, the same software with the same functionalities, except running in the browsers. The task is to essentially write Microsoft Office (front-end logic) entirely in JavaScript (or TypeScript), with the additional problems of dealing with browser compatibilities issues, which are just as hard as OS compatibilities issues.

Then, imagine all the software going to the "cloud". JavaScript now has to have the capability of re-writing all these software originally written in C++, C#, Java... all sorts of languages. It is quickly becoming a superset of all ecosystems where everyone is trying to migrate their software to. So it is not surprising that people are inventing more and more tooling to make it more powerful to suit their needs.

Re:Yarn – A new package manager for JavaScript by fuzzy2 on Tuesday October 11, 2016 @01:34PM (#12686542)
You say tooling, but then talk about libraries. I think both are just as numerous for nearly all popular programming languages. It’s just that JavaScript is currently “hot shit”, so all this stuff is a lot more visible.

There are tons of libraries for C, many of which aim to do the same, only faster/smaller/scalable/whatever. There are many compilers, both open and closed source. And there are documentation tools, syntax checkers, unit testing frameworks and whatnot.

Of course there are also languages like C# where there’s a de-facto standard for almost everything: IDE, compiler, base library, GUI framework(s).

I think choice is great!

Re:Yarn – A new package manager for JavaScript by bandrami on Tuesday October 11, 2016 @02:20PM (#12687069)
You say tooling, but then talk about libraries.

Because, from this outsider's perspective, it seems like most of the tooling is library management (rather than, say, profiling or linting -- does javascript even have a linter? -- or debugging).

Re:Yarn – A new package manager for JavaScript by dimal on Tuesday October 11, 2016 @07:15PM (#12689278)
JSLint, JSHint, ESLint. Each of which built on the good aspects of its predecessor and evolved as new requirements came up. There are a _ton_ of tooling libraries for JavaScript. Just google "X JavaScript" for any tooling you'd expect, and you'll usually have several options. Of course, on the flip side, people will complain that there are too many options. Blah blah blah. No matter what the JS community does, people will criticize.
Re:Yarn – A new package manager for JavaScript by fuzzy2 on Tuesday October 11, 2016 @03:00PM (#12687495)
Then you haven’t seen anything yet. x)

There are tons of tools, of course also including jslint, debuggers (e.g. IntelliJ, dunno about others). There are editors and even IDEs. Then there’s the problem of bringing (NPM) modules to the browser using tools like webpack or SystemJS or whatever. There are general purpose build/automation systems like gulp. There are transpilers that “compile” ES6 to ES5. For any given task, you can probably find at least five programs that do it.

And if you look at all the topics, you’ll find that library management makes up only a small fraction of everything.

Re:Yarn – A new package manager for JavaScript by flukus on Tuesday October 11, 2016 @07:03PM (#12689223)
> does javascript even have a linter?

Yes, thousands of them, npm alone has 1200 results for linter:

https://www.npmjs.com/search?q=linter

Re:Yarn – A new package manager for JavaScript by Osiris on Tuesday October 11, 2016 @02:47PM (#12687381)
> does javascript even have a linter? -- or debugging

Yes, as libraries. There are multiple linter options that can be installed with a project. Debugging is available, usually through an IDE or browser.

Re:Yarn – A new package manager for JavaScript by Lazare on Tuesday October 11, 2016 @07:38PM (#12689389)
JS has several linters, although ESLint is the one to pick if you're looking for one.
Re:Yarn – A new package manager for JavaScript by seangrogg on Tuesday October 11, 2016 @01:40PM (#12686605)
This is a valid question coming from an outsider looking in.

There are various packages that are extremely small (see leftpad and associated controversy). They often wind up in a slightly larger package, which itself winds up in a slightly larger package, which recurs until you finally wind up with one actual package of consequence that you're targeting. For example, Express (a very common Node.js abstraction) has 26 direct dependencies, yet 41 total dependencies.

A lot of this results from early Node.js' mantra of having small, focused packages. This could potentially be a good thing because instead of having three major dependencies that have their own way of leftpadding they can all rely on one library and thus code is efficiently reused. This can be bad, however, when they each need their own version of the dependency - or worse - the dependency is removed from the registry (see Leftpad and associated controversy).

One of the legitimate problems that I've seen is that there are various libraries that are just thin wrappers over functionality that is native to Node.js - but written to be "easier to grok". Thus, these thin abstractions become practical code duplication out of some mixture of Node's developers lack of effective verbosity/documentation and application developer laziness. But then they creep higher up the dependency chain because someone at a lower level used it.

On one hand it can be quite simple (and rewarding) to write code while minimizing dependencies. On the other hand, abstractions such as Express make it very easy to write code and it feels like you only have "one dependency" until you look under the hood.

Re:Yarn – A new package manager for JavaScript by Zarel on Wednesday October 12, 2016 @09:21AM (#12692527)
41 dependencies isn't even that much.

Babel, the most popular transpiler, is 335 total dependencies, and it doesn't even do anything out-of-the-box. You need to add babel-preset-latest for 385 total dependencies if you want to actually transpile anything.

Want a linter? ESLint is 128 total dependencies.

Re:Yarn – A new package manager for JavaScript by nmgsd on Tuesday October 11, 2016 @02:17PM (#12687039)
A lot of these answers are pointing out the x-browser complexity which is true but that isn't what drives JS package mgmt. It's mostly Node stuff. The mature common JS libs for browser work are pretty robust when it comes to x-browser stuff now days.

For browser work, you can do almost everything you need with some jQuery, handlebars and moment if there are dates. A few other small libs here and there and you've got almost everything covered. Some edge cases may drive you to use some library that is heavily dependent on 32 different sub-libs but it's really not that often.

Server-side Node.js is the issue, not browser compatibility.

Re:Yarn – A new package manager for JavaScript by sotojuan on Tuesday October 11, 2016 @06:32PM (#12689066)
That's interesting because I have less JS headaches when using Node. I avoid front end JS these days
Re:Yarn – A new package manager for JavaScript by aphextron on Tuesday October 11, 2016 @04:59PM (#12688471)
>Are people really making projects with dozens (hundreds? more?) of dependent libraries?

Yes, because the standard library provides practically nothing useful in itself.

Re:Yarn – A new package manager for JavaScript by shados on Wednesday October 12, 2016 @12:03AM (#12690359)
Handling dependencies is hard. Handling dependencies for a platform you don't control is harder. Handling dependencies for a platform you don't control, where every single kilobytes count, is insane.

Add those together, and you get the need for real complex tooling.

With that said, tooling is nowhere as complex as it is for languages like C++ or Java. People are just used to it on those platforms, and the tooling is more mature/understood because it already went through the countless iterations, 15-20 years ago or more.

Re:Yarn – A new package manager for JavaScript by blub on Wednesday October 12, 2016 @02:05AM (#12690718)
The tooling for building C++ consists of make or something that generates make files. There's also no "1 function" libraries. Adding a dependency is done by (compiling it if needed) and referencing it from the make file. It's super easy to understand, but involves manual work because C++ doesn't have a package manager.

Java isn't too complicated either. I've used Gradle and Maven but doing things manually like in C++ can also work.

Crucially, they don't reinvent the wheel every couple of months so a C++ or Java dev can focus on building things instead of relearning how to build things.

Re:Yarn – A new package manager for JavaScript by kin on Tuesday October 11, 2016 @01:26PM (#12686464)
Javascript in my opinion is still very young. You can't compile it to web assembly (yet) and the fact that there are different browsers that interpret it in so many different ways make for libraries to exist to mitigate this. Also none of these tools are 100% necessary, they just make your life easier and tools always have room for improvement. I'm sure others can add to this. I don't think any of this is a bad thing, it's just overwhelming for newcomers that haven't been following this whole thing.
Re:Yarn – A new package manager for JavaScript by qudat on Tuesday October 11, 2016 @01:57PM (#12686810)
Others have touched on the subject but one of the biggest issues is browser compatibility. Building a responsive website that works on all major browsers, across multiple versions, as well as all the mobile quirks is not an easy task in the slightest ... and that's just to make a site look pretty. Then we have to start talking about building massive web apps that are front-end heavy which requires even more tooling to scale, maintain properly.
Re:Yarn – A new package manager for JavaScript by gotofritz on Friday October 14, 2016 @03:21AM (#12706572)
Because JS is open source and it's not controlled by an Oracle / Microsoft / Apple / XXX foundation. Everybody is free to do stuff - and does. In the end there aren't actually as many tools as people think, a lot of hobbyists projects who die quite quickly
Re:Yarn – A new package manager for JavaScript by odbol_ on Tuesday October 11, 2016 @01:33PM (#12686533)
Compared to C/C++ tooling and package managers, npm is like taking a bazooka to a knife fight.
Re:Yarn – A new package manager for JavaScript by wycats on Tuesday October 11, 2016 @02:17PM (#12687040)
Is npm the bazooka or C++? As someone who's worked with C/C++ (and its hilarious explosion of tooling -- half-a-dozen at Google alone), maven, bundler and Cargo, I think it's just not accurate to say that the npm ecosystem has a particularly high level of complexity.
Re:Yarn – A new package manager for JavaScript by odbol_ on Tuesday October 11, 2016 @04:57PM (#12688461)
npm is the bazooka. Covers a lot more area with a single tool, but sometimes dangerous if you use it wrong.

C/C++ tooling is a plastic butterknife you get with airplane food.

Re:Yarn – A new package manager for JavaScript by rdavl on Thursday October 13, 2016 @04:22AM (#12699279)
Some languages actually have standard libraries so don't need bazookas..
Re:Yarn – A new package manager for JavaScript by rounce on Thursday October 13, 2016 @07:02AM (#12699811)
What're you smoking? Can I have some?
Re:Yarn – A new package manager for JavaScript by fivesigma on Tuesday October 11, 2016 @01:05PM (#12686259)
Browsers are the new OSes. Everything on them runs on javascript. You do the math.
Re:Yarn – A new package manager for JavaScript by pjmlp on Tuesday October 11, 2016 @12:57PM (#12686170)
JavaScript is the new BASIC and every millennial wants to populate his/her Github portfolio for Silicon Valley interviews.
Re:Yarn – A new package manager for JavaScript by StreamBright on Wednesday October 12, 2016 @04:35AM (#12691229)
You should check out the mayhem caused by a single contributor removing his left-pad library.

http://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/