Is there a good reason the Unity 2D platformer tutorial code is like this?

In the Lerpz 2D platforming tutorial there is a PlatformerController script that calculates movement and jumping. A variable inside the ApplyJumping function calls to another function to get the result…

function ApplyJumping () {
	movement.verticalSpeed = CalculateJumpVerticalSpeed (jump.height);
}


function CalculateJumpVerticalSpeed (targetJumpHeight : float) {
	return Mathf.Sqrt (2 * targetJumpHeight * movement.gravity);
}

I’m trying to learn as many efficient coding techniques as I can so I’m wondering if there’s a reason the programmer chose to put this into its own function? Why didn’t he just write it as:

function ApplyJumping () {
	movement.verticalSpeed = Mathf.Sqrt (2 * jump.height * movement.gravity);
}

…because to me, this seems more efficient. Why did he create a whole function to call to? Was it unnecessary or is there a reason for it? The CalculateJumpVerticalSpeed function is not called anywhere else in the project.

//edit: might sound like I’m criticizing but I’m not! Just trying to learn. :slight_smile:

It doesn't make any difference. The reason is good programming technique. While the function is currently not called anywhere else in the project, it might be at some point in the future- it's always best to split this kind of thing down into small, modular operations so that it's easy to see exactly what parts do what. For example, you might want to make some kind of 'jump height calculator' (for AI use, or to give the player a feel for how high they will jump) which uses the same function. Instead of copy-pasting the code from the jumping part, just make another call to the 'calculate jump height' function! This way, if you make a change to one, the change propagates to the other without you having to do any work- since they are both using the same line of code.