Anti Patterns Siddhesh Lecture1 Of3

56
Anti-Patterns Refactoring Software, Architectures and Projects in Crisis Siddhesh Bhobe 8-Aug-2002

description

Anti Patterns - what not to do!

Transcript of Anti Patterns Siddhesh Lecture1 Of3

Page 1: Anti Patterns Siddhesh Lecture1 Of3

Anti-PatternsRefactoring Software, Architectures and Projects in Crisis

Siddhesh Bhobe8-Aug-2002

Page 2: Anti Patterns Siddhesh Lecture1 Of3

Menu Definition Motivation for AntiPatterns Software Development AntiPatternsIn Part II: Software Architecture AntiPatterns In Part III: Software Project Management

AntiPatterns

Page 3: Anti Patterns Siddhesh Lecture1 Of3

Pattern… Arrangement of repeated parts Design or shape to direct the

cutting of cloth Model or specimen

But a pattern can also be one of behavior!

Page 4: Anti Patterns Siddhesh Lecture1 Of3

AntiPattern… Tells you what to avoid Identification of what to avoid is a

critical factor in successful software development

AntiPatterns rampant in Software Development Architecture Management Behavior

Page 5: Anti Patterns Siddhesh Lecture1 Of3

Occur as a result of… Manager or developer not knowing

better Insufficient knowledge or

experience in solving a particular type of problem

Applying a perfectly good pattern in wrong context

Page 6: Anti Patterns Siddhesh Lecture1 Of3
Page 7: Anti Patterns Siddhesh Lecture1 Of3

“An AntiPattern is a literary form that describes a commonly occurring solution to a problem that generates decidedly negative consequences”

Page 8: Anti Patterns Siddhesh Lecture1 Of3

Questions How can I recognize the most

common software design mistakes? What can we do to fix bad software? How can we get our design process

on track? How do I know when I am being

misled by a vendor?

Page 9: Anti Patterns Siddhesh Lecture1 Of3

More Questions Is the latest standard or

technology breakthrough going to solve my problems?

Is our project headed for disaster? What are the “gotchas” of software

reuse?

Page 10: Anti Patterns Siddhesh Lecture1 Of3

Software Development AntiPatterns

Page 11: Anti Patterns Siddhesh Lecture1 Of3

AP: The Blob

“This is the class that is really the heart of our architecture”

Page 12: Anti Patterns Siddhesh Lecture1 Of3

Symptoms and Consequences Procedural-style design One object with lion’s share of

responsibility Others hold data or execute simple

processes Lack of cohesiveness Too complex for reuse and testing

Page 13: Anti Patterns Siddhesh Lecture1 Of3

Typical Causes Lack of architecture skills Prototypes developing into

production systems Defining system architecture as

part of requirements analysis

Page 14: Anti Patterns Siddhesh Lecture1 Of3

Known Exceptions Wrapping legacy systems Just make the system accessible

Page 15: Anti Patterns Siddhesh Lecture1 Of3

Solution Identify functionalities according to

“contracts” Find “natural homes” for these

collections of functionalities Remove redundant associations Top Down Approach: Migrate some

functionalities to the data classes

Page 16: Anti Patterns Siddhesh Lecture1 Of3

AP: Lava Flow

“Oh that! Well Ray and Emily wrote that routine back when Jim was trying a workaround for Irene’s input processing code. I don’t think it’s used anywhere now, but I am not sure. It isn’t really documented clearly, so just leave it alone”

Page 17: Anti Patterns Siddhesh Lecture1 Of3

Symptoms and Consequences Frequent unjustifiable variables

and code fragments Loose, “evolving” architecture Dead code or commented out

blocks

Page 18: Anti Patterns Siddhesh Lecture1 Of3

Typical Causes R&D code placed into production Uncontrolled distribution of

unfinished code Single developer written code Lack of configuration management Transient development teams Hasty changes on the fly

Page 19: Anti Patterns Siddhesh Lecture1 Of3

Known Exceptions Small-scale prototypes in R&D

environments Deliver rapidly and results not

required to be sustainable

Page 20: Anti Patterns Siddhesh Lecture1 Of3

Solution Ensure that sound architecture

precedes code development Configuration Management Curing existing problem is often

very painful

Page 21: Anti Patterns Siddhesh Lecture1 Of3

AP: Functional Decomposition

“This is our ‘main’ routine, here in the class called LISTENER”

Page 22: Anti Patterns Siddhesh Lecture1 Of3

Symptoms and Consequences Resembles procedural language in

class structure Classes with names like

“Calculate_Interest” is a sure indication

Classes with all private variables No inheritance Can result in incredibly complex code

Page 23: Anti Patterns Siddhesh Lecture1 Of3

Typical Causes Output of experienced non-object

oriented programmers who design an implement an OO application

Page 24: Anti Patterns Siddhesh Lecture1 Of3

Known Exceptions Fine when OO solution is not

required, and only required to give an OO interface to the implementation code

Page 25: Anti Patterns Siddhesh Lecture1 Of3

Solution Define analysis model to explain the

critical features of the system Formulate design model that

incorporates essential pieces Combine several classes that satisfy

a single design objective (Helper classes).

Rewrite classes with no state as function

Page 26: Anti Patterns Siddhesh Lecture1 Of3

AP: Poltergeists: Restless Ghosts

“I am not really sure what this class does, but it sure is important!”

Page 27: Anti Patterns Siddhesh Lecture1 Of3

Symptoms and Consequences Temporary, short duration objects Redundant navigation paths Transient associations Single-operation classes that “seed”

other classes Classes with “control-like” operation

names like “start_process_alpha”

Page 28: Anti Patterns Siddhesh Lecture1 Of3

