News for hackers. Stuff that matters.
Re:How I want to write Node: Stream all the things by hamburglar on Friday February 14, 2014 @01:16PM (#7240011)
This is highly intriguing, but I must ask why the JS community has this fascination with obscure identifiers like "_". It decreases readability when what should be a logically-chosen descriptive identifier for your class is replaced with a single character that visually recedes into the language syntax. Edit: I've grudgingly given jquery a pass on this because of its ubiquity, but come on, a stream library? Not to mention the fact that a reasonably popular lib already seems to have squatted on underscore.
Re:How I want to write Node: Stream all the things by wcummings on Friday February 14, 2014 @01:25PM (#7240058)
In my codebases, literally 1/10 lines or more contain at least one call to underscore.js, frequently more than one (not even including async). Its for brevity. If you wrote out underscore.* or Highland.* your code would become hard to read. These are utility functions that are used heavily.

I'm excited about this, as someone who uses underscore.js and async together, heavily.

Re:How I want to write Node: Stream all the things by hamburglar on Friday February 14, 2014 @01:30PM (#7240094)
underscore.js is a pretty good sized collection of utilities, which is why you call it a lot. I am having a hard time believing you're going to be constructing so many Highland streams that you need a one-character identifier for it to increase readability.
Re:How I want to write Node: Stream all the things by wcummings on Friday February 14, 2014 @01:33PM (#7240113)
If you look at the full docs, there is a lot of overlap, highland provides a lot of of the functions from underscore.js, and since from what I can tell its trying to unify the "javascript utility belt", I can only imagine more will be added.
Re:How I want to write Node: Stream all the things by al2o3cr on Friday February 14, 2014 @01:42PM (#7240167)
"highland provides a lot of of the functions from underscore.js"

"A lot of the functions" (versus "all of the functions") sounds like a one-way ticket to readability hell, since it means that an inattentive reader may assume the functions ARE from Underscore.

Re:How I want to write Node: Stream all the things by wcummings on Friday February 14, 2014 @02:14PM (#7240395)
To me the benefit of a convenient shorthand outweighs this, someone would figure it out really quick, seems like a non-issue. A few different libs use $ and the world doesn't end.
Re:How I want to write Node: Stream all the things by ryanatkn on Friday February 14, 2014 @01:28PM (#7240078)
JS devs rely heavily on libraries to do things that most programmers would expect the language to handle. $ and _ have been adopted as toolkit identifiers and are littered throughout most JS codebases. Highland does much of what one would expect from _ via Underscore/Lodash. I'd bet most people think they improve readability.
Re:How I want to write Node: Stream all the things by Cthulhu_ on Friday February 14, 2014 @01:47PM (#7240215)
I agree; what I personally wonder is why Underscore and similar libraries don't make use of Javascript's prototype business and add methods to the array and object prototypes? Probably things I'm overlooking here, but, [1, 2, 3].map(stuff) is much nicer than _.map([1, 2, 3], stuff) and the like.
Re:How I want to write Node: Stream all the things by jashkenas on Friday February 14, 2014 @01:55PM (#7240263)
Ha ha.

You're describing the state of affairs before Underscore existed, back when functional-ish programming in JavaScript was ruled by Prototype.js:

http://prototypejs.org/

... which added a lot of useful methods to native prototypes.

While handy in controlled and limited environments, mucking about with native prototypes quickly becomes extremely dangerous and difficult — once you have two third-party modules on the page that expect different versions of your patched prototype method ... once you have a new version of a browser that implements one of your previously-extended functions, but does it differently — you're pretty well screwed. Both of those things tended to happen in large sites.

Re:How I want to write Node: Stream all the things by hamburglar on Friday February 14, 2014 @02:07PM (#7240353)
Whereas with _.map, you always know exactly which implementation you're getting, right? :)
Re:How I want to write Node: Stream all the things by jashkenas on Friday February 14, 2014 @02:36PM (#7240529)
Actually, you do. You've loaded it, and you can lock it down privately to your library or app with _.noConflict().

You can have ten different versions of Underscore loaded on the page, living in peace and harmony, in ten different third-party modules. Not that you should. But that you could.

Re:How I want to write Node: Stream all the things by hamburglar on Friday February 14, 2014 @03:19PM (#7240758)
Well then I guess this _ has a bug because it doesn't have a 'noConflict' method. :)

But to be perfectly fair, you are 100% correct: this is not a technical complaint and perhaps this entire sub-thread is, as has been claimed, "bike-shedding." Since this lib is designed to be loaded via an AMD-style mechanism, users can call it whatever they want, so _ is just as valid an identifier as any other. Except the obvious issue that readers of the code, examples, and any code that follows suit, will end up with this completely pointless ambiguity because _ is ultimately a meaningless name if it evolves to mean simply "some library I loaded." You may as well write sample code like:

var $ = require('http'); $.createServer(...);

I would think people would call that out as ridiculous and confusing.

Re:How I want to write Node: Stream all the things by jdd on Monday February 17, 2014 @05:12PM (#7254865)
Extending native prototypes creates other less obvious hurdles for libraries too. Craft.js, es5-shim, Modernizr, MooTools, Prototype.js, and Sugar.js, to name a few, have all, at one time or another, added incorrect shims to native prototypes.

While Underscore is in a better position than those that extend native prototypes, regarding api/environment conflicts, it can still be tripped up by poor shims because it defers to many ES5 methods if they exist. For example, if Prototype 1.6.0 and Underscore.js are included on a page Underscore's `_.reduce` method won't work properly. This is one of the reasons why libs/frameworks like Dojo, Ember, Lo-Dash, RequireJS, Sizzle, and YUI do native checks too.

Re:How I want to write Node: Stream all the things by b3n on Friday February 14, 2014 @01:52PM (#7240254)
It's considered bad practice to add add methods to the prototypes of built in objects because it has the chance of breaking other people's code.
Re:How I want to write Node: Stream all the things by owenversteeg on Friday February 14, 2014 @02:10PM (#7240373)
Most people are very hesitant to add methods to array, string, etc. because if more than one person does that you'll end up with all sorts of problems.
Re:How I want to write Node: Stream all the things by rubiquity on Friday February 14, 2014 @08:06PM (#7242141)
Underscore uses the "_" variable because, well the library is actually named "underscore." Highland uses the "_" because... I don't have anything nice to say.
Re:How I want to write Node: Stream all the things by caolanmcmahon on Friday February 14, 2014 @01:21PM (#7240041)
var Highland = require('highland');
Re:How I want to write Node: Stream all the things by hamburglar on Friday February 14, 2014 @01:26PM (#7240065)
Yes, clearly you can do that, but it's obviously not your intent. All the docs use _ as the class name, and that's what you use internally. The class is named "_" and that's what people using it are going to expect to see if it becomes popular. You could make a better choice.
Re:How I want to write Node: Stream all the things by bigonlogn on Friday February 14, 2014 @01:46PM (#7240205)
> You could make a better choice.

But you can call it whatever you want, so... who cares? The choice is yours... Being a pedant is hardly constructive.

Re:How I want to write Node: Stream all the things by caolanmcmahon on Friday February 14, 2014 @01:31PM (#7240099)
I think I'm getting the hang of HN ;)
Re:How I want to write Node: Stream all the things by hamburglar on Friday February 14, 2014 @01:46PM (#7240201)
But seriously, it seems like a pretty neat library. I just think your nomenclature is the suxxors and eventually we're going to look back on this trend and think, "boy, making everyone reading your code wonder which _ you're talking about is a pretty silly way to save a couple characters."
Re:How I want to write Node: Stream all the things by e12e on Saturday February 15, 2014 @02:02AM (#7242982)
var ‾ = require('highland'); // Meet overline, the new underscore
Re:How I want to write Node: Stream all the things by badman_ting on Friday February 14, 2014 @01:29PM (#7240087)
Just seems like a silly thing to get hung up on.
Re:How I want to write Node: Stream all the things by hamburglar on Friday February 14, 2014 @01:35PM (#7240128)
Naming is important for code readability. I think a lot of people recognize that. Which is why I'm so baffled by this trend of "screw it, I won't even bother with a name! Call everything underscore!"
Re:How I want to write Node: Stream all the things by gruseom on Friday February 14, 2014 @01:58PM (#7240289)
Please don't bikeshed in technical threads. One comment on something like this is more than enough; zero is probably better.

When a new thing comes out, the discussion should focus on what's significant about it.