4 ms·
If you have a simulation, where the outcome is not known and individual Objects are keeping track of their own data and behavior... VS. ...you already have da
by williamcotton 13y ago
If you have a simulation, where the outcome is not known and individual Objects are keeping track of their own data and behavior...
VS.
...you already have data about a set of things and those things aren't going to be changing their own data.
Think, Video Game VS. Data Visualization
- williamcotton 13y agoIf I have a run loop/game loop, I always use OOP. I'm curious, has anyone ever implemented a run loop in a functional style? I know there are recursive approaches to passing the time deltas and what not, but it seems rather difficult to make video games with a purely functional approach... Can anyone offer any insight?
- augustl 13y agoOne insight is that functional programming and pure functional programming are very different beasts. As an example, Clojure does not aim to be pure, Haskell does. In Clojure, the focus is on immutability, and state is modeled as a succession of immutable values. Example: the employees in a company is represented as an immutable value. A place (a ref) stores the current immutable value, and you can always ask this ref for that value, and set it to a new one. But the value itself is always immutable. In Haskell, everything must be pure, and uses monads to models things such as random number generators, I/O, and other side effects.
- klibertp 13y agoIt is hard. At least that's what I read in: http://prog21.dadgum.com/23.html http://prog21.dadgum.com/23.html EDIT: but not that hard, according to http://prog21.dadgum.com/37.html http://prog21.dadgum.com/37.html ;)
- williamcotton 13y agoWow, thanks for that link! The author's explanation was incredibly clear and I feel like I got a handle on it! Just 'lift' the relevant game state and pass mutatations along in a simular way to how you might pass exceptions along with a promise based system... Then it eventually feeds to a makeSounds() or an updateAnimations() or whatever! That way the code can keep all related functionality in one place, instead of spreading sound or animation related methods all over the code base encapsulated in each object with its own logic! Brilliant!
- williamcotton 13y agoAnd pass the previous frame state to the same functional pipeline, recursively... Now I need to make an OOP vs FP game loop/physics engine in javascript and compare and contrast the approaches! (Feel free to leave the votes alone on this one, or down vote to oblivion, because I am just using HN for note keeping so I leave the thought in context...)
- seanmcdirmid 13y agoFRP can supposedly handle stepped physical computations.
- wonderzombie 13y agohttps://en.wikipedia.org/wiki/Entity_component_system https://en.wikipedia.org/wiki/Entity_component_system http://www.gameenginebook.com/gdc09-statescripting-uncharted2.pdf http://www.gameenginebook.com/gdc09-statescripting-uncharted... Caveat lector: I'm not familiar with the current state of the art in gamedev, so this may not be new or interesting. The gist of this is that you prefer composition over inheritance, which is a bit more functional than an OO inheritance hierarchy. It's not strictly functional and it's definitely not purely functional. But it's a step in that direction, as it lends itself to viewing your system as a series of transformations over data rather than a system of actors. The second piece is also possibly only tangential, as it does have state. But it shows an interesting way to incorporate concepts germane to FP like continuations, and it does use a homegrown Lisp as its scripting language.
- weavejester 13y agoI've recently experimented with using functional reactive programming to handle the events of a game. I've found it allows for a greater degree of abstraction than an event loop with callbacks, in the same way that higher-level functions like map/filter/reduce provide an abstraction over iteration.