Inline temps? I think not

Are these two snippets equivalent?

Snippet A:
  this.binding.type 
= this.initialization.resolvedType;
this.type.resolvedType = this.binding.type;
this.initialization.setExpectedType(
this.initialization.resolvedType);
this.initialization = new CastExpression(this.binding.type);


Sinppet B:
  TypeBinding temp 
= this.initialization.resolvedType;
this.binding.type = temp;
this.type.resolvedType = temp;
this.initialization.setExpectedType(temp);
this.initialization = new CastExpression(temp);


Which of the two snippets is easier to read?

The reason that the second piece of code is more straight forward is due to the local variable "temp" which gives a symbolic name to some value. Such a symbolic name makes it easy to understand the code and follow the flow of data therein.

Too many people advocate the eliminatation of temporary variables. Even the (otherwise excellent) refactroing catalog shows you how to "Inline Temps" and "Replace Temps with Queries". True, the motivation there is to transform the code such that further refactoring steps are made possible, but still, it leaves the wrong impression.

My two cents: Introduce temps! Replace queries with temps!

0 comments :: Inline temps? I think not

Post a Comment