Skip to main content
gamedev.net
🔒 Locked

Functional reactive programming?

Started by klrr Nov 27, 2013 at 8:54 PM 5 replies 8.3k views
Original Post
klrr
klrr

Hello, I recently started writing a game using the Reactive-banana FRP library for Haskell. I realized that there actually exist FRP libraries for several mainstream languages, so I thought I might ask here and see what the perception of this fairly new paradigm is.[1,2,3]

Okey, for those who are unfamiliar Functional Reactive Programming is a new programming paradigm invented at Microsoft Research in late 90s. It initially was meant for animation (hence, the first paper was named "Functional Reactive Animation"[4]) but has been used for games, robots, audio, GUI, etc. Essentially it introduce time-varying values called events and behaviours(also called "signals"). Events are discrete time-varying values and behaviours are the continious equaliant. For example, an event could represent a mouse click and a behaviour could represent the position of a moving ship. The difference between these and mutable data or impure function calls is that you decleare its properties when you define the event/behaviour. You do not later mutate it and when its being called its not mutating anything(except for some primitives that needs to be hooked into the pure network of events and behaviours).

So this lets you declaritivly define games, which is awesome. It makes everything much easier than having to mutate some state or pass state around(as you would have to do in functional languages). I want to ask what this community's opinion is on this new paradigm is? I personally think its really good but I just got started, and my experience in game development is not that big so I don't have much to compare to. I only know of two companies who uses FRP, so it's still a young paradigm.[5,6] Also, feel free to ask me any questions too!

1. C++ FRP library https://github.com/kentuckyfriedtakahe/sodium/tree/master/c%2B%2B

2. Java FRP library https://github.com/kentuckyfriedtakahe/sodium/tree/master/java

3. JS FRP library https://github.com/baconjs/bacon.js

4. First FRP paper http://conal.net/papers/icfp97/

5. Mobile game development company using FRP http://ipwnstudios.com/

6. Web presentation software company using FRP http://prezi.com/

benlaud
benlaud

Functional reactive programming is a good idea. But in fact it is very similar to MVVM , and I guess it is a more popular term used in game industry? I found several MVVM library for Unity. However, I have no idea about the adoption of this design paradigm in the industry.

klrr
klrr

How is it similar to MVVM?

xenobrain
xenobrain

I've been learning the FRP paradigm in Scala. It's tremendously appealing to me both to my sense of "cleanliness" and as an intellectual puzzle. Naturally my thoughts have turned to it's applicability to C++ game programming.

Since I started, I've begun to use "const" more then ever and taking better advantage of functional composition that's helped me solve some previously tough problems (RPG spell effect system in particular).

It would be interesting to apply the paradigm to large scale systems, but I'm very worried about the runtime cost of many small memory allocs and frees necessary to maintain data structure immutability. C++11 move semantics and/or careful application of (mutable) memory pools may help amoritize it somewhat but that feels too much like I'm fighting the language rather than working with it.

My current experiment is with using immutable, overservable, memory pooled data streams (based on RxCPP) for marshalling data across systems in batches. The results are promising so far, but has a long way to go before production use.

Goran Milovanovic
Goran Milovanovic

FRP has tremendous promise, but it takes some time to actually understand in detail.

It helps to use a language like Elm, which was designed with FRP concepts from the outset, as a core part of a language (not just a library).

Actually, I'm currently working on a video tutorial series for Elm, if anyone is interested.

+---------------------------------------------------------------------+ | Game Dev video tutorials  ->   http://www.youtube.com/goranmilovano | +-------------------------------------
Krohm
Krohm




I want to ask what this community's opinion is on this new paradigm is?
After reading the (scarcely informative) links I've googled I'm afraid I don't really get the whole point. The PDF is probably what I'm looking for. It doesn't seem to be something I want to quickly skim over. Considering the paper was awarded "most influential in '97" and the small amount of links found, I'm not inclined to invest much time on it.
Previously "Krohm"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.