Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > PHP/MySQL/Scripting

  • Print
  • + Share This
This chapter is from the book

Refactor to Simplify Code

Refactoring is the art of reworking your code to a more simplified or efficient form in a disciplined way. Refactoring is an iterative process:

  1. Write correct, well-commented code that works.

  2. Get it debugged.

  3. Streamline and refine by refactoring the code to replace complex sections with shorter, more efficient code.

  4. Mix well, and repeat.

Refactoring clarifies, refines, and in many cases speeds up your code. Here's a simple example that replaces an assignment with an initialization. So instead of this:

function foo() {
  var i;
  // ....
  i = 5;
}

Do this:

function foo() {
  var i = 5;
  // ....
}

For More Information

Refactoring is a discipline unto itself. In fact, entire books have been written on the subject. See Martin Fowler's book, Refactoring: Improving the Design of Existing Code (Addison-Wesley, 1999). See also his catalog of refactorings at http://www.refactoring.com/.

  • + Share This
  • 🔖 Save To Your Account