pycon 2015 - technical debt - the monster in your closet

73

Click here to load reader

Upload: nina-zakharenko

Post on 14-Jul-2015

51.050 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Pycon 2015 - Technical Debt - The Monster in Your Closet

TECHNICAL DEBT !

THE CODE MONSTER IN YOUR CLOSET

Nina Zakharenko@nnja

Page 2: Pycon 2015 - Technical Debt - The Monster in Your Closet

WHAT IS TECHNICAL

DEBT?

Page 3: Pycon 2015 - Technical Debt - The Monster in Your Closet

(BOTH BUSINESS & TECHNICAL)

A SERIES OF BAD DECISIONS

Page 4: Pycon 2015 - Technical Debt - The Monster in Your Closet

WHICH LEAD TOERROR PRONE CODE

& ARCHITECTURE

Page 5: Pycon 2015 - Technical Debt - The Monster in Your Closet

… AND USING MORE

TO ACCOMPLISHRESOURCES

LESS

Page 6: Pycon 2015 - Technical Debt - The Monster in Your Closet

What decisions were made in the past

Page 7: Pycon 2015 - Technical Debt - The Monster in Your Closet

that prevent me from getting sh** done today?

Page 8: Pycon 2015 - Technical Debt - The Monster in Your Closet

WHAT CAUSES IT?

Page 9: Pycon 2015 - Technical Debt - The Monster in Your Closet

ME.AND YOU.

Page 10: Pycon 2015 - Technical Debt - The Monster in Your Closet

Mistakes I Made Early On

Not knowing how to say NO to features

Not seeing the value in Unit Tests

Page 11: Pycon 2015 - Technical Debt - The Monster in Your Closet

Mistakes I Made Early On

Overly Optimistic Estimates

Putting releases over good design & reusable code

Page 12: Pycon 2015 - Technical Debt - The Monster in Your Closet

TIME CRUNCH

The project was due yesterday!

I’ll take a shortcut, and clean up the mess tomorrow.

Page 13: Pycon 2015 - Technical Debt - The Monster in Your Closet

UNNEEDED COMPLEXITY

Lines of code committed != amount of work accomplished.

Page 14: Pycon 2015 - Technical Debt - The Monster in Your Closet

Step 1: Have a problem.

Step 2: Look up How to do it on Stack Exchange

LACK OF UNDERSTANDING

Step 3: Copy and Paste it into your codebase

Step 4: ???

Step 5: Bugs!

Page 15: Pycon 2015 - Technical Debt - The Monster in Your Closet

CULTURE OF DESPAIR

This is already a heap of trash.

Will anyone really notice if I add something to the top?

Page 16: Pycon 2015 - Technical Debt - The Monster in Your Closet

RED FLAGSHouston, We Have a Problem.

Page 17: Pycon 2015 - Technical Debt - The Monster in Your Closet

CODE SMELLS?

Not bugs.

An indication of a deeper problem.

Page 18: Pycon 2015 - Technical Debt - The Monster in Your Closet

CODE SMELLS

• Half implemented features • No or poor documentation

Page 19: Pycon 2015 - Technical Debt - The Monster in Your Closet

CODE SMELLS

• Commented out code, incorrect comments • No tests or broken tests

Page 20: Pycon 2015 - Technical Debt - The Monster in Your Closet

POOR DOCUMENTATIONclass OrganicGlutenFreePizzaFactory: def get_dough(self): """         Return amazing, organic, GMO and Gluten Free Dough         """ # ran out of organic gluten free, use the other stuff. !

# return 'organic gluten free dough' return 'gmo white pesticide dough'

Page 21: Pycon 2015 - Technical Debt - The Monster in Your Closet

ARCHITECTURE & DESIGN… SMELLS

• Parts of the code that no one wants to touch • Changing code in one area breaks other parts of the

system • Severe outages caused by frequent & unexpected

bugs

Page 22: Pycon 2015 - Technical Debt - The Monster in Your Closet

GOOD DESIGNImplementing new features comes easily.

BAD DESIGNShoe-horning new features into the system.

Page 23: Pycon 2015 - Technical Debt - The Monster in Your Closet

PYTHON SPECIFIC SMELLS

Page 24: Pycon 2015 - Technical Debt - The Monster in Your Closet

Functionality Changes, Variable names Don’t.

employees = ['John', 'Mary', 'Dale'] !

employees = 'Bob' !

employees[0]

Page 25: Pycon 2015 - Technical Debt - The Monster in Your Closet

Monkey Patching

def new_init(self): pass !

some_library.SomeClass.__init__ = new_init

