-
October 29th, 2022, 06:20 AM
#1
Does functional programming replace GoF design patterns?
Since I started learning F# and OCaml last year, I've read a huge number of articles which insist that design patterns (especially in Java) are workarounds for the missing features in imperative languages. One article I found makes a fairly strong claim:
Most people I've met have read the Design Patterns book by the Gang of Four (GoF). Any self respecting programmer will tell you that the book is language agnostic and the patterns apply to software engineering in general, regardless of which language you use. This is a noble claim. Unfortunately it is far removed from the truth.
Functional languages are extremely expressive. In a functional language one does not need design patterns because the language is likely so high level, you end up programming in concepts that eliminate design patterns all together.
The main features of functional programming (FP) include functions as first-class values, currying, immutable values, etc. It doesn't seem obvious to me that OO design patterns are approximating any of those features.
Additionally, in functional languages which support OOP (such as F# and OCaml), it seems obvious to me that programmers using these languages would use the same design patterns found available to every other OOP language. In fact, right now I use F# and OCaml every day, and there are no striking differences between the patterns I use in these languages vs. the patterns I use when I write in Java.
Is there any truth to the claim that functional programming eliminates the need for OOP design patterns? If so, could you post or link to an example of a typical OOP design pattern and its functional equivalent?
-
November 4th, 2022, 10:40 AM
#2
Re: Does functional programming replace GoF design patterns?
You posted the same question here and got many high-rated replies,
https://stackoverflow.com/questions/...esign-patterns
But it was 13 years ago, so maybe you have forgotten?
-
November 5th, 2022, 01:49 AM
#3
Re: Does functional programming replace GoF design patterns?
 Originally Posted by wolle
Actually, it was -> 13 years, 11 months ago
but whose counting. GOOD CATCH.
-
November 5th, 2022, 03:14 AM
#4
Re: Does functional programming replace GoF design patterns?
Victor Nijegorodov
-
November 6th, 2022, 02:23 AM
#5
Re: Does functional programming replace GoF design patterns?
 Originally Posted by TechVeera
Is there any truth to the claim that functional programming eliminates the need for OOP design patterns? If so, could you post or link to an example of a typical OOP design pattern and its functional equivalent?
If you accomplish a certain functionality according to the OO paradigm using OO patterns, you can achieve the same with the FP paradigm using FP patterns. So in this sense, it is true that FP eliminates the need for OO patterns.
One should not even attempt to use OO patterns in FP. It is because the patterns of a paradigm represent good coding in that paradigm. And using alien patterns most likely violates the paradigm resulting in bad code. So when doing OO, use OO patterns and when doing FP, use FP patterns.
Here is a talk on the topic focusing on FP patterns,
https://www.youtube.com/watch?v=srQt1NAHYC0
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|