Typical Causes Bad architecture or design Wrong tool for the job Architectural commitments during

requirements analysis

Page 29: Anti Patterns Siddhesh Lecture1 Of3

Known Exceptions No exceptions

Page 30: Anti Patterns Siddhesh Lecture1 Of3

Solution Remove these classes from the

hierarchy Add functionality in the related

classes they invoked

Page 31: Anti Patterns Siddhesh Lecture1 Of3

AP: Boat Anchor Piece of hardware or software that

serves no useful purpose on the current project

Page 32: Anti Patterns Siddhesh Lecture1 Of3

Typical Causes Policy or programmatic

relationship Starting assumption or constraint

in a project Commitment to product without

technical evaluation

Page 33: Anti Patterns Siddhesh Lecture1 Of3

Solution Keep technical backups during

evaluation phase Prototype with evaluation licenses Rational decision making prior to

acquisition

Page 34: Anti Patterns Siddhesh Lecture1 Of3

AP: Golden Hammer

“Maybe we shouldn’t have used Excel macros for this job after all”

Page 35: Anti Patterns Siddhesh Lecture1 Of3

Symptoms and Consequences Identical tools and products used for

wide array of conceptually diverse requirements

Inferior performance and scalability Developers debate requirements

with analysts and end users Existing products dictate design and

architecture

Page 36: Anti Patterns Siddhesh Lecture1 Of3

Typical Causes Familiar technology or concept

applied obsessively to many problems

Large investments made in training in a particular technology or product

Reliance on proprietary features

Page 37: Anti Patterns Siddhesh Lecture1 Of3

Known Exceptions If the product that defines the

constraint is the intended strategic solution for long term

Product is part of a vendor suite that provides for most of the software needs.

Page 38: Anti Patterns Siddhesh Lecture1 Of3

Solution Commitment to alternative

technologies and approaches Hiring people with diverse

backgrounds and experiences Exposure of developers to

technical developments

Page 39: Anti Patterns Siddhesh Lecture1 Of3

AP: Dead End Modified reusable component no

longer supported or maintained by the supplier

Shifts burden to the developer and maintainers

Upgrades cannot be easily integrated Support problems get blamed on

modifications

Page 40: Anti Patterns Siddhesh Lecture1 Of3

Known Exceptions Testbeds that support basic

research such as throwaway code Significant benefits through

customization

Page 41: Anti Patterns Siddhesh Lecture1 Of3

Solution Avoid COTS Customization and

modifications to reusable software Use mainstream platforms and

upgrade in sync with vendor Use isolation layers

Page 42: Anti Patterns Siddhesh Lecture1 Of3

AP: Spaghetti Code

“It’s easier to rewrite this code than attempt to modify it”

Page 43: Anti Patterns Siddhesh Lecture1 Of3

Symptoms and Consequences Very low reuse value Flow dictated by object

implementation, not by clients Minimal relationships between

objects Difficult to maintain and extend

Page 44: Anti Patterns Siddhesh Lecture1 Of3

Typical Causes Inexperience Ineffective code reviews No design prior to implementation Developers working in isolation

Page 45: Anti Patterns Siddhesh Lecture1 Of3

Known Exceptions Reasonably acceptable if

interfaces are coherent Lifetime of the code is short Product developed to obtain

domain knowledge for designing products with an improved architecture later on

Page 46: Anti Patterns Siddhesh Lecture1 Of3

Solution Code cleanup Term doesn’t appeal to managers,

so call it “software investment” Code cleanup should follow each

addition of feature Performance improvement is also

part of code cleanup

Page 47: Anti Patterns Siddhesh Lecture1 Of3

Examples of code cleanup Write accessor functions for use in

refactored code Convert code segments into

functions for reuse Reorder function arguments for

consistency Remove inaccessible or dead code Rename classes, functions, variables

Page 48: Anti Patterns Siddhesh Lecture1 Of3

AP: Input Kludge “End users can break new

programs within moments of touching the keyboard”

Use of ad hoc algorithms for handling program input

Solution: Use production-quality input algorithms like lexical analysis and parsing software

Page 49: Anti Patterns Siddhesh Lecture1 Of3

AP: Cut-and-Paste Programming

“Man, you guys work fast. Over 400,000 lines of code in three weeks is outstanding progress!”

“Hey, I thought you fixed that bug already, so why is it doing this again?”

Page 50: Anti Patterns Siddhesh Lecture1 Of3

Symptoms and Consequences Similar segments of code all over

the code base Duplication of testing, review, bug

fixing efforts

May have positive short-term consequences increased like line count

Page 51: Anti Patterns Siddhesh Lecture1 Of3

Typical Causes Degenerate form of software reuse:

Reusing source code Inexperienced programmers

following examples of other senior programmers

Taking working examples and modifying them

Organization rewards development speed, not reuse and overall design

Page 52: Anti Patterns Siddhesh Lecture1 Of3

Known Exceptions When the sole aim is to get the

code out of the door as quickly as possible

However, price paid is one of increased maintenance

Page 53: Anti Patterns Siddhesh Lecture1 Of3

Solution Black box reuse

Page 54: Anti Patterns Siddhesh Lecture1 Of3

In Part II and III… Software Architecture AntiPatterns Software Project Management

AntiPatterns

Page 55: Anti Patterns Siddhesh Lecture1 Of3

References AntiPatterns: William Brown,

Raphael Malveau et al (PSPL Library S-76)

http://www.antipatterns.com/thebook.htm

Similar presentation at http://www.mitre.org/support/swee/html/67_mccormick

Page 56: Anti Patterns Siddhesh Lecture1 Of3

Thank You!