I'm wondering about whether it is good to declare multiple unneeded variables to make my code more readable. Which of the following snippets is better coding? it calculates the force between two masses.
// 1
double dx = xPos - b.xPos;
double dy = yPos - b.yPos;
double r = Math.sqrt(dx*dx + dy*dy);
double F = G * mass * b.mass / (r*r);
// 2
double Fx = G * mass * b.mass / Math.pow( Math.sqrt(Math.pow(2,xPos-b.xPos) + Math.pow(2,yPos-b.yPos)), 2);
How do I balance readability and performance? Is doing it all in one line with a comment okay?
(I realize that the Math.pow( Math.sqrt( in the second example could be removed but this is just an example)