4 ms·
Tweaked the structure of a functional-style space invaders game to be cleaner and more actually functional. Major insight: moving triggers for sound effects fro
by lincolnq 11y ago
Tweaked the structure of a functional-style space invaders game to be cleaner and more actually functional. Major insight: moving triggers for sound effects from deep inside the game logic to a separate piece of code that compared the state before and after the frame, and played the appropriate sounds based on that.
Question for the functional programming pros here: would you rather build it this way, or with a writer monad? The writer monad seems like less code overall, and keeps the side effect generation code near the code which generates the sound.
- danharaj 11y agoI do Haskell as my job. In general I would much rather have a function in the vein of `DeltaState -> [SoundEffects]` than another layer of effects. If the sounds aren't dependent on by what means the state changed, but only on what the change in state is, then you may as well factor out the sound logic. Conversely, since I want to keep the program well factored I endeavor to separate concerns into pure computations as much as possible and minimize effects.