6 ms·
As a year-deep front end developer, I have recently taken a strong interest in functional programming principles and am trying to learn their use-cases. Does a
by DarkTree 11y ago
As a year-deep front end developer, I have recently taken a strong interest in functional programming principles and am trying to learn their use-cases.
Does anyone have ideas for small projects I can complete that will really drive home the importance/benefits of functional programming?
- 1971genocide 11y agoRead "Learn you a good haskell" - and practice the exercises in that book. It helped me a lot to understand the practical side of functional programming. For a book that maximizes the utility of functional programming in your everyday life I would recommend "functional javascript" by the famous author of underscore.js
- SpaceCadetJones 11y agoNot a project, but maybe check out the book JavaScript Allonge which I believe is free to read online
- nine_k 11y agoDirectly available as https://github.com/raganwald/javascript-allonge https://github.com/raganwald/javascript-allonge
- eddd 11y agoElm tutorial walks you through simple "mario bross" game. It is quite fun. http://elm-lang.org/examples/mario http://elm-lang.org/examples/mario
- hepta 11y agoCuriously, the biggest benefits (of typed functional languages) for me are revealed with larger codebases or spiked code that I have to revisit some weeks later.
- imakesnowflakes 11y ago> that will really drive home the importance/benefits of functional programming.. From my experience with Haskell, on a practical level, I think it really comes down to a guarantee that you will not be able to mess the code up beyond a certain extant. I am not really sure if it should be attributed to the type system or to functional programming in general. A functional programming language require a really good type system, because you need it maintain sanity with you have to chain together functions a lot more than you do in an imperative language. So I think it has to be a mix of both.
- coolsunglasses 11y agoHaving done Clojure for a living before Haskell, it's the type system, explicit effects, laziness, overall good design, and FP. In that order. But the "FP" part is only tangentially the point unless you take FP to mean "pure functional programming", ie, just a lambda calculus. Having the ability to write "map" and "filter" in your programming language doesn't really do much for you in practice. Believing otherwise is why people thought FP users were nuts for a long time.
- danneu 11y agoThe main benefit of Elm and Redux is the simplicity of their core abstraction: that your app is just a reducing function over a stream of events from the outside world including game ticks, mouse clicks, <input> field changes, etc. For example, a counter that increments per click: initApp = { counter: 0 }; stepApp = (action, oldApp) => oldApp.counter + 1; viewApp = (app) => `<p>Clicks so far: ${app.counter}</p>`; currentApp = reduce(stepApp, initApp, mouseClicks); currentHtml = map(viewApp, currentApp); This makes it really easy to inspect, test, and reason about what's actually happening and why since every change to your app had to be caused by an event that triggered a step from oldApp to newApp. Redux and I think Elm come with a debugger that even prints out `{action}, {oldState}, {newState}`. Makes it really easy to get a reading on things. Though it's possibly hard to appreciate this until you've battled it out in the trenches with an abstraction that isn't so simple, especially on a large, complex app. I personally found Redux (w/ React) immediately accessible and think it's a good place to start, especially if you're already coming from React or you want to reap the benefits without leaving Javascript. I'd feel really comfortable using Redux on any team project that was already using React and some other Flux'y implementation. I've also been learning Elm this past week though it's taking me far longer to become productive since there are fewer resources and I have no ML experience. I've managed to create a simple Spreeder.com-style speed-reader (https://www.danneu.com/elm-speed-reader/ https://www.danneu.com/elm-speed-reader/), and if you look at the source code (https://github.com/danneu/elm-speed-reader/blob/master/Machine.elm#L70 https://github.com/danneu/elm-speed-reader/blob/master/Machi...), you can see that it's not much different from the counter-app example I pitched above where the `update` function reduces across a stream of actions including button clicks and the tick. (Disclaimer: I'm an Elm noob)
- alphanumeric0 11y agoI agree, this is one of Elm's main draws. PureScript has a library for this style of FRP (https://github.com/bodil/purescript-signal https://github.com/bodil/purescript-signal). From the documentation, Elm signals are like a process network (https://en.wikipedia.org/wiki/Kahn_process_networks https://en.wikipedia.org/wiki/Kahn_process_networks). In my experience I've been able to model any conceivable interactions with a website using this model.