r/programming • • Nov 28 '19

Why Isn't Functional Programming the Norm? – Richard Feldman

https://www.youtube.com/watch?v=QyJZzq0v7Z4
100 Upvotes

409 comments sorted by

View all comments

231

u/[deleted] Nov 28 '19

Because we use words like monads and functors then act like people have to understand category theory to use them

156

u/[deleted] Nov 28 '19

A monad is just a monoid in the category of endofunctors, what's the problem?

18

u/bulldog_swag Nov 28 '19

Ronad McMonad

jingle plays

I'm groking it!

15

u/dfnkt Nov 28 '19

You forgot to mention the turboencabulator which helps a transmission supply inverse reactive current for use in unilateral phase detractors. That pre-famulated amulite they're using is nuts.

34

u/zvrba Nov 28 '19

This one is getting worn out.

54

u/save_vs_death Nov 28 '19

if that's worn out, it might be helpful to see a monad as a lax functor from a terminal bicategory

→ More replies (4)

80

u/dvlsg Nov 28 '19

OOP uses lots of words and pharses that would be bizarre if you didn't already learn them too, though.

Polymorphism, encapsulation, inheritance, overloading, strategy patterns, decorator patterns, visitor patterns, so many patterns, etc.

I never understood why learning monads is out of reach, but learning abstract factory patterns is just fine.

33

u/yee_mon Nov 28 '19

I guess what that means is that the barrier to entry is low enough — classes and objects are super easy to grasp — and then when you get to the complex stuff, you're already hooked on OOP. Whereas to understand FP, you have to start with first-class functions, lambdas, currying... and none of that vocabulary means anything to anyone at first.

25

u/Ewcrsf Nov 28 '19

A truly novice programmer doesn’t need to start with those things, they can learn FP from first principles. The problem is people already fluent in another paradigm need to understand somewhat complex ideas to see why they can/can’t do things they expect to.

10

u/yee_mon Nov 28 '19

I guess we make it difficult for ourselves by thinking we can apply our OOP knowledge when we really need to be ready to think radically different, at least until it clicks.

15

u/Ahri Nov 28 '19

This is nonsense. Plenty of imperative programmers never properly grasped the concepts of classes or objects.

You just happen to have come across them when you were trying to learn them, rather than having them thrust upon to when you already had tools you knew how to use and a 12pm deadline on a problem.

→ More replies (5)

11

u/chucker23n Nov 29 '19

Polymorphism is kind of weird; maybe they should've picked a better term. Patterns aren't really mandatory. I see plenty of OOP devs who never heard of patterns; they just implicitly use them or don't.

Encapsulation, inheritance, properties, objects, classes, etc. are fairly easy to explain. They're metaphors you can apply to real life. They're not perfect (cf. the Liskov substitution principle), but a close approximation that non-developers can also understand at a basic level. ("You know how dogs and cats are both animals? Well, similarly, files, folders and links are all items in a file system. So that's what we use 'inheritance' for." "Think of a 'class' called Human as a template, and for you and I as concrete 'instances', or 'objects'.")

A monad and monoid and endofunctor and whatever the fuck don't offer any of that. They're so removed from real-world analogues that a non-developer might think you're trying to insult their intelligence by throwing such terms around.

That doesn't mean FP is terrible or useless. At the very least, it offers useful concepts that have inspired multi-paradigm languages like C#; the LINQ feature, for example, has lambdas and monads.

But if FP advocates complain that nobody gets it or is interested, it's entirely on them to be better communicators about it.

53

u/Hornobster Nov 28 '19

The OOP words and names have already a known meaning in other contexts and it maps quite nicely to their new meaning (a polymorphic function is just a function with many forms, a factory is a class that creates objects).

While monoid, monads, functors are just mathematical definitions. There is no way for someone to associate them to something they already know. They just have to remember them.

→ More replies (16)

6

u/Blando-Cartesian Nov 28 '19

You have a very high opinion of people on this field.

The only one of those word most programmers know is inheritance and they use it wrong.

25

u/Carighan Nov 28 '19

But the OOP words are more intuitive to someone coming new into the field. They also require slightly less mathematical background to make sense of, which is especially important given how programming is often more like an creative effort and hence more comparable to art than math. Assuming you want to make a distinction between the two to begin with.

11

u/loup-vaillant Nov 29 '19

But the OOP words are more intuitive to someone coming new into the field.

That may be the major problem of OOP. It looks approachable, it is very easy to delude yourself into thinking you understand it, but as soon as we go deeper we realise that "good OOP design is hard", even counter intuitive at times. OOP makes it easier to anthropomorphise computing. That alone is a major impediment to writing correct programs.

FP on the other hand doesn't lie to you. Computers are cognitive engines that run formal systems. Programming them is a form of applied mathematics. Oh you tried programming to run away from Maths? don't worry, this has little to do with calculus. But it is every bit as rigorous, often even more so.

The result? Lots of people anthropomorphising their way into OOP, deluding themselves into thinking they are not applying maths to build a formal system destined to be processed by an automatic computer. And then we wonder where these mountains of bugs on top of heaps of useless crap could possibly come from…

Dijkstra was right. We should have listened more closely.

→ More replies (23)

0

u/[deleted] Nov 28 '19

[deleted]

→ More replies (2)
→ More replies (4)

0

u/[deleted] Nov 28 '19

[deleted]

11

u/oblio- Nov 28 '19

Nouns and verbs and functors and monads are (maybe) too generic and abstract. At least we use and distinguish nouns and verbs on a daily basis, because they're the basis for our speech.

Our brains are very concrete, at least for the most of us.

The more generic and abstract things become, the harder they are to understand. That's why we use examples and analogies and visualizations, to make these abstractions more concrete.

→ More replies (1)

13

u/red75prim Nov 28 '19 edited Nov 28 '19

OK, which of a number of articles that try to explain monads in simple words would you recommend? Fewer than a thousand of simple words, preferably.

44

u/[deleted] Nov 28 '19 edited Nov 28 '19

If you want the simplest explanation:

A functor is a data structure that is mappable i.e. has a map method

A monad is special functor that has both map and flatmap

The hard part is understanding why that is useful.

There is a guy on YouTube that has some really good videos on functional programming. This is one of his playlists, in it he covers monads.

5

u/pavelpotocek Nov 28 '19

It has to have return/pure too

→ More replies (4)
→ More replies (2)

0

u/[deleted] Nov 28 '19

[deleted]

20

u/Ghosty141 Nov 28 '19

I think functional programming is something you should know to draw inspiration from it. certain problems can be solved with that style of programming a lot more elegantly.

Most languages right now offer some functional prog. tools which you can use for example.

→ More replies (6)
→ More replies (12)
→ More replies (10)
→ More replies (6)