r/ProgrammingLanguages • u/hellotanjent • Nov 09 '22
Is “x' = f(x)” a programming paradigm?
/r/AskProgramming/comments/yq0uq7/is_x_fx_a_programming_paradigm/3
u/moon-chilled sstm, j, grand unified... Nov 09 '22
Sounds like TLA+.
I was also working on a game engine based on a similar paradigm (plus message-passing) at one point, but I lost interest, and also decided that that is the wrong paradigm for games—time is continuous, not discrete.
2
u/hellotanjent Nov 09 '22
"I want executable TLA+ that looks and performs like C++" would be a reasonable description of my long-term project goals. :D
I did game programming professionally during the N64 to XBox 360 era - "for (x in game_objects) x.update(delta_time);" was then and is still basically the model for most game simulations - discrete, but with an elapsed time parameter.
2
u/moon-chilled sstm, j, grand unified... Nov 09 '22
for (x in game_objects) x.update(delta_time)
Yes - the main problem with this is the implicit interdependencies between objects; this is what I wanted to avoid. A nice side effect of my design is that it admits efficient implementation--simply double buffer the game state--and high parallelism. And given such an architecture, it's easy to go from 2 buffers to n, for first-class time travel, or multiplayer, or ...
Afaik, deltas are no longer in vogue because they make the physics dependent on the framerate. Especially bad in a multiplayer context. I think interpolation is a common strategy for when the physics and graphics tick rates don't match.
1
u/hellotanjent Nov 09 '22
Yep, sounds like we had basically the same ideas. Double-buffering the game state works but does cost memory and CPU (due to the copies).
Deltas are better than explicit ticks for the special-effects/rendering update part of the engine (otherwise you get jitter on GSync-type displays), but fixed ticks are better for netcode. Physics theoretically shouldn't care about the tick rate as long as collisions are detected regardless of step size, but physics engines are notoriously wonky.
2
u/Molossus-Spondee Nov 09 '22
It sounds a little like you want functional reactive programming.
But you probably want it to use linear types and stuff for performance.
1
u/hellotanjent Nov 09 '22
Functional reactive programming really doesn't work for something like the gate simulation I do in GateBoy, where I'm trying to get as close to realtime as possible.
2
u/Rabbit_Brave Nov 09 '22
Temporal logic programming?
1
u/hellotanjent Nov 09 '22
Yeah, I usually call it "Temporal Programming" (with a nod to Lamport's TLA+).
2
u/ericbb Nov 09 '22
There really isn't any software-oriented language out there that ...
What do you think about Cell? Make sure to read the State updates section of the Relational Automata chapter.
1
u/hellotanjent Nov 09 '22
Seems very similar. I recall reading a bit about Cell a few years ago; I'll have to revisit it.
1
u/alagris12358 Nov 09 '22
There actually is. It's called GPAC https://en.m.wikipedia.org/wiki/General_purpose_analog_computer#:~:text=The%20general%20purpose%20analog%20computer,order%20to%20compute%20some%20function.
It is a continuous model of computation https://arxiv.org/abs/0907.3117
It is the fundamental theory that underlies analog computers, in the same way as turing machines are fundamental to digital computers
3
u/hellotanjent Nov 09 '22
Analog computers are super cool - you should google "The Analog Thing" for a modern example that you can buy and play with - but they're out of scope for this particular topic.
1
u/alagris12358 Nov 09 '22
That's cool af. I was always looking for something like this. I wonder if there are bigger machines. Like FPGAs or something
1
u/hellotanjent Nov 09 '22
There are definitely "analog fpgas" out there, but they're a niche of a niche product. I believe Cypress had a programmable analog block on its PSoC 5 chips, but there are also larger sea-of-opamps kind of things out there.
7
u/jediknight Nov 09 '22
Why not write it like (a,b) = (b+1, a+1) ?
As for "a program is a sequence of operations", I believe we should get away from manually mutating things. It is much better to give the compiler enough information to do the mutation itself in the most optimal way. It is better to program in a denotational language where things are predictable.
1
1
u/phischu Effekt Nov 09 '22
What could also be related is clash, a language (embedded into Haskell) that has first-class support for what they call signals. Here are some examples. They synthesize hardware from a given program.
1
u/hiljusti dt Nov 18 '22
I'd say that the important consideration here (from the C/C++ perspective) is a given CPU's instruction set will not necessarily have a way to map this to actual operations it can perform on registers. At least 3 stored values will be required to perform your example computations, or possibly using a stack and more operations
24
u/PurpleUpbeat2820 Nov 09 '22
In purely functional style you can literally write:
Depends entirely upon the type of
x. If it is a tuple of machine-precision numeric values as in you example then it can be done extremely efficiently. If it is a dictionary you're screwed.Related ideas are RC with in-place mutation for objects with counts of 1 and Perceus in Koka.