the benefit of sneezing code into an editor vs clean code

63
The Benefit of Sneezing Code Into an Editor vs Clean Code #sneezingcode joind.in/11457 @dave1010 Dave Hulbert

Upload: dave1010uk

Post on 01-Jul-2015

378 views

Category:

Software


0 download

DESCRIPTION

Balancing technical debt and getting things done is one of the hardest problems we have. When should we write beautiful, elegant, clean code and when should we just hammer away blindly at the keyboard until it's done? This talk goes in to why this balance is so difficult and covers everything from estimations to refactoring and testing, with a focus on real world PHP apps.

TRANSCRIPT

Page 1: The benefit of sneezing code into an editor vs clean code

The Benefit of Sneezing Code Into an Editor vs Clean Code

#sneezingcodejoind.in/11457

@dave1010Dave Hulbert

Page 2: The benefit of sneezing code into an editor vs clean code

@dave1010Dave Hulbert

Page 3: The benefit of sneezing code into an editor vs clean code

The Benefit of Sneezing Code Into an Editor vs Clean Code

Page 4: The benefit of sneezing code into an editor vs clean code

The Benefit of Sneezing Code Into an Editor vs Clean Code

Page 5: The benefit of sneezing code into an editor vs clean code

The Benefit of Sneezing Code Into an Editor vs Clean Code

Page 6: The benefit of sneezing code into an editor vs clean code

Balance

Page 7: The benefit of sneezing code into an editor vs clean code

Balance

Page 8: The benefit of sneezing code into an editor vs clean code

Balance

Page 9: The benefit of sneezing code into an editor vs clean code

Balance

Page 10: The benefit of sneezing code into an editor vs clean code

Delivering fast is good

Page 11: The benefit of sneezing code into an editor vs clean code

Good code is good

Page 12: The benefit of sneezing code into an editor vs clean code

Analogy

Page 13: The benefit of sneezing code into an editor vs clean code
Page 14: The benefit of sneezing code into an editor vs clean code

Aims

● How to run fast (in general)● How to sprint (sneeze)● How to run a marathon (clean code)● Why you should sprint● Why you should run a marathon

Page 15: The benefit of sneezing code into an editor vs clean code

How to run fast (in general)

● Developers– Skilled, Passionate, Healthy, Focused, Disciplined– (Relevant) conferences, user groups (hello)– Read books, blogs, code– Write code, Open Source contributions

Page 16: The benefit of sneezing code into an editor vs clean code

How to run fast (in general)

● Projects– Good communication– Good specifications / requirements– Fast feedback– Good clients

Page 17: The benefit of sneezing code into an editor vs clean code
Page 18: The benefit of sneezing code into an editor vs clean code

How to run slow (in general)

● Complexity– Code / System

● Bad / slow / no tests● Bugs● Lack of investment

– Servers / Workstations / Software

Page 19: The benefit of sneezing code into an editor vs clean code

How to run slow (in general)

● Interruptions● Being blocked / waiting● Internal processes● Too many meetings

Page 20: The benefit of sneezing code into an editor vs clean code

Aims

● How to run fast (in general)● How to sprint (sneeze)● How to run a marathon (clean code)● Why you should sprint● Why you should run a marathon

Page 21: The benefit of sneezing code into an editor vs clean code

How to sprint (sneeze)

● What is sprinting?

Page 22: The benefit of sneezing code into an editor vs clean code

How to sprint (sneeze)

● Overtime● Ignore everything else● Reduce tests / testing● Reduce planning● Reduce communication● Outsource● Cut corners● Focus; don't improve tools / processes● Outsource

Page 23: The benefit of sneezing code into an editor vs clean code
Page 24: The benefit of sneezing code into an editor vs clean code
Page 25: The benefit of sneezing code into an editor vs clean code
Page 26: The benefit of sneezing code into an editor vs clean code

Technical Debt

● What is technical debt?

Page 27: The benefit of sneezing code into an editor vs clean code
Page 28: The benefit of sneezing code into an editor vs clean code
Page 29: The benefit of sneezing code into an editor vs clean code

Causes of technical debt

● Deciding to release before it's ready● Deciding to use a RAD framework● Deciding to skip tests & documentation● Lack of understanding (requirements, code)● Premature optimisation● Software entropy

Page 30: The benefit of sneezing code into an editor vs clean code

Consequences of technical debt

● Interest; interest on interest● More time on maintenance● Less time on new features● Harder to estimate new features● Miss deadlines

Page 31: The benefit of sneezing code into an editor vs clean code
Page 32: The benefit of sneezing code into an editor vs clean code
Page 33: The benefit of sneezing code into an editor vs clean code

Aims

● How to run fast (in general)● How to sprint (sneeze)● How to run a marathon (clean code)● Why you should sprint● Why you should run a marathon

Page 34: The benefit of sneezing code into an editor vs clean code

How to run a marathon(clean code)

● Non-code speed-ups: time & money investment– Staff training– Tools and processes– Planning / requirements

Page 35: The benefit of sneezing code into an editor vs clean code
Page 36: The benefit of sneezing code into an editor vs clean code
Page 37: The benefit of sneezing code into an editor vs clean code
Page 38: The benefit of sneezing code into an editor vs clean code

