revisiting refactoring

21
Revisiting Refactoring Learning From the Past Improving the Future

Upload: nick-harrison

Post on 09-May-2015

1.008 views

Category:

Technology


0 download

DESCRIPTION

A tour de force of Refactoring, Refuctoring, Code Smells, and Code Smiles

TRANSCRIPT

Page 1: Revisiting Refactoring

Revisiting Refactoring

Learning From the Past

Improving the Future

Page 2: Revisiting Refactoring

What We Will Cover What is a Refactor What is a Refuctor What are Code Smells What are Code Smiles How does this change what we do

Page 3: Revisiting Refactoring

Defining Refactoring

• Code refactoring is the process of changing a computer program's internal structure without modifying its external functional behavior or existing functionality

• improve internal non-functional properties of the software

• improve code readability

• to simplify code

Page 4: Revisiting Refactoring

A List of Refactors

• http://www.refactoring.com/catalog/

Page 5: Revisiting Refactoring

Observations About Refactoring

• Refactoring improves the design of software

– without refactoring, a design will “decay” as people make changes to a software system

• Refactoring makes software easier to understand

– because structure is improved, duplicated code is eliminated, etc.

• Refactoring promotes a deep understanding of the code at hand by tearing it apart and putting it back together again

Page 6: Revisiting Refactoring

What We Will Cover

What is a Refactor

What is a Refuctor

What are Code Smells

What are Code Smiles

How does this change what we do

Page 7: Revisiting Refactoring

Defining Refuctoring

• Refuctoring is the process of taking a well-designed piece of code and, through a series of small, reversible changes, making it completely unmaintainable by anybody except yourself.

• Often occurs when refactoring is not disciplined

• Occurs when changes are made at the last minute

Page 8: Revisiting Refactoring

A Sampling of Refuctors

• Inconsistent Naming Conventions

• Module Gravity Well

• Useless prefixes / suffixes “Pig Latin”

• Reusing names

• Often introduced accidentally in a rush

Page 9: Revisiting Refactoring

What We Will Cover

What is a Refactor

What is a Refuctor

What are Code Smells

What are Code Smiles

How does this change what we do

Page 10: Revisiting Refactoring

Defining Code Smells

• A Code Smell is a hint that something has gone wrong somewhere in your code

• A Code Smell is a hint that something might be wrong, not a certainty.

• Calling something a CodeSmell is not an attack; it's simply a sign that a closer look is warranted.

Page 11: Revisiting Refactoring

A List of Code Smells

• Duplicate Code

• Large Method

• Marge Class

• Inappropriate Intimacy

• Feature Envy

• Switch Statements

• Comments

Page 12: Revisiting Refactoring

Observations About Code Smells

• Smells are guidelines

• Smells should not be dogmatic

• Smells should introduce a sense of humor to code reviews

• Code smells have associated Refactors to address specific smells

Page 13: Revisiting Refactoring

What We Will Cover

What is a Refactor

What is a Refuctor

What are Code Smells

What are Code Smiles

How does this change what we do

Page 14: Revisiting Refactoring

Defining Code Smiles

• A code "smile" is some aspect of the code that makes other developers smile when they have to maintain it.

• Code Smiles add up to code that is easily maintained

Page 15: Revisiting Refactoring

A List of Code Smiles

• Common sense naming conventions

• Cohesive and loosely coupled modules

• Elegant abstractions

• Lack of duplication

• A close resemblance to the application domain

Page 16: Revisiting Refactoring

Observations About Code Smiles

• Code smiles do not happen by accident

• Code full of Smiles can deteriorate without careful attention

• Code smiles may also require supporting documentation or one on one training

Page 17: Revisiting Refactoring

What We Will Cover

What is a Refactor

What is a Refuctor

What are Code Smells

What are Code Smiles

How does this change what we do

Page 18: Revisiting Refactoring

Defining Prefactoring

• Simple steps to take to prevent common problems before they arise

• Conduct “Lessons Learned” meetings from previous projects

• Identify common problems

• Take steps at every stage to avoid issues known to cause problems in the past

Page 19: Revisiting Refactoring

Towards a Catalog of Prefactors

• Identify a recurring issue

• Define a preventative measure

• Verify that the prevention is being followed

• Verify that the recurring issue is reduced

• Refine the preventative measure

Page 20: Revisiting Refactoring

Sample Prefactoring

• Inappropriate Intimacy

• Object model not resembling Business Model

• Separation By Interfaces

• Read code aloud to customers