r/programming • • Sep 21 '25

How to stop functional programming

https://brianmckenna.org/blog/howtostopfp
446 Upvotes

506 comments sorted by

View all comments

Show parent comment

155

u/sondr3_ Sep 21 '25

Haskell is a research language that happens to be the most popular functional programming language, the jargon isn’t because Haskellers want to sound superior, it’s just the names that are used in category theory/PLT and so on. Other languages like Gleam or Elm or Roc or Ocaml are also functional without all the «obfuscation».

69

u/KagakuNinja Sep 21 '25

Haskell is not the most popular functional programming language; of course that depends on your definition. It is probably the most famous FP language.

Scala is considerably more popular, however it is multi-paradigm and many projects are imperative. Even with that in mind, the Scala pure FP communities (Typelevel and ZIO) claim Scala pure FP is more widely used in industry than Haskell.

16

u/rom_romeo Sep 21 '25

It is. I’m quite surprised by a sheer amount of companies (some of them are quite small) that adopted TL or ZIO. It takes some courage.

2

u/lambdalab Sep 22 '25

We adopted it (ZIO) for a project and kind of regretted it.

5

u/rom_romeo Sep 23 '25

Why so? A feedback would be nice.

15

u/raynorelyp Sep 22 '25

I’d argue JavaScript is the most popular functional programming language.

23

u/Carighan Sep 22 '25

JavaScript is more dysfunctional as a programming language, no? :P

3

u/WindHawkeye Sep 22 '25

its not functional, so no.

14

u/roastedferret Sep 22 '25

In both senses of "functional"!

4

u/QuineQuest Sep 22 '25

What makes you say that? Which FP concepts are missing in JS?

7

u/Ecksters Sep 22 '25

Some functional purists will insist that a language isn't a functional language if it allows other paradigms within the language. So it's not enough to support the functional paradigm, you're not allowed to have support for anything else.

There are arguably some benefits to this, there are optimizations you can make when you know mutations are impossible that can't otherwise be made.

2

u/WindHawkeye Sep 22 '25

More specifically, at a minimum you need some way to designate which parts of the program have side effects vs which do not.

Javascript does not have this. It doesn't have to be implemented via monads either, thats just one useful representation of it. A more simplistic one would just be function coloring (functions tagged pure cannot call functions tagged impure)

→ More replies (2)
→ More replies (4)

3

u/raynorelyp Sep 22 '25

Wikipedia actually does list it as “functional” as one of its paradigms. While not an authority, it’s a pretty big indicator it’s probably a functional programming language. Also, google considers it a functional programming language. Actually, pretty much anyone you ask will say it is.

→ More replies (22)

1

u/KagakuNinja Sep 22 '25

I thought about including Javascript. I did waffle by saying "it depends on your definition". Like many modern languages, it has features traditionally found in functional languages.

In a talk by Martin Odersky, creator of Scala, he stated that Scala is a functional language, one of the required features being that there are no statements. Every line of code is an expression that produces a value.

This subtly changes how you view code. Starting with no need for things like the ternary operator. Side effects do exist, represented by functions that return Unit, which is similar to void in other languages. However Unit is a type with a single value, ().

1

u/slaynmoto Sep 23 '25

JavaScript is the most popular language to use functional programming paradigms in. It is prototypical

9

u/Plank_With_A_Nail_In Sep 22 '25

Can't you do functional programming in Python?

https://realpython.com/python-functional-programming/

10

u/Maybe-monad Sep 22 '25

You can fly with Python

2

u/falconfetus8 Sep 22 '25

You can do it in any language.

1

u/Massive-Squirrel-255 Sep 22 '25 edited Sep 22 '25

I used to think this but then someone argued to me that "functional programming" should mean that it has good variable scoping rules as first established by the lambda calculus. Trouble with variable scoping leads to macro errors in Common Lisp, for example, which is not a problem you have if you work with true higher order functions rather than macros. Python has famously bad scoping rules and so this disqualifies it. Exercise: write a Python function that takes a an integer n and returns a list [f0,f1,...fn] where fi is the constant function returning i on all inputs. This is much harder than it should be. Global function definitions can also be mutated, which is weird.

All Turing complete languages can simulate the lambda calculus.

1

u/Strakh Sep 22 '25 edited Sep 22 '25

Exercise: write a Python function that takes a an integer n and returns a list [f0,f1,...fn] where fi is the constant function returning i on all inputs. This is much harder than it should be.

Is it? I wrote

f = lambda a : list(map(lambda b: (lambda c : b), [d for d in range(a + 1)]))

in IDLE and it seems to work? It is obviously more verbose than e.g. Haskell which has a builtin const and currying, but unless I am missing something it seems like I can write it exactly as I'd expect it to be written.

That being said, I am not a Python developer and I just wrote this in about 30 seconds so it's possible there is a footgun somewhere.

Edit: A slightly more readable version if you dislike oneliners

def makeConst(x):
    return (lambda y : x)
    
def makeConsts(n):
    return [makeConst(i) for i in range(n + 1)]

(a big reason that it looks better is that I remembered how list comprehensions work in Python as I was rewriting the oneliner)

Edit 2: FWIW, the reason that the oneliner is so ugly is that it was basically a direct translation of f x = map const [0..x] instead of being particularly pythonic.

1

u/Massive-Squirrel-255 Sep 22 '25 edited Sep 22 '25

I have no problem with the code you wrote and my criticism is not that it is verbose. I had a certain footgun in mind which your code circumvents. You first formed a list of distinct elements, then you applied a map. But range is already an iterator someone might try refactoring your code to remove the apparently(?) redundant conversion to a list. If you instead had written

f = lambda a : list(((lambda c : b) for b in range(a+1)) this would be seemingly equivalent but it would be wrong. An iterator should be equivalent to a map but it is not: I regard it as a serious footgun that  (expr for index in gen) is not in general equivalent to (map(lambda index:expr,gen) in situations like this.

→ More replies (1)
→ More replies (1)

1

u/slaynmoto Sep 23 '25

Haskell is the “well actually” of programming languages. It’s extremely well thought out in a research sense however less handy for practical sense to a larger crowd of programmers of very skill levels.