How to run a marathon(clean code)

● Clean Code (Uncle Bob)– SOLID

● TDD– Run every bit of code that you write, ASAP

● DDD– Model the domain completely in PHP classes that

don't touch the UI, database or framework

Page 39: The benefit of sneezing code into an editor vs clean code
Page 40: The benefit of sneezing code into an editor vs clean code
Page 41: The benefit of sneezing code into an editor vs clean code
Page 42: The benefit of sneezing code into an editor vs clean code

Refactoring

Page 43: The benefit of sneezing code into an editor vs clean code

Refactoring

● Key to keeping up speed in big projects● Restructuring without changing behaviour● No direct measurable user benefit (not a user

story)● Makes it easier to read, understand, test,

change, add new features to● IDE makes refactoring easier

Page 44: The benefit of sneezing code into an editor vs clean code
Page 45: The benefit of sneezing code into an editor vs clean code

Refactoring

● Inject dependencies● Decouple (fewer “use” statements)● Create interfaces to type hint to● Extract functions● Rename● Reduce cyclomatic complexity (number of

if/else/for/foreach/while/switch in a method)● Change depth of inheritance

Page 46: The benefit of sneezing code into an editor vs clean code
Page 47: The benefit of sneezing code into an editor vs clean code

Examples

● Journey Planner● User API

Page 48: The benefit of sneezing code into an editor vs clean code

Aims

● How to run fast (in general)● How to sprint (sneeze)● How to run a marathon (clean code)● Why you should sprint● Why you should run a marathon

Page 49: The benefit of sneezing code into an editor vs clean code

Why you should sprint

● Help you deliver faster in the short term● Long term strategy● MVP (prove a theory)● Disposable prototype

Page 50: The benefit of sneezing code into an editor vs clean code

Why you should sprint

● Treat your servers like cattle, not pets● Sometimes code is similar

Page 51: The benefit of sneezing code into an editor vs clean code
Page 52: The benefit of sneezing code into an editor vs clean code

Examples

● Laravel– RAD framework– Sacrifices SOLID code (a bit) for ease of use– Static “facades” (instead of using injected

dependencies)– $user->save() (instead of $userRepository-

>persist($user) )

Page 53: The benefit of sneezing code into an editor vs clean code

Examples

● WordPress– “5 minute install”– Low barrier to entry– Lots of themes and plugins

Page 54: The benefit of sneezing code into an editor vs clean code

Aims

● How to run fast (in general)● How to sprint (sneeze)● How to run a marathon (clean code)● Why you should sprint● Why you should run a marathon

Page 55: The benefit of sneezing code into an editor vs clean code

Why you should run a marathon

● Technical debt is a risk– Especially with big projects

● Quality is valuable● Deliver faster in the long term

Page 56: The benefit of sneezing code into an editor vs clean code

Aims

● How to run fast (in general)● How to sprint (sneeze)● How to run a marathon (clean code)● Why you should sprint● Why you should run a marathon

Page 57: The benefit of sneezing code into an editor vs clean code

Sprint vs Marathon

Sprint (example) Marathon (example)

Peripheral component (logs) Central component (DB)

Trivial (make a CSV) Complex (search algorithm)

Few consequences of bugs (game) Important (nuclear reactor)

Isolated (contact form) Reused (authentication)

Abandonable (migration script) Continued updates

One developer Big team

Time & money to pay technical debt later

Long term delivery

Page 58: The benefit of sneezing code into an editor vs clean code

Bonus: estimating

● Estimates for new features need to include refactoring– (if you don't want to increase technical debt)– Refactoring doesn't add perceived value so it's

hard to sell● Technical debt is expensive

– Sprint + paying technical debt interest costs more than running a marathon + continual refactoring

Page 59: The benefit of sneezing code into an editor vs clean code

Bonus: Testing

● TDD is about running your code ASAP● Write a test when you fix a bug● Fix bugs before writing new code (The Joel

Test)

Page 60: The benefit of sneezing code into an editor vs clean code

Wish list

● A script to track TODOs over time (Jenkins?)● A tool that helps you decide whether to

sprint or run a marathon

Page 61: The benefit of sneezing code into an editor vs clean code

Resources

● Books that I've read at least a few chapters of– Mythical Man-Month: Essays on Software Engineering,

Frederick Brooks– Clean Code: A Handbook of Agile Software

Craftsmanship, Robert C Martin– Implementing Domain-Driven Design, Vaughn Vernon– Modernizing Legacy Applications In PHP, Paul M.

Jones– More: http://amzn.to/Y29TAK

Page 62: The benefit of sneezing code into an editor vs clean code

Resources

● Refactoring http://refactoring.com/catalog/● Speed in Software Development

http://www.targetprocess.com/articles/speed-in-software-development.html

● Technical debt http://www.construx.com/10x_Software_Development/Technical_Debt/

● Images: HBO, Reddit, XKCD, the Internet

Page 63: The benefit of sneezing code into an editor vs clean code

Thanks!

#sneezingcode

joind.in/11457

@dave1010

Dave Hulbert