How to handle any change of state of a character with functional programming?

If I'm using functional programming the character should be stateless, in my understanding. With that said, I should instantiate a new character every time a position, for example, is changed. Is this correct? This doesn't sound very efficient, but I might be wrong. I'm tinkering before start implementing and wanted to be sure this is the right way.


  • \$\begingroup\$ Game development rarely uses purely functional styles. About the closest we get is highly data-oriented design, like ECS systems operating on buffers of data like a giant map call. May I ask why you're looking at functional style as a key goal for your character update logic? \$\endgroup\$ – DMGregory Mar 2 '19 at 4:40
  • \$\begingroup\$ I've used ECS and I loved it. I'm looking at functional style, because I've used in other projects and I liked it a lot. \$\endgroup\$ – tupan Mar 2 '19 at 12:44
  • \$\begingroup\$ Here’s a link to a series of short articles about implementing pac-man in a purely functional way: prog21.dadgum.com/23.html It doesn’t come down one way or the other on whether this is a good idea or not. \$\endgroup\$ – Ryan1729 Mar 2 '19 at 17:59

What your looking for is FRP game development.

Some Video Introductions:

It is 100% possible and preferable to make the core game logic in a purely functional way, the industry as a whole is simply behind, stuck in one paradigm of thinking.

Its possible to do it in Unity as well.

To answer the question a new game state will be updated/created every time something moves, as carmack says in his talk, it's not a problem. The drastic reduction in cognitive overhead that comes from a purely functional, highly maintainable, flexible architecture far out ways the performance hit, if it exists at all.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.