Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

6. Tips and Tricks > 6.4. Refactoring

Refactoring

Refactoring means transforming code without changing its functionality. Consider renaming, which is the simplest form of refactoring. If you rename a local variable from rose to daisy, it would smell as sweet.

Much has been written on refactoring, such as Refactoring: Improving the Design of Existing Code (Addison Wesley). Before Eclipse and similar tools were available, programmers had to do refactoring manually or with simple text substitutions. For example, in the vi editor, running the command :1,$s/rose/daisy/g will replace “rose” with “daisy” everywhere in the current file.

If you’ve ever tried this, you know it’s usually a bad idea. Your simple search-and-replace operation can change more than just the variable you intended, even with a clever substitution string. Plus, if you need to change multiple files, you’ll have to go to a scripting language such as Perl.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint