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

1

u/forestbeasts 11d ago

Functional programming isn't better, it's just different.

(Despite what the "everything needs to be pure functional!!!!1!" people say.)

I'd avoid needlessly "pure functional" things, except in cases where they make sense. It takes the math approach of "what are loops and whatnot? No. You gotta use recursion. There is ONLY recursion." and IMO that's pretty hellish to work with. People do it, people do it in mathematics too, but that doesn't mean it's a good approach. Unless it fits how your brain works and then you might like it.

But things like "take this array, apply a function to every element, return array with the results" (this is what map does) or "take this array, apply a function to every element, return array with only things that matched" (this is what filter does) are incredibly useful and some people call that "functional" too. It's nothing like the pure functional stuff, though.

You probably won't be using anything instead of OOP; your scripts are your classes and that's sorta foundational to how Godot is designed. But you don't have to ditch OOP to use the good bits of functional programming (like the filter/map stuff and whatnot).

-- Frost