5 ms·
The only thing stopping Functional Programming from taking off are functional programmers. It took me years (and Elixir) to get past the "here are some words,
by bongobingo1 4y ago
The only thing stopping Functional Programming from taking off are functional programmers.
It took me years (and Elixir) to get past the "here are some words, some mean what you think, some mean something completely different to what you know, some mean almost the same thing. Also here's 30 overloaded operators that you have to juggle in your head and we wont introduce things like variables for another 4 pages." without running back to something imperative to actually build something.
Functional programming's great when you have immutability to drop an entire class of bugs and the mental energy that accompanies that, can pass-around and compose-with small functions easily which makes writing, testing and figuring much simpler and can make your brain click that "its all data" without trying to over complicate it by attaching methods to it.
Honestly I think that's 90% of what the royal You needs to understand to get FP and actually try it. Selling people on "its all stateless man" or other ivory tower tripe is such garbage because (as the tutorials always point out) a program with no state is useless, and then the poor shmuck has to learn about monads just to add a key to a map and print something at which point they're asking "how was this better again?"
- BoppreH 4y agoI think that's a bit harsh. It's frustrating to translate an imperative task to an FP language, but it's also frustrating to translate a Bash command into Python, or Prolog semantics into Go, or any program full of mutations and global state into (safe) Rust. I think a lot of the friction you mentioned comes from learning imperative programming first. Our vocabulary, tools, and even requirements come with an implicit imperative assumption. PS: I didn't downvote you, though your tone is harsher than I prefer for HN.
- bongobingo1 4y ago> I think a lot of the friction you mentioned comes from learning imperative programming first. Our vocabulary, tools, and even requirements come with an implicit imperative assumption. Yes that's exactly my point and why no one cares about how great a monad is when trying to learn FP.
- wiseowise 4y agoHow is that a problem of functional programming? When you learn a language you don’t start with “Well in English we say…” you learn language with its idioms and quirks.
- bongobingo1 4y agoIt's not. It's a problem with people trying to sell FP to non FP programmers. A non FP programmer doesn't care about monads. They care about making what they already do simpler and clearer.
- wiseowise 4y agoFair enough. I guess it's the same as when you're trying to teach imperative programming starting from classes and OOP.
- Izkata 4y ago> When you learn a language you don’t start with “Well in English we say…” you learn language with its idioms and quirks. Idioms and quirks come after rote memorization of basic vocabulary and sentence structure, which are then used to learn the idioms and quirks. I think Bongo is saying FP-ers are skipping the basic vocabulary part and jumping straight to the idioms and quirks. It was interesting in 2015/2016 to see co-workers learn some of that basic vocabulary of functional programming without realizing they were touching on it, using map/fold/etc when learning React.
- skrtskrt 4y agoI strongly disagree, it is definitely the teachers and advocates of FP which are lacking. There are plenty of programs and libraries written in "imperative" languages like Python with lots of functional style applied. That should be the starting point, not sermonizing about whether a monad can even be defined with English words.
- alexvoda 4y agoOf course you can use English words. To quote: "A monad is just a monoid in the category of endofunctors, what's the problem?" /s
- TheOtherHobbes 4y agoHaskell is particularly, egregiously bad for this. None of the concepts are particularly complex. They're unfamiliar, sort of, but they're not insanely obscure. But then there's the labelling. If an ordinary for-loop was called a yarborough and a function call a demicurry it really wouldn't help with the learning. I realise the concepts are supposed to map[1] to category theory, but category theory stole words like monad from elsewhere anyway. [1] Ha.
- lupire 4y agoThis comment only makes sense in the monolingual USA, where learning a new language is an arduous task and not something people do all the time. German, Polish, and Chinese programmer all learn what "for" means. And anyway, Java calls functions "methods", yet somehow we survived.
- hnfong 4y agoThat is somewhat true, but in practice, not really so. Imagine you're a Chinese programmer. Obviously a lot of open source documentation is in English, so you have to learn basic English anyways (I'm bilingual from an early age, but most people struggle if they start the process even in their teens). Then you see English-speaking programmers talking about yarborough and demicurry as if they were English words. Now you're majorly confused. Worse, an encyclopedia of philosphy tells you that it means something (see eg. https://plato.stanford.edu/entries/leibniz/#MonWorPhe https://plato.stanford.edu/entries/leibniz/#MonWorPhe ) What's the actual connection? When you ask, people casually tell you to read up on category theory, which is apparently something they teach to advanced Math majors. Remember we're struggling to learn basic English here!!!
- shrimpx 4y agoI would argue that command sequences that mutate global state are far more intuitive to humans (food recipes, furniture assembly manuals, the steps to take to fix a flat tire on your bike, etc.) than functions. So it’s not just what we learn first in a pedagogic sense. We’re already wired for imperative programming. “Thread the state of the world through the food recipe instructions” is a ridiculous concept to a normal person.
- kaba0 4y agoI think it is very dependent on the problem at hand. Some traditional CS algorithm? Mutable it is. But a compiler with different passes is a great fit for the FP paradigm. But even if we go to pure math, you will have constructive proofs beside traditional ones.
- olddustytrail 4y ago> “Thread the state of the world through the food recipe instructions” Oh, that's how it works? That actually makes sense. Thanks!
- senand 4y agoI agree in principle. However, if you work imperatively, you'll use _much_ more (global) state than if you worked with a pragmatic functional language like Clojure. Which in turn leads to normal people not understanding what's going on, since humans are built to keep, say, 10 things (atoms) in mind, not 100.
- revskill 4y agos = 1; s = 2; is same as unit(1).chain(add(1)) That's the beauty of immutable data.
- nailer 4y ago> Functional programming's great when you have immutability to drop an entire class of bugs and the mental energy that accompanies that, can pass-around and compose-with small functions easily which makes writing, testing and figuring much simpler and can make your brain click that "its all data" without trying to over complicate it by attaching methods to it. A hundred percent. FP for me, is "let's stop gluing state and functions together for no reason" and get all the benefits above. I understand pure functions, avoiding state, closures, and using first class functions as the basic building blocks of creating higher level structures. When it becomes "a functor is a monoid of the schlerm frumulet" - ala the typical FP advocacy blog / latest React state management manifesto masquerading as library documentation, I zone out. The odd thing is, I don't feel I've lost anything by doing so.
- rkangel 4y agoI agree that Elixir is the ideal gateway into FP. It's also quite a good argument that "FP" at its core is something more fundamental than what is talked about in this article. Elixir doesn't really use many of the category theory derived approaches at all, it has a convenient way of doing method chaining and some higher order function stuff and that's about it. And the results are excellent code. The two main FP things that you need to learn to do Elixir well (IMO) are thinking about data structures first, and purity. Choose the right representation of the data at each stage and then what functions do you need to move between each. Make those functions side effect free (but not obsessively). Then you put your stateful code in GenServers and you have useful real code and most of it was incredibly easy to test.
- skydhash 4y agoPretty much this. I've been learning Common Lisp and the way I try to design my programs is to have a somewhat clear understand on how your data should transform from input to output. Then you write the functions. Let's say your data is a log file and you want to load everything in memory. You write the code that returns the data, which you either store in a variable or compose with other functions. At the end, you compose all of these functions in your programs. Everything is an expression, meaning that you can extract things easily into functions. This is how you make things readable. `load-log-from-file` and `auth-failure-count` is better than keeping everything together in a single function.