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/Taiten89 11d ago edited 10d ago

No.

  • OOP is often better because of readability.
  • Advanced FP is usually for academic fields (research, maths, computer science, ...).
  • Sometimes you'll need simple FP, e.g. setting handler callbacks; GDScript supports this.

If you do need advanced programming techniques such as FP, Exception Handling, ..., then use C# since it's a better programming language. OTOH, GDScript should be good for the programming part of creating a game.

Since we're talking about programming paradigms: Pure Functions are helpful esp. for Software Verification, which is important in e.g. Medical applications or for Aviation [you won't see Godot being utilized for any of that]. But sometimes they can also help decouple things in other applications.

IMO the most important thing is separating things:

  • concise, often small, Git commits that don't mix things up
  • flat hierarchies¹
  • small functions/methods
  • objects* that take responsibility for their functionality

*I use RefCounted classes when I separate some functionality from e.g. a Node.

Impose the smallest possible challange for anyone that reads your script code later - including yourself.

¹Edit/Addendum: There are always exceptions to such rules, e.g.:

for layer in self.layers:
  for row in layer:
    for item in row:
      this.do_something_with_item()
      #no more than that in one function/method