|
|
|
|
|
by ajuc
1638 days ago
|
|
I can structure the code cleanly, that's why I love functional programming. Althought I mostly use clojure not SML-like languages so I don't go overboard with currying. From my limited experience currying makes order of arguments matter A LOT, and then you have to refactor that often. My problem is that I'm mostly writing games in my free time (the only time when I'm allowed to use functional languages), and writing games is mostly about quick iteration and testing many small changes. So previously I had the code to handle collisions only take potentially colliding objects as inputs and outputs. Now I want to add particle effects when things collide. Pass that particle system and return particles from the function. Then I think - what if collisions cause the screen to "shake"? Again pass new data to the function. Then I decide it looks stupid and revert it. Then I think - what if police reacted to collisions if they are near the police station? Again - pass some new data there. I can do this, but it's a lot of refactoring. I'd prefer if I could just use a global variable and hit a button in IDE to refactor it to a nice functional code. |
|
I'm not familiar enough with clojure, buy in F# you sample with collision/shake/police may looks like
where each function accept gameState, run some login against it, and return modified state, so you don't need to pass dozen arguments through call-stack.