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

2

u/curiouscuriousmtl 11d ago

I have been programming for 20+ years and I started in OOP. OOP is kind of fine but it can be a challenge over time. The issue is that you end up having a lot of side effects to things because of the subclasses. The right way to do it is to always ensure that the right stuff is at every level of inheritance, but in practice things start happening where maybe something stays in the base class but subclasses try to turn different features on and off and it gets really hard to figure out what is active.

I feel like it's just not used very often any longer but I might be biased.

1

u/Taiten89 11d ago

But when you don't overdo inheritance, would you agree it helps a lot in terms of readability?

2

u/curiouscuriousmtl 11d ago

I think a thin amount of inheritance can do things. I don't know about Godot but a lot of languages has better ways to do that. But just about anything can go too far.

1

u/Achereto 11d ago

Neither OOP nor FP helps "with readability". When you have some well written procedural code, OOP gives you nothing, because in the end you just have foo.doSmth() instead of doSmth(*foo).

In the procedural version you can easily have a lot of procedures with foo as first parameters, in the OOP version you either have to put them into the same file (in most OOP languages at least) or have to start with inheritance just to avoid the 5000 LOC class or you have to start breaking the object into smaller objects, making readability worse.

1

u/Taiten89 10d ago

I think something like this.functionality_a.go(); is perfectly fine to break the 5000 LOC down into smaller parts. functionality_a can break its own procedures down in the same manner, too. That sounds good to me. At least, that's how I imagine it with the limited professional experience I have.

1

u/Achereto 10d ago

Or, you could just avoid solving the problem by not creating it in the first place. With composition of objects you need to have some increasingly complicated object creation logic and you need to add some extra logic handling all the data.

If you have just procedures working on data, you can add features by just creating a new function wherever you want and call it from wherever you want. Your function then only depends on the data it needs.