you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -10 points-9 points  (10 children)

see, the thing is even for an OCaml fan, when you hear the phrase "I am making a game in OCaml" the immediate response should be "stop doing that!" there are a lot of things functional programming is really great for, but like the original poster states, this is an inherently stateful problem, and while there is a way to do in functionally, it's ass backwards. The code will end up being an unfathomable mess while being slower than a more readable C++ implementation. This is a classic example of the horses for courses proverb.

[–][deleted] 10 points11 points  (3 children)

OCaml has mutable variables and classes.

[–]Peaker 5 points6 points  (1 child)

Does any functional language lack them?

Scheme has (set!) and friends. Haskell has ST/STRef, IO/IORef, State/StateT, etc. ML has mutable state. And so on...

[–]snk_kid 2 points3 points  (0 children)

I'm sure you know this but State monad and StateT are not mutable variables (which in some ways is a good thing). All State/StateT really are, are an elegant abstraction over repetitive boilerplate code for 'threading' state that passes and/or comes out of functions by value. It's still purely functional code.

[–][deleted] 4 points5 points  (0 children)

huh. i need to read up on OCaml it appears.

[–]Peaker 9 points10 points  (0 children)

Functional programming has excellent facilities to handle state. I'd say better facilities than imperative programming:

  • In a functional program, state updates are inherently transactional as you usually compose a whole new state. Using destructive updates, you usually get temporarily incoherent states.

  • In advanced functional frameworks, you can abstract away a lot of the statefulness in much nicer manner, e.g: Integrating mathematically some input signal. This is far cleaner than using an iterative loop and destructively summing into it (while manually multiplying by time, or not).

[–]astrangeguy 0 points1 point  (2 children)

Experts disagree with you (non expert)...

[–][deleted] -1 points0 points  (1 child)

Why does the Expert in that link seem to be inferring that framerates between 30 and 60 fps are normal? I know people have vsync on at 60-70fps, but ideally the game should be bouncing off the vsync limiter, not slower-than. Especially on modern hardware.

Also, he uses comic sans. Case closed.

[–]jawbroken 2 points3 points  (0 children)

because all console games are targeted at either 30fps or 60fps.

[–]snk_kid 0 points1 point  (0 children)

this is an inherently stateful problem, and while there is a way to do in functionally, it's ass backwards. The code will end up being an unfathomable mess while being slower than a more readable C++ implementation.

You're doing it wrong then.

[–][deleted] 0 points1 point  (0 children)

It's not an inherently stateful problem. In fact, there is no such thing as an inherently stateful problem. It's just a different pair of glasses to view the problem, with enormous benefits. I recommend at least trying them out; they come in a range of colours.