Investigating Design Patterns

I wanted to investigate the claim, that functional programming does not need design patterns.

So I wrote a blog post about it

11 Likes

Hi, that’s a very nice blog post. Seems like quite a lot of work.

A couple of tiny typos: Factory Pattern, the type definition has Trasportation
Flyweight pattern, the markdown is not interpreting the link to the pattern, perhaps because of a space between the square and round brackets?

More substantively, the criteria behind a tick or a cross is a little subjective. For example, you give Mediator Pattern a tick and Memento pattern a cross, but I cannot quite work out why? Both of them you seem to implement well enough.

For me, design patterns represent a deficiency in the language. Not necessarily a bad deficiency. But you’re writing down the pattern, because you cannot generalise it in code. If there were a library that implemented a pattern, then you wouldn’t need to write down the pattern, just release the library and state its use cases. Patterns are essentially re-usable design, because the equivalent code cannot be generalised and re-used. So the language is not capable of expressing the pattern in a reusable way. As I said, this might not be a bad deficiency of the language since it might be that nobody knows how to generalise such a pattern.

This is why you generally hear “functional programs do not need design patterns” from functional programming proponents, because it’s essentially saying “functional languages can express design in a reusable manner”. This should also give you pause.

With that in mind, each design pattern could be evaluated as “could this be written as a library in a functional language”? You could further split those that could into “already have been” and “doesn’t yet exist”, whereby the latter would indicate that the problems that the design pattern solves don’t come up for functional programmers (or that it’s so trivial nobody feels the need to release a library, e.g. it might already be a natural part of the language).

3 Likes

Hi, thanks for that review :green_heart:

Regarding :white_check_mark: vs. :x:, I was completely subjective: Which pattern would I actually call by name.

The Mediator pattern felt like a real pattern to me - not that I have ever needed it - but still. Also, while working through the example I didn’t get the feeling, that a functional approach would make this meaningless.

The Memento pattern, however, really felt like just an opaque non-empty list. It’s not something I would write a package for. That said, it reminded me a lot of elm-community/undo-redo.

But thanks again for your comment :smile:

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.