1. 12
  1.  

  2. 10

    First: I hadn’t realized that “functional programmer” now means “programmer of ML derived, statically typed languages.” I guess I missed the memo, or (more likely) blog post, declaring that an oft accepted, and lazy definition involving something like “minimizes side effects; embraces small, composable, and pure abstractions” has become strict.

    Second: I cringe at the idea that one could truly understand functors, monads, and other categorical foundations, but not have internalized the equivalence relationship between a traditional for or while loop and its recursive counterpart.

    1. 1

      First: I hadn’t realized that “functional programmer” now means “programmer of ML derived, statically typed languages.” I guess I missed the memo, or (more likely) blog post, declaring that an oft accepted, and lazy definition involving something like “minimizes side effects; embraces small, composable, and pure abstractions” has become strict.

      Welcome to English, where we don’t have an académie but rather define our terms by their usage.

      1. 3

        It’s literally the worst thing in the world.

    2. 9

      These are combinators, not loops, right?

      1. 3

        Matter of semantics in this context, really. c.f.: https://en.wikipedia.org/wiki/Fixed-point_combinator

        The resulting function behaves like a while or a for loop in an imperative language.

      2. 15

        this was a long and shaggy explanation of a fairly obvious equivalence. this pissy commentary brought to you by the lack of story downvotes.

        1. 9

          I get annoyed by the characterization of people like me as “functional programmers”. I can program in Haskell, or in C. It’s about picking the right tool for the job. I prefer functional programming when it makes sense, but it’s not something I see fit to insist on for all cases.

          The problem is that the benefits of FP don’t appear in small examples. An iterative loop actually is more intuitive to most people than a recursive function. Hell, goto is extremely intuitive– think of how recipes are written, e.g. “Go to step 13”– but it makes for bad code at scale. Same with OOP, which makes code more comprehensible to MBA-toting self-appointed “big picture guys” but a lot less rigorous and therefore harder to work with.

          My personal opinion: as a performance optimization, or just when it makes a small bit of code more legible, imperative loops are fine so long as the language allows it… and it’s better to be idiomatic within the language than to adhere to an ideology. A 10-line block after a while-loop isn’t the enemy. There’s nothing wrong with that. The problem is when you get a 25,000-line class with no clear organization.

          This may be a minor nit, but we also get it wrong with the term “side effect”. IO does not have “side effects”; those are the main effects. What is undesirable is when there are unexpected state changes.

          Immutability and referential transparency are, on the whole, good things. They become close to mandatory, unless there’s a good reason not to use them, on large projects. They can also be achieved in imperative languages at the function/API level, with a clear separation between computation and imperative action, and they should be. However, this idea that we are (or should be) purists who refuse to write while-loops out of some ideological purity is nonsense.

          1. 5

            Using folds is using recursion. It’s just not explicit. Meh? Also, lisps have had loop macros for as long as there have been lisps, and until used in do notation in Haskell looks pretty damn loopy. I’ve never encountered the “functional programmers don’t use loops” myth, but rather usually “how do I avoid using loops in functional languages?”

            1. 2

              When I look at a traditional loop construct:

              for x in mylist:
                do_something(x)
              

              I see that

              1. The value of x keeps changing
              2. do_something must have a side effect, or return a value that mutates some variable in the loop

              These two make me think - uh, loops are not functional re: state mutation.

              1. 2

                Functional does not necessarily imply pure. That position has become more mainstream because of the benefits for parallelization and the growing popularity of Haskell, but most other functional languages are not pure.

                1. 1

                  Hmm, but then does the description not lose it’s value? If you are allowed to mutate, then every language is functional, regardless of what you call the implementation of how you call a piece of code that is a function.

                  1. 3

                    I’d say that the only genuine requirement for being functional is the ability to treat functions as values; that is, to implement higher-order functions. Yes, that means that most modern languages can be written in a functional style.

            2. 1

              I guess we know why the site is called two-wrongs.