Godot + Functional Programming

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By PH-Zero

Cheers!

Just checked out Godot and totally in love with its simplicity (as opposed to Unity)

I did study some of the documentation, and I have one thing in my mind which I would like to hear you thoughts on.

I’m a functional programmer currently working with Haxe. (therefore using Godot Sharp)

How would you unify Godot with the concept of functional programming, Godot being heavily based on OOP/imperative?

There is the Haskell approach:
encapsulating all imperative action in values of the generic type IO a (think Action<R> where R is the type of the result of the action).

I guess in Godot this could look somewhat like
function newNode(parent:Node, pos:Vector3D, orient:Quaternion, model:Model):Action<Node>
where Node represents a handle to an existing node in the scene tree.
There would then be functions to change them and stuff like move(node:Node, offset:Vector3D):Action<{}>.

In the above example one would’ve to write all this encapsulating code first…

My approach

I’d dream up something like GameState<T> where T is the internal state variable.

In a pacman game for instance the id of the arena, the position of pacman and all the ghosts etc. is contained in a structure called PacGame. So when instantiating a new GameState<T> it would take a parameter T->Video (In that case PacGame->Video). The type Video would essentially be a set of some kind of position-orientation-model triple. It’s like saying “listen Godot, so this is how my pacman game should look like”.

This would kind of be my favorite. But is it possible instead of dealing with nodes to just tell Godot “Please for this frame go and render those models at (X,Y,Z) and at (X,Y,Z) and so on”?

I understand if this is a bit against the grain, but I kind of abhor oop… just doesn’t go well with functional (at least IMHO =)

What are your thoughts on that?
How would you approach this?

Very curious about your answers =)

Have a good one!

  • Robin

I’ve heard about doing functional programming in the engine, but only in GDscript. Here’s a video by vnen (a.k.a. George Marques, the guy who maintains GDscript) on how to make functional applications in GDscript.

Ertain | 2020-12-26 18:39