Tuesday, February 9, 2010

Webs Developer

PHP, Ruby Rails, JavaScript, AJAX and other bits ‘n pieces…

Sameer Borate’s Blog: Refactoring 3: Replace Temp with Query

Posted by web slinger on June - 8 - 2009

Continuing on in his refactoring series (part 1 & part 2) Sameer has posted part three - a method of replacing temporary variables with calls to other methods.

Temporary variables are a integral part of any code. But a splattering of the same all over can make your code hard to understand or modify. Replace temp with query is a refactoring method where you replace temp variable expressions with methods. This method is often also required before you use the Extract Method refactoring.

In his example, he takes a variable inside a current method (base_price) and replaces it with a method call by the same name resulting in a more reusable format other methods can call rather than just computing the value themselves.

Share and Enjoy:
  • Reddit
  • Digg
  • Slashdot
  • StumbleUpon
  • TwitThis
  • Technorati
  • del.icio.us
  • Facebook
  • Fark
  • Google

Continue reading over at PHP Developer...

Add A Comment