HackerTube

Hey Underscore, You're Doing It Wrong!

InfoQ9 HN recommenders · recommended in 7 months, 2014–2022
YouTube
talk · intermediate · evergreen · 2014–2022 on HN

Brian Lonsdorf explains why Underscore.js falls short as a functional programming library, then introduces currying, composition and point-free style in JavaScript. He argues for data-last argument ordering.

A repeatedly recommended introduction to functional JavaScript that explains currying and why data should come last.

12 comments from Hacker News

@r3a1d33p2022-08 · in “Ask HN: Learning Functional Programming in 2022?”

I find this talk inspiring. Underscore.js got many things wrong for FP: ▶ this video . I've read Grokking Simplicity too. It's very approachable book. Highly recommend it for JS/TS developers who want to learn FP!

Strongly recommends View on HN
@wizao2015-01 · in “Lodash v3.0.0”

There is an excellent talk called "Underscore, you're doing it wrong!". The talk explains how well designed param order with currying leads to very short and expressive code -- and how underscore missed the boat. This aspect of it should be interesting as it's related to this post. It's well worth the watch. ▶ this video

Strongly recommends View on HN
@lrichardson2014-04 · in “Functional JavaScript, Part 3: apply, call, and the arguments object”

That is great feedback. I am actually working on creating a "functional" version of the 2048 game, along with my own implementation of the AI solver, as part of this series. Kinda goofy, and maybe not a "real world" situation as much, but should at least show the concepts being applied. I also very much recommend this video by Brian Lonsdorf, titled "Hey Underscore, You're Doing It Wrong!: ▶ this video

Strongly recommends View on HN
@splintercell2017-09 · in “Currying vs. Partial Application (2015)”

With all due respect, I don't think you understand the purpose of currying and partial application. In your defense, the article merely explains what currying is, but does not explain why you need it. For instance while writing functional Javascript code, I never curry my methods, instead I use helper methods from functional libraries such as lodash or Ramda to curry. Where currying is useful is in cases like this: ```javascript //Definitions const filterUsers = (fieldName, value, users) => //Implementation const sortUsersBy = (fieldName, users) => //Implementation const takeUsers = (count, users) => //Implementation //Without currying UserService .getUsers() .then(users => filterUsers('active', true, users)) .then(users => sortUsersBy('age', users)) .then(users => takeUsers(3, users)); //If these methods were curried UserService .getUsers() .then(filterUsers('active', true)) .then(sortUsersBy('age')) .then(takeUsers(3)); ``` Here is a video which explains proper uses of currying (and does it very well) [1]. Here is another article if your coworker start using functional programming and you want to stop them [2]. 1. ▶ this video 2. link

Recommends View on HN
@patricklynch2016-07 · in “Just: A library of dependency-free JS utilities that do just do one thing”

Because then you can curry/partially apply functions independent of your data. It's _not_ because it's convention everywhere else. (I realize that only really makes sense if you know why it makes sense, so this video gives a pretty good explanation in ~30 minutes - ▶ this video )

Recommends View on HN