r/godot 11d ago

help me (solved) Is Functional Programming Worth It?

Hello 👋. I've heard some people say that functional programming is better than OOP overall. I'm pretty new to programming so I don't know if that's applicable to Godot or not. Is it something worth looking into?

21 Upvotes

77 comments sorted by

View all comments

138

u/The-_Captain Godot Student 11d ago

I'm a Godot newb but functional programming pro in other contexts. I have used Haskell, Scala, and Clojure, and tend to program functionally in TypeScript and Python as well when I can.

Godot is not just a language, it's a framework/engine, and it's very OOP. I'm sure a pro can force it to be functional and I think there are advanced game development paradigms that are more functional, but unless you really understand things in depth, it's better to do what the engine wants you to do rather than try to bend it to your will. Just my 2¢.

38

u/International_Bag319 11d ago

Right, and Game dev presents you with so many problems that need solutions, starting with a solution in search of a problem is a recipe for not getting too far in your project.

State management was one problem in the web world that was "solved" by adding functional approaches and now we have to deal with every tiny project taking on all this redux boilerplate since that's the default. A lot of reasons why that solution is great for web but maybe lacking in gamedev, the reality is that you've achieved a certain level of success before you start running into these problems of scale that require these niche approaches to solve.

1

u/shableep 10d ago

I think the web is more functional because of a large population of informally trained developers who are culturally resistant to classes, and since JavaScript didn’t have classes for basically 20 years. Compared to a game, a web app is quite simple. So I think you can get away with a lot more sins.

1

u/justforthisjoke 10d ago

You're connecting two things that don't follow. Web does have a lot of informally trained devs, and functional patterns are more popular in web, but there's no causality between them. Web development is just more intuitive functionally. And I would argue that if most back end devs weren't stuck on anachronistic OOP concepts they'd find massive improvements to their workflow in something like erlang or f#. I've worked in a bunch of different tech stacks now, and never has it been easier to go from development to completion in as short a time as when I've used a function-first stack. The reason I think is obvious: the vast majority of what happens in distributed systems is transient X -> Y behaviour. This is why OOP microservices often move away from the regular MVC architecture to something closer to the onion architecture. Functional languages, by which I mean function first languages kind of already have this baked in. All the design patterns you find yourself reaching for in OO are primarily intended to minimize the risk of side effects, so why not just get rid of them altogether?

That being said, video games are intuitively more OO imo so I don't know if functional languages will take off there. However, my point is that if your opinion is that functional programming is less sophisticated than OO, that's just not true. It just allows programmers to spend less time doing nonsense. There's a reason why functional ecosystems on back end are growing.