Page 26: Pycon 2015 - Technical Debt - The Monster in Your Closet

What exactly does that decorator do?def decorator_evil(target): return False !

@decorator_evil def target(a,b): return a + b !

>>> target False !

>>> target(1,2) TypeError: 'bool' object is not callable

Page 27: Pycon 2015 - Technical Debt - The Monster in Your Closet

Circular Dependencies

def some_function(x): from some.module import some_method some_method(x)

Page 28: Pycon 2015 - Technical Debt - The Monster in Your Closet

CASE STUDIES

Page 29: Pycon 2015 - Technical Debt - The Monster in Your Closet

IRS CHIEF:

"We Still Have Applications That Were Running When JFK Was President"

Page 30: Pycon 2015 - Technical Debt - The Monster in Your Closet

50 Year old Technology

"And we continue to use the COBOL programming language, it is extremely difficult to find IT experts who

are versed in this language.”

Page 31: Pycon 2015 - Technical Debt - The Monster in Your Closet

It’s not just the IRS.

Banks & Financial Insitutions Universities

Air Traffic Control !

… all use COBOL.

Page 32: Pycon 2015 - Technical Debt - The Monster in Your Closet

STORY TIME

I used to work in finance.

At the time I was there, all of the banking systems were run on mainframes.

The bankers were getting frustrated. They wanted a UI.

Page 33: Pycon 2015 - Technical Debt - The Monster in Your Closet

IDEA!

Let’s write a fancy new web front end.

It’ll do ALL the things.

Page 34: Pycon 2015 - Technical Debt - The Monster in Your Closet

BUT

Rewriting the backend is too expensive. !

It already does what we need. !

Let’s leave the mainframe.

Page 35: Pycon 2015 - Technical Debt - The Monster in Your Closet

CURSORS

The mainframe would output a text screen from a program result, based on a query.

The results would be parsed by reading variables from the screen in certain positions.

Page 36: Pycon 2015 - Technical Debt - The Monster in Your Closet

RESULT?

The new system was incredibly slow.

And error prone.!

After months of work, the multi-million dollar rewrite was scrapped.

Page 37: Pycon 2015 - Technical Debt - The Monster in Your Closet

YOU CAN PUT LIPSTICK ON A PIG

Page 38: Pycon 2015 - Technical Debt - The Monster in Your Closet

THE MVP

(Minimum Viable Product)

Get the product to early customers as soon as possible.

Page 39: Pycon 2015 - Technical Debt - The Monster in Your Closet

A GREAT IDEA

I worked on a project that was created by a lone developer in a coffee fueled 48 hours.

It was a great success.

Page 40: Pycon 2015 - Technical Debt - The Monster in Your Closet

THERE WAS A PROBLEMYears went on, but the initial code and design didn’t go

away.Instead, it became the base for an expanding project,

with expanding features.

Worse, there was never any time to refactor.

Page 41: Pycon 2015 - Technical Debt - The Monster in Your Closet

SCOPE CREEP

Features that someone thought was a good idea one day, stuck around forever.

“In case we need them. Later.”

Page 42: Pycon 2015 - Technical Debt - The Monster in Your Closet

SAD DEVELOPERS

That made it feel like your fault.

When a release was pushed, something was bound to break.

There were no working tests.

Page 43: Pycon 2015 - Technical Debt - The Monster in Your Closet

GRINDING TO A HALT

Development time for new features skyrocketed.

The project was deemed too difficult to maintain.

… and cancelled.

Page 44: Pycon 2015 - Technical Debt - The Monster in Your Closet

SOMETIMES YOU NEED TO BURN IT. WITH FIRE.

Page 45: Pycon 2015 - Technical Debt - The Monster in Your Closet

BATTLING THE MONSTER

Page 46: Pycon 2015 - Technical Debt - The Monster in Your Closet

Technical Debt is a team-wide problem.

Everybody needs to be a part of the solution.

DON’T POINT FINGERS

Page 47: Pycon 2015 - Technical Debt - The Monster in Your Closet

WORK TOGETHER

Code Standards

Pair Programming

Code Reviews

Page 48: Pycon 2015 - Technical Debt - The Monster in Your Closet

Unless something is on fire, or you’re losing money, unreviewed code should never be merged into master.

Page 49: Pycon 2015 - Technical Debt - The Monster in Your Closet

STAY ACCOUNTABLEUnit & Integration Tests

Pre-Commit Hooks

Continuous Integration

Page 50: Pycon 2015 - Technical Debt - The Monster in Your Closet

SELL IT TO MANAGEMENT

By allocating some project time to tackling debt, the end result will be less error prone, easier to maintain,

