Beau's tumblr

software engineer interested in all things ruby on rails or ETL

@bfabry

Sep 13

Extract till you drop

“Uncle Bob” is one of the creators of the Agile software development method and is the author of some of the best known books on object oriented design.

The fairly simple idea he describes here is a very easy way to improve the code you write drastically. Code that is broken up into many small collaborating methods is better for lots of reasons:

  • Easier to read and understand. Bit of a no-brainer but very important anyway. Method names are a very powerful way of commenting your code.
  • Stands up to change better. If in the replace example we wanted to change the way the code does matching, in the original version that would be a pita, in the refactored version that would be easy.
  • Shows the way to new refactorings. Each method performing single pieces of functionality means that each method individually will be using less data, which can point you to things like “Move method” because you can clearly see that a method isn’t using any of the variables from a class it’s in. An example would be the nextSymbol() method that is created in the string replacer. In this case we don’t have access to the class where we would like the method but if we did that method could be moved straight into the Matcher class and then could be reused in other places.
  • Permalink
  • Posted at 2:54 PM
← Previous post Next post →
  • Archive
  • Random
  • Mobile
  • RSS
  • Ask me anything
  • Powered by Tumblr
  • ER2 theme by Bill Israel