SimulaVR / Simula

Linux VR Desktop
MIT License
2.91k stars 87 forks source link

Code architecture #75

Closed lboklin closed 4 years ago

lboklin commented 5 years ago

Something I find slows me down a lot when prototyping is that there's no cohesive design or standard regarding whether to utilize the Godot-native OOP approach of registering classes with inheritance and use the callback entry points for logic and state handling or to write in a functional style, utilizing data types for state handling and operate on the scene tree's nodes in a more idiomatic style.

The problem with the OOP approach of registering classes is that:

  1. We don't have an easy way of registering and wiring up signals, so that adds an amount of boilerplate state variables we need to keep track of per object until some utility functions and types are added to godot-extra like for registering classes and methods.
  2. It's difficult to debug stateful objects which individually do their own thing compared to state managed from a central entry point. Right now for example we have GodotSimulaController manipulating the transform of sprites entirely on its own, while GodotWestonSurfaceSprite handles their own input from a pointer, while GodotSimula handles controller input received via signals emitted from the controllers...
  3. Difficult to know where to put new code.
  4. Difficult to refactor.
  5. Exported methods (GFunc ...) take and return variants, which is completely unsafe and takes a bunch of boilerplate to convert to and from usable types.

The problem with a functional style is that code can be difficult to architect in a way that scales and performs well. See: various intricate FRP frameworks which attempts to solve this problem. It's also hard to balance writing pure functions vs using the unsafe Godot bindings in the IO monad (safety vs leveraging existing engine functionality).

The benefit of a more functional code base should be obvious; better composeability, reuseability, easier refactoring and it lends itself more to type driven programming which can improve the correctness of the code.