Using "purer" functions has been a big help in code writing. Trying to clear away any side effects from a function makes it easier to design and debug.
px,py,vx,vy=update(px,py,vx,vy,ax,ay) is a pure or at least mostly pure function. The only data the function reads is the inputs, and the function does nothing except return the correct values.
And writing things out in pure functions made it obvious that the dimensions were independent, so I can write...
function update(p,v,a,t)
t=t or 0.033333333 --approx. 1/30 sec frame time
return p+v*t+0.5*a*t*t, v+a*t
end
function updateball(ball,otherstuff)
--100 times more readable than putting everything in one line
ball.px,ball.vx=update(ball.px,ball.vx,ball.ax)
ball.py,ball.vy=update(ball.py,ball.vy,ball.ay)
--can use it for both 2 and 3 dimensions
end
(It's silly that I like to write p_new=p+v*t+0.5*a*t*t instead of just p_new=p+v*t, the extra accuracy is probably never needed. But how the heck should I be able to compare tradeoffs in speed and accuracy? Both speed and accuracy of even a crappy computer are light-years beyond what I need to emulate a PICO8 fantasy console. Most people use a simpler formula because of laziness, not desire for efficiency.)