4 ms·
Just adding my two cents. Wanna be a good JS dev? Go play around with a lisp. Like Clojure for a month or two. Get comfortable with functional programming. Then
by darby2000 11y ago
Just adding my two cents. Wanna be a good JS dev? Go play around with a lisp. Like Clojure for a month or two. Get comfortable with functional programming. Then come back to JS. So many people come from a OOP to JS and they have a bad time with it. JS is more like a lisp with C syntax than it is a traditional OO language. Learning Clojure, not only improved my JS abilities, but just my over all programming maturity. IMO. Additionally, I agree with the author about reading books, and libraries. It's always good advice for any language.
- vinay427 11y agoInteresting, thanks for this perspective. As someone who started with C/C++ (and a hint of Python) but has recently started working in Clojure, I'm now very encouraged to re-try JS.
- mdup 11y agoIndeed. Personally I'm used to think in functional ways: map, fold, function composition, immutability... I'd like to be good at Haskell but I'm always having lots of pain dealing with it, because I never see the end of the learning curve. I've found JS to be a nice middle land where I can get productive functionally without too much hassle. It's like a good friend who understands my way of thinking without being in the way too much. Underscore.js hits the sweet spot for me: _.chain(...).map(...).filter(...).value() is verbose but surprinsingly readable. I'm not a fan of Python map() syntactically, and I absolutely hate C++11's std::transform.
- notduncansmith 11y agoIf you want to make that even less verbose, try myArray.map(...).filter(...) (those methods don't have to come from underscore, they exist on the Array prototype as of ES5).
- cle 11y agoI totally agree. If you've only been exposed to OOP, and you don't have the bandwidth for learning an unrelated language, then start using a functional library like Underscore. Just use it everywhere, even if you think it's ridiculous. Don't use for-loops, use _.each. Try to think of every problem in terms of chaining map, reduce, zip, pluck, groupBy, etc. Do whatever you can to avoid side-effects. Once you're comfortable with it, try reading "Functional JavaScript". You'll quickly develop a taste for when OOP or functional is appropriate, but I think the best way to get to that point is to immerse yourself in functional programming first, which might mean writing some ridiculous functional stuff, but the long-term payoff will be worth it.
- Roboprog 11y agoTHIS! JSON starts to look like funny s-expressions. JS brings a lot more to the table than just a scripted version of "C++ for retards" (aka Java), as it also lets you make use of many FP concepts like higher order functions and functional (vs object) composition. For example, using currying (aka "dependency injection for functions") lets you often do with a single function what would take a silly-long class to do in Java. Use currying to inject leading parameters to a function that would normally be in the constructor (or setters, ugh) in a Java class, then the remaining "short arg list" function acts like the oh-too-common one actual "we're ready, now do something" method in a class.
- notduncansmith 11y ago> JS is more like a lisp with C syntax Indeed, so the tale goes: Brendan Eich was originally going to make Scheme for the browser, but Netscape said their browser language had to look like Java, and that's how we wound up with this odd vaguely-functional browser language called Javascript. In light of that, definitely seconded. Using Clojure (and watching Rich Hickey's amazing talks) made me a much better developer, and especially a better JS developer. Somewhat relatedly, one thing I personally like about CoffeeScript is that it really lets the functional, Lisp-y side of Javascript shine through by melting away all the crufty syntax. That really helped me apply some of the style I picked up from Clojure.
- hasenj 11y agoThis! I cringe when I see Java/C++ style code in JavaScript. Unfortunately it's how most JS coders write code.
- dlau1 11y agoAgree so much with this comment. Downside is that after using a proper functional language (clojure[script]) you end up wanting some really basic things such as immutable core data structures. I feel like if you start from scratch on a javascript project, it's possible to program in a functional manner. I've found it really tough to introduce functional concepts to an already full stack javascript codebase. BTW: I'd recommend ramda [1] for those interested in functional javascript programming. The auto-currying makes it way more powerful than underscore/lodash in terms of encouraging pure reusable functions. [1]: https://github.com/ramda/ramda https://github.com/ramda/ramda
- jdd 11y agoThere's a flavor of lodash with auto-curried iteratee-first data-last methods too. See lodash-fp – https://www.npmjs.com/package/lodash-fp https://www.npmjs.com/package/lodash-fp