and easier to add features to.

Page 51: Pycon 2015 - Technical Debt - The Monster in Your Closet

TIME

COST

Source: https://msdn.microsoft.com/en-us/magazine/ee819135.aspx

NOT BROKEN, WHY FIX IT?

Page 52: Pycon 2015 - Technical Debt - The Monster in Your Closet

SKI RENTAL PROBLEM

You’re going skiing for an unknown number of days. !

It costs $1 a day to rent, or $10 to buy.

Source: http://en.wikipedia.org/wiki/Ski_rental_problem

Page 53: Pycon 2015 - Technical Debt - The Monster in Your Closet

Technical debt frustrates developers.

Frustrated developers are more likely to leave.

THERE’S ANOTHER COST

Hiring developers is hard.

Page 54: Pycon 2015 - Technical Debt - The Monster in Your Closet

Figure out the project tolerance and work with it.

Don’t be a perfectionist.

Some lingering technical debt is inevitable.

Page 55: Pycon 2015 - Technical Debt - The Monster in Your Closet

Use these arguments to justify the additional time it takes you to do things right.

Page 56: Pycon 2015 - Technical Debt - The Monster in Your Closet

“Always code as if the guy who ends up maintaining your code will be a violent

psychopath who knows where you live.”

- Martin Golding@

Page 57: Pycon 2015 - Technical Debt - The Monster in Your Closet

TO WIN THE FIGHT

PAY DOWN YOUR DEBT

Page 58: Pycon 2015 - Technical Debt - The Monster in Your Closet

PRIORITIZE

What causes the biggest & most frequent pain points for developers?

Page 59: Pycon 2015 - Technical Debt - The Monster in Your Closet

What is the life expectancy of this project?

longer shelf life —> higher interest

SHELF LIFE

Page 60: Pycon 2015 - Technical Debt - The Monster in Your Closet

Just like with monetary debt, pay off the high interest loan first.

Page 61: Pycon 2015 - Technical Debt - The Monster in Your Closet

If you don’t have to pay it off, you got something for nothing.

Technical Debt can be strategic.

Page 62: Pycon 2015 - Technical Debt - The Monster in Your Closet

Is the single greatest tool in your toolbox.

REFACTORING

Page 63: Pycon 2015 - Technical Debt - The Monster in Your Closet

Systematically changing the code without changing functionality, while improving design and readability.

WHAT IS IT?

Page 64: Pycon 2015 - Technical Debt - The Monster in Your Closet

Slow and steady wins the race.

REFACTORING

The end goal is to refactor, without breaking existing functionality.

Page 65: Pycon 2015 - Technical Debt - The Monster in Your Closet

Replace functions and modules incrementally.

REFACTORING

Test as you go.

Tests are MANDATORY at this step.

Page 66: Pycon 2015 - Technical Debt - The Monster in Your Closet

How you make time for refactoring depends on the size of your team.

MAKING TIME

(And the size of your problem)

Page 67: Pycon 2015 - Technical Debt - The Monster in Your Closet

Devote a week every 6 - 8 weeks.SMALL

MEDIUMDevote a person per week, rotate.

LARGEEveryone devotes 10% of their time.

Page 68: Pycon 2015 - Technical Debt - The Monster in Your Closet

A FEW LAST TIPS

Page 69: Pycon 2015 - Technical Debt - The Monster in Your Closet

CODE IS FOR HUMANS

Source: http://despairsoftware.blogspot.com/2014/05/engineering-principles-software-best.html

Despite common misconception, code is not for computers.

!

Code is for humans to read.

Page 70: Pycon 2015 - Technical Debt - The Monster in Your Closet

DON’T REPEAT YOURSELF

Source: http://despairsoftware.blogspot.com/2014/05/engineering-principles-software-best.html

If being DRY requires mind-bending backflips and abstractions, stop.

(BUT)

Page 71: Pycon 2015 - Technical Debt - The Monster in Your Closet

THE BOY SCOUT RULEThe Boy Scouts have a rule: "Always leave the

campground cleaner than you found it."

Source: http://programmer.97things.oreilly.com/wiki/index.php/The_Boy_Scout_Rule

"Always check a module in cleaner than when you checked it out."

Page 72: Pycon 2015 - Technical Debt - The Monster in Your Closet

EXPECT TO BE FRUSTRATEDThe process of cleaning up days / months / years

of bad code can be analogous with untangling a ball of yarn.

!

Don’t give up.

Page 73: Pycon 2015 - Technical Debt - The Monster in Your Closet

THANK YOU!I’m Nina Zakharenko

@nnja /nnja

[email protected]!

"#