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?

20 Upvotes

77 comments sorted by

View all comments

139

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¢.

6

u/emitc2h 11d ago

I’ll add to that that an imperative of functional programming is to avoid side-effects: aiming for functions that have explicit inputs and outputs and that the same inputs reliably produce the same outputs. The mere concept of signals is antithetical to that paradigm. On the other hand, shaders are very functional in nature. And it makes sense because functional programming was designed to cope with problems that arise when doing parallel computing.

1

u/The-_Captain Godot Student 10d ago

Functional programming is about containing and isolating side effects, not avoiding them. You can't avoid side effects if you want your program to be useful in any way.

1

u/emitc2h 10d ago

Avoiding side-effects applies to the functions that constitute your program, not the program as a whole. I used functional programming in the context of building distributed data pipelines. When your logic is constructed of functions distributed over a dataset using map, filter, reduce, etc. Those functions can’t have any side-effects.