r/functionalprogramming • • Sep 25 '23

Question Why OOP sucks?

4 Upvotes

81 comments sorted by

View all comments

Show parent comment

6

u/pthierry Sep 26 '23

Several people in the game industry are starting to show that functional programming has immense usefulness in an ECS. The team of Mortal Kombat and Injustice 2 discovered they they needed immutable data and referential transparency to optimise their online gameplay. John Carmack says they should do games in Haskell.

Maybe we could have games without chaotic mutation all over the place, just orderly mutation.

2

u/ScientificBeastMode Sep 26 '23

I think it depends on the problem space. One of the hard things about functional programming languages is that most of them are garbage collected, which is a gigantic limitation on performance for some use cases. If you are really trying to optimize and push the limits of the graphics, you really need to avoid garbage collection and heap allocations in general, at least in that part of the code.

While you could easily use OCaml to create a game, I would worry that it’s reliance on a garbage collector (and its current limitations around multi-core execution) might make it a dealbreaker. So I would want to write the performance-sensitive code first and test it before fully committing to using OCaml.

2

u/P-39_Airacobra Sep 26 '23

That's really interesting, do you have more info/link for reading? I've been trying to learn/experiment with the ECS/functional combo for a while now.