Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
“Discuss latest changes to master before releasing” (github.com/jashkenas)
59 points by ChrisGaudreau on Feb 20, 2015 | hide | past | favorite | 27 comments


If you find yourself annoyed by some aspects of Underscore, you might want to check out Lodash[1]. Lodash's API is a superset of Underscore, though you can create custom builds with only the parts you need. In general, Lodash performs better and has fewer bugs than Underscore. Unlike Underscore, Lodash has 100% test coverage. Also, Lodash has some handy things like _.cloneDeep(), and semantic versioning. That means your package.json can have "lodash": "3.x" in its dependencies without worrying about breakage.

For a more in-depth discussion of the differences between Lodash and Underscore, I recommend Ben McCormick's Underscore vs Lo-Dash[2].

1. https://lodash.com/

2. http://benmccormick.org/2014/11/12/underscore-vs-lodash/


Lodash is also several times larger than Underscore. The point of Underscore is to keep it light.

And yes, you can pick and choose what modules you want. But you could do that with Mootools and it was released a decade ago. If you want a heavy framework with lots of modules, there are plenty to choose from.

Maybe if it offered a light version on the front page? The file linked from the front page is 372KB. By comparison, the file linked from Underscore's front page is 51KB.


A couple things:

- The actual difference (minified and gzipped) is 17.6 KB vs. 5.7KB.

- Lodash is written modularly so you can import only the methods you actually need.

- In order to "lose some weight" (as Jeremy Ashkenas called it), underscore dropped several methods that people really wanted (including other contributors).

- Also to cut down the size, several major pieces of functionality is not broken in older versions of IE

- Lodash provides a lot more functionality than underscore does, there's a lot of additional utilities including the ones that were dropped last minute by underscore.

There are a lot of other reasons to use lodash, but that was quickly becoming not a _couple_ of things.


With regard to size, the gzipped size isn't the whole story - more code results in more processing time and memory usage.


True, but probably not the magnitude of difference you should be worried about.


That is not a fair comparison. Gzipped and minified underscore is 5.7kb. Lodash is 17.3kb. For the vast majority of sites that is a trivial difference in size.

Both of which are linked from the front page of their respective websites.


If you're using CommonJS you can do require('lodash/category/method'), and when it gets built on the frontend it'll only include the method and its dependencies. So if you're using only 5% of lodash, you'll only get that 5%.


Right. If on node, you can also use modules via NPM ( https://www.npmjs.com/browse/keyword/lodash-modularized ).

But as I said, this is common in many frameworks. Hell, you can even do with JQuery ( http://projects.jga.me/jquery-builder/ ). So having this ability doesn't make Lodash special.

This is not presented as the preferred method to use the framework on the project page either. You just get a link on the front page to the whole shebang. Probably because most developers just download the whole thing and stick it in.

What I was really hinting at was code complexity. Sometimes having something light and small that you can stick in there without worrying about anything is useful. Lodash can address that by having a light version linked off their front page, but they haven't done that.

On top of everything, Underscore is ribbing them on this very point. See http://underscorejs.org/ and bit down "(3x smaller than Lodash ;)" in bold. Seems like a really easy point to address.


If you care about filesize, you'll probably optimize as much as possible. You can do this with Lodash using modular imports.

There's little upside in hosting a light version, and fragmenting the docs. Min/max'ing on filesize lets you save 15 kB, or 0 kB. Creating a light build that saves 5 kB is a maintenance cost with a poor ratio relative to reward.


> If you care about filesize

I don't care about filesize. I care about code complexity. The more crap you add to a page, the slower it will run. You also get a higher probability of conflicts and problems in the long run.

If you need something, you need something. But if you don't and you just throw it in there, you're asking for problems down the road.


For an example of cherry-picking lodash modules see

https://github.com/postaljs/postal.js/issues/91#issuecomment....


Just noting that CommonJS has nothing to do with this capability, it will work in any format.


Completely agree. I always ask people why they're using underscore over lodash. Once they learn about lodash, they'll usually switch over right away.

There used to be a compatibility build of lodash, but I think it might've been deprecated by now... In any case, migrating would be fairly straightforward I think.


I like Ramda[1] better than both underscore or lodash because of it's argument ordering (function first) and auto-currying[2]. It's 7kb minified and gzipped.

[1] http://ramdajs.com/

[2] https://buzzdecafe.github.io/code/2014/05/16/introducing-ram...


https://www.npmjs.com/package/lodash-fp

Don't know how they compare though.


Yap, lodash v3 (https://github.com/lodash/lodash/releases/tag/3.0.0) introduced lodash-fp for auto-curried iteratee-first lodash methods.


I like Ramda as well, currying was a feature I didn't expect to use as often as I did.


To be fair: Underscore doesn't follow semver, so breaking changes between versions should be expected. This thread just seems like an excuse to pile on jashkenas and promote lodash.


It is released and consumed via 2 package managers that mandate the use of semver.


Via the Lodash CLI you can "lodash underscore". This results in 6.7kb gzipped. In my experience, jdalton is a very solid coder and the lodash package is excellently maintained.


I don't follow Underscore but whoever wrote this title (currently "Underscore 1.8 makes last minute breaking changes to master without discussion") must really have an axe to grind, and it seems inappropriate for HN. Doesn't really set the tone for any constructive discussion.


The submitted title ("Underscore 1.8 makes last minute breaking changes to master without discussion") broke the HN guidelines by editorializing the title. We changed it to the article title, such as it is. If any of you wants to suggest an accurate and neutral title that is better, we can change it again.


Yeah, and linking to a PR risks a bunch of parties w/o a real stake in the project piling on and shitting up the PR. Really poor form, OP.


shitting up the PR

Good people of HN, this phrase deserves your upvotes.


There have been previous events in underscore's history that lead to sudden breaking changes without following semver. That's probably why.


what idiot is using Underscore at this point?


Welcome to JavaScript.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: