• expr@programming.dev
      link
      fedilink
      arrow-up
      41
      ·
      6 days ago

      As a senior engineer writing Haskell professionally, this just isn’t really true. We just push side effects to the boundaries of the system and do as much logic and computation in pure functions.

      It’s basically just about minimizing external touch points and making your code easier to test and reason about. Which, incidentally, is also good design in non-FP languages. FP programmers are just generally more principled about it.

      • Samskara@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        1
        ·
        12 hours ago

        Reasoning about memory use for example is difficult with FP.

        Using pure functions is a good idea for non FP languages as well.

      • namingthingsiseasy@programming.dev
        link
        fedilink
        arrow-up
        13
        ·
        6 days ago

        I’ve never had the chance to use a functional language in my work, but I have tried to use principles like these.

        Once I had a particularly badly written Python codebase. It had all kinds of duplicated logic and data all over the place. I was asked to add an algorithm to it. So I just found the point where my algorithm had to go, figured out what input data I needed and what output data I had to return, and then wrote all the algorithm’s logic in one clean, side effect-free module. All the complicated processing and logic was performed internally without side effects, and it did not have to interact at all with the larger codebase as a whole. It made understanding what I had to do much easier and relieved the burden of having to know what was going on outside.

        These are the things functional languages teach you to do: to define boundaries, and do sane things inside those boundaries. Everything else that’s going on outside is someone else’s problem.

        I’m not saying that functional programming is the only way you can learn something like this, but what made it click for me is understanding how Haskell provides the IO monad, but recommends that you keep that functionality at as high of a level as possible while keeping the lower level internals pure and functional.