Can you shorten "GameObject.GetComponent(Script)" to a variable?

When visually parsing my scripts, my eyes just get totally jangled by the constant, long references to GameObject.GetComponent(Script), such as:

runnersObj.GetComponent(RunnerControlScript).GetBatterObj();

In my ideal world, I could write something like this:

var RunnerControl : scriptReference; // fake type for illustration purposes only!
RunnerControl = runnersObj.GetComponent(RunnerControlScript);
// later in code...
RunnerControl.GetBatterObj();

This would greatly beautify the code, IMHO.

Is this possible, and if possible, is it recommended?

This is not only possible, this is advisable as this will cache the result of the GetComponent instead of looking it up each time.

Try something like this:

var RunnerControl;
var runnersObj:GameObject;

function Start()
{
    RunnerControl = runnersObj.GetComponent("NameOfScript");
}

function Update()
{
    Debug.Log(RunnerControl.someVariable);
    RunnerControl.SomeFunction();
    // Other stuff to do with RunnerControl
}

Just remember to assign runnersObj in the editor.

Thank you, everyone.

It sounds like one question has a resounding yes: you can assign the results of a GetComponent call to a variable, making it easier to read (and update, if necessary).

However, I'm seeing two different answers on its impact. Eric5h5 says it will be 30-40x slower, Joshua says it will be faster because the results are cached. Both make sense to me.

Is there a deeper answer to this?