UP | HOME
../../ | Slides

Refactoring

Table of Contents

Refactoring is the modification of software source code to improve software qualities. … while preserving functionality. Enhancement is not refactoring. Refactoring is part of maintenance

1 Code Refactoring

  1. Software Quality
  2. Remove "bad smells"
  3. Functional equivalence: before v after
  4. Performance?
  5. Other quality issues
  1. Refactoring is exclusive of bug fixes.
  2. http://tedfelix.com/software/refactoring.html is a list extracted from Martin Fowlers writings.
  3. http://autorefactor.org/ Site looks old-fashined, but content is good. Collection of Examples auto- refactored.

2 Bad Code Smells

  1. Falling short of some goals.
  2. Comments poorly done
  3. Nesting depth too deep
  4. Duplicated code
  5. Long method
  6. Large class. "God object"?

2.1 Bad Code Smells #2

  1. Refused Bequest, contract of the base class
  2. Feature Envy: A class that uses methods of another class excessively.
  3. Inappropriate Intimacy: dependencies on implementation details of another.
  4. Data Clumps: "… consider deleting one of the data values: if you did this, the others do not make sense, …"
  5. Too many parameters, Lazy class / Freeloader, Excessively long identifiers, Excessively short identifiers, Excessive use of literals

2.2 Bad Code Smells #3

  1. Divergent Change "occurs when one class is commonly changed in different ways for different reasons."
  2. Primitive Obsession: "People new to objects usually are reluctant to use small objects for small tasks, …"
  3. Shotgun Surgery: "You whiff this when every time you make a kind of change, you have to make a lot of little changes to a lot of different classes."

2.3 Holzmann's "Ten Rules" to Have Good Smells

  1. Restrict to simple control flow constructs.
  2. Give all loops a fixed upper-bound.
  3. Do not use dynamic memory allocation after initialization.
  4. Limit functions to no more than 60 lines of text.
  5. Use minimally two assertions per function on average.
  6. Declare data objects at the smallest possible level of scope.
  7. Check the return value of non-void functions, and check the validity of function parameters.
  8. Limit the use of the preprocessor to file inclusion and simple macros.
  9. Limit the use of pointers. Use no more than two levels of dereferencing per expression.
  10. Compile with all warnings enabled, and use one or more source code analyzers.

3 OO Design Patterns

4 Big Refactorings

  1. Tease Apart Inheritance tries to tame a messy inheritance hierarchy.
  2. Convert Procedural Design to Objects
  3. Separate Domain from Presentation moves domain logic out of the UI classes.
  4. Extract Hierarchy introduces polymorphism to replace complex conditional code.
  5. Rearchitect: Client/ Server
  6. Rearchitect: Engine + GUI

5 Anti-Patterns

6 References

  1. Sir Charles Anthony Richard Hoare on Software Quality, http://onlinelibrary.wiley.com/doi/10.1002/spe.4380020202/epdf, Software – Practice and Experience, 103-105, 1972. Turing Award Winner. Required Reading.
  2. http://en.wikipedia.org/wiki/Refactoring Required Visit/Reading the individual refactoring techniques also.
  3. Kent Beck and Martin Fowler, http://martinfowler.com/ and http://refactoring.com/catalog/ A catalog of several patterns. Describes many of the smells discussed. https://sourcemaking.com/ also has most of the materials presented well. [Martin Fowler claims that much of their content is his.]; Martin Fowler, Refactoring: Improving the Design of Existing Code, book, Addison-Wesley, 2000. [Well .., not design improvement, but code improvement.] http://tedfelix.com/software/refactoring.html is a list extracted from Martin Fowlers writings. All sites: Required Visits.
  4. Gerard J. Holzmann, The Power of Ten – Rules for Developing Safety Critical Code,'' IEEE Computer, June 2006, pp. 93-95. http://spinroot.com/gerard/pdf/P10.pdf Required Reading.
  5. Mantyla, M. V. and Lassenius, C, "Subjective Evaluation of Software Evolvability Using Code Smells: An Empirical Study", Journal of Empirical Software Engineering, vol. 11, no. 3, 2006, pp. 395-431. http://www.soberit.hut.fi/~mmantyla/ESE_2006.pdf Skim Reading.
  6. Refactoring PDF Slides by Prof Kim ./refactoring-ut-austin-2013.pdf Required Reading.

Copyright © 2016 www.wright.edu/~pmateti • 2016-06-01