CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2022
    Posts
    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?

  2. #2
    Join Date
    Feb 2017
    Posts
    677

    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?

  3. #3
    Join Date
    Jan 2013
    Location
    Largo, FL.
    Posts
    356

    Re: Does functional programming replace GoF design patterns?

    Quote Originally Posted by wolle View Post
    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?
    Actually, it was -> 13 years, 11 months ago

    but whose counting. GOOD CATCH.

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Does functional programming replace GoF design patterns?

    Quote Originally Posted by Steve R Jones View Post
    Actually, it was -> 13 years, 11 months ago

    but whose counting. GOOD CATCH.
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2017
    Posts
    677

    Re: Does functional programming replace GoF design patterns?

    Quote Originally Posted by TechVeera View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured