Revisiting Refactoring

Post on 09-May-2015

998 views 0 download

description

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

Transcript of Revisiting Refactoring

Revisiting Refactoring

Learning From the Past

Improving the Future

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

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

A List of Refactors

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

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

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

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

A Sampling of Refuctors

• Inconsistent Naming Conventions

• Module Gravity Well

• Useless prefixes / suffixes “Pig Latin”

• Reusing names

• Often introduced accidentally in a rush

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

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.

A List of Code Smells

• Duplicate Code

• Large Method

• Marge Class

• Inappropriate Intimacy

• Feature Envy

• Switch Statements

• Comments

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

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

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

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

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

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

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

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

Sample Prefactoring

• Inappropriate Intimacy

• Object model not resembling Business Model

• Separation By Interfaces

• Read code aloud to customers