62
Preparing to write Clean Code

Preparing to write Clean Code

Embed Size (px)

DESCRIPTION

This is the version I gave at Utah Code Camp on 23 March 2013 in Salt Lake City, UT. Feel free to use it and adapt it to your group's needs.

Citation preview

Page 1: Preparing to write Clean Code

Preparing to write Clean Code

Page 2: Preparing to write Clean Code

The Clean Code Manifesto

Page 3: Preparing to write Clean Code

Preparing to writeClean Code

David Adsit@davidadsit

codeobsession.blogspot.com

Page 4: Preparing to write Clean Code

How to write Clean Code:

Page 5: Preparing to write Clean Code

How to write Clean Code:

Phase 1:Know what Clean

Code is

Phase 2:???

Phase 3:Profit!

Page 6: Preparing to write Clean Code

What is Clean Code?

Page 7: Preparing to write Clean Code

What is Clean Code?

Page 8: Preparing to write Clean Code

What is Clean Code?

Page 9: Preparing to write Clean Code

What is Clean Code?

“Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer’s intent but rather is full of crisp abstractions and straightforward lines of control.”

- Grady Booch

Page 10: Preparing to write Clean Code

What is Clean Code?

“With a ubiquitous language, conversations among developers, discussions among domain experts, and expressions in the code itself are all based on the same language, derived from a shared domain model.”

- Eric Evans

Page 11: Preparing to write Clean Code

What is Clean Code?

CleanCode

LegacyCode

Page 12: Preparing to write Clean Code

What is Legacy Code?“To me, legacy code is simply code without tests.…Code without tests is bad code. It doesn't matter how well written it is; it doesn't matter how pretty or object-oriented or well-encapsulated it is. With tests, we can change the behavior of our code quickly and verifiably.Without them, we really don't know if our code is getting better or worse.”

- Michael Feathers

Page 13: Preparing to write Clean Code

Attributes of Clean Code

Names of Classes and Methods should Reveal Intention

Comments should be rare and only used to explain why

Page 14: Preparing to write Clean Code

Attributes of Clean Code

Names of Classes and Methods should Reveal Intention

Comments should be rare and only used to explain why Formatting should be consistent

Page 15: Preparing to write Clean Code

Attributes of Clean Code

Names of Classes and Methods should Reveal Intention

Comments should be rare and only used to explain why Formatting should be consistent

Challenge: Create an editor that stores code as data in a canonical format and renders based on each developers’ preferences

Page 16: Preparing to write Clean Code

Attributes of Clean Code

Names of Classes and Methods should Reveal Intention

Comments should be rare and only used to explain why Formatting should be consistent

Challenge: Create an editor that stores code as data in a canonical format and renders based on each developers’ preferences

Classes and Methods should be small and focused The contents should not be surprising

Page 17: Preparing to write Clean Code

Attributes of Clean Code

Names of Classes and Methods should Reveal Intention

Comments should be rare and only used to explain why Formatting should be consistent

Challenge: Create an editor that stores code as data in a canonical format and renders based on each developers’ preferences

Classes and Methods should be small and focused The contents should not be surprising

Classes should have and express a clear role Object != Value Type != Service != Data Transfer Object/View

Model

Page 18: Preparing to write Clean Code

Attributes of Clean Code

Names of Classes and Methods should Reveal Intention

Comments should be rare and only used to explain why Formatting should be consistent

Challenge: Create an editor that stores code as data in a canonical format and renders based on each developers’ preferences

Classes and Methods should be small and focused The contents should not be surprising

Classes should have and express a clear role Object != Value Type != Service != Data Transfer Object/View

Model Boundaries should be clear

Reuse/3rd party libraries can be great! Protect your code with adapters

Page 19: Preparing to write Clean Code

Attributes of Clean Code

TESTED!

Page 20: Preparing to write Clean Code

The Full Test Suite

Page 21: Preparing to write Clean Code

The Full Test Suite

Unit Tests

Integration Tests

Acceptance Tests

UI Tests

Page 22: Preparing to write Clean Code

The Full Test Suite

Unit Tests

Integration Tests

Acceptance Tests

UI Tests

Page 23: Preparing to write Clean Code

The Full Test Suite

Unit Tests

Integration Tests

Acceptance Tests

UI Tests

Page 24: Preparing to write Clean Code

The Full Test Suite

Unit Tests

Integration Tests

Acceptance Tests

UI Tests

Page 25: Preparing to write Clean Code

That all sounds great but…

Page 26: Preparing to write Clean Code

That all sounds great but…

Page 27: Preparing to write Clean Code

That all sounds great but…

Page 28: Preparing to write Clean Code

That all sounds great but…

The Boy Scout Rule (for Code)

Leave the code cleaner than you found it.

Page 29: Preparing to write Clean Code

How to write Clean Code:

Phase 1:Know what

Clean Code is

Phase 2:Continuous

Improvement

Phase 3:Profit!

Page 30: Preparing to write Clean Code

The Long Road

“How long will it take to master aikido?” a prospective student asks. “How long do you expect to live?” is the only respectable response.

- George LeonardMastery

Page 31: Preparing to write Clean Code

The Long Road

“To become truly good at programming is a life’s work, an ongoing enterprise of learning and practicing.”

- Ron Jeffries et al. Extreme Programming Installed

Page 32: Preparing to write Clean Code

Kindred Spirits

Page 33: Preparing to write Clean Code

Utah Software Craftsmanship Group

We meet on the first Wednesday of each month from 6pm to 8pm at:

Neumont UniversityRoom 300

10701 S. Riverfront ParkwaySouth Jordan, Utah 84095

https://groups.google.com/forum/?fromgroups#!forum/ut-software-craftsmanship

( http://bit.ly/utahsc )

Page 34: Preparing to write Clean Code

The Utah SC Group Meeting

Lightning talks 1-3 / month 5-7 minutes max

Page 35: Preparing to write Clean Code

The Utah SC Group Meeting

Lightning talks 1-3 / month 5-7 minutes max

Discussion Large or small groups

Page 36: Preparing to write Clean Code

The Utah SC Group Meeting

Lightning talks 1-3 / month 5-7 minutes max

Discussion Large or small groups

Coding exercise Katas Randori Experiments Language demos

Page 37: Preparing to write Clean Code

The Utah SC Group Meeting

Lightning talks 1-3 / month 5-7 minutes max

Discussion Large or small groups

Coding exercise Katas Randori Experiments Language demos

Pie!

Page 38: Preparing to write Clean Code

As Seen on TV!!

Page 39: Preparing to write Clean Code

Software Craftsmanship Manifesto

As aspiring Software Craftsmen we are raising the bar of professional software development by practicing it and helping others learn the craft. Through this work we have come to value:

Not only working software, but also well-crafted software Not only responding to change, but also steadily adding val

ue Not only individuals and interactions, but also a communit

y of professionals Not only customer collaboration, but also productive/

partnerships

That is, in pursuit of the items on the left, we have found the items on the right to be indispensable.

Page 40: Preparing to write Clean Code

Professionalism

Responsibility Do no harm to function Do no harm to structure

Page 41: Preparing to write Clean Code

Professionalism

Responsibility Do no harm to function Do no harm to structure

Honesty Yes No Estimates

Page 42: Preparing to write Clean Code

Professionalism

Responsibility Do no harm to function Do no harm to structure

Honesty Yes No Estimates

Readiness Study Practice

Page 43: Preparing to write Clean Code

Professionalism

Responsibility Do no harm to function Do no harm to structure

Honesty Yes No Estimates

Readiness Study Practice

Mentorship Find a mentor Be a mentor

Page 44: Preparing to write Clean Code

3 Great Virtues

"We will encourage you to develop the three great virtues of a programmer: laziness, impatience, and hubris.“

- Larry Wall

Page 45: Preparing to write Clean Code

Laziness

The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful, and document what you wrote so you don't have to answer so many questions about it. Hence, the first great virtue of a programmer.

Page 46: Preparing to write Clean Code

Impatience

The anger you feel when the computer is being lazy. This makes you write programs that don't just react to your needs, but actually anticipate them. Or at least pretend to. Hence, the second great virtue of a programmer.

Page 47: Preparing to write Clean Code

Hubris

Excessive pride, the sort of thing Zeus zaps you for. Also the quality that makes you write (and maintain) programs that other people won't want to say bad things about. Hence, the third great virtue of a programmer.

Page 48: Preparing to write Clean Code

Make the Computer do the Work

Use source control There’s no excuse not to

Page 49: Preparing to write Clean Code

Make the Computer do the Work

Use source control There’s no excuse not to

Get a refactoring tool Computers are better at mundane, repetitive tasks than people

are

Page 50: Preparing to write Clean Code

Make the Computer do the Work

Use source control There’s no excuse not to

Get a refactoring tool Computers are better at mundane, repetitive tasks than people

are Eliminate manual build steps

Don’t forget the database

Page 51: Preparing to write Clean Code

Make the Computer do the Work

Use source control There’s no excuse not to

Get a refactoring tool Computers are better at mundane, repetitive tasks than people

are Eliminate manual build steps

Don’t forget the database Automate the verification process

Page 52: Preparing to write Clean Code

Make the Computer do the Work

Use source control There’s no excuse not to

Get a refactoring tool Computers are better at mundane, repetitive tasks than people

are Eliminate manual build steps

Don’t forget the database Automate the verification process Push-button deployment / rollback

Page 53: Preparing to write Clean Code

Teamwork

Page 54: Preparing to write Clean Code

Strengthen Your Team

Start Pair Programming The most efficient way to improve the code is to test it The most efficient way to improve a team is to pair

Page 55: Preparing to write Clean Code

Strengthen Your Team

Start Pair Programming The most efficient way to improve the code is to test it The most efficient way to improve a team is to pair

Start a study group at work Read a chapter from a relevant book and discuss it

Page 56: Preparing to write Clean Code

Strengthen Your Team

Start Pair Programming The most efficient way to improve the code is to test it The most efficient way to improve a team is to pair

Start a study group at work Read a chapter from a relevant book and discuss it

Go to a conference Share what you learned

Page 57: Preparing to write Clean Code

Strengthen Your Team

Start Pair Programming The most efficient way to improve the code is to test it The most efficient way to improve a team is to pair

Start a study group at work Read a chapter from a relevant book and discuss it

Go to a conference Share what you learned

Find a user group Attend monthly

Page 58: Preparing to write Clean Code

Strengthen Your Team

Start Pair Programming The most efficient way to improve the code is to test it The most efficient way to improve a team is to pair

Start a study group at work Read a chapter from a relevant book and discuss it

Go to a conference Share what you learned

Find a user group Attend monthly

Follow interesting developers online Google Reader is dead, but blogs aren’t and neither is Twitter

Page 59: Preparing to write Clean Code

Strengthen Your Team

Start Pair Programming The most efficient way to improve the code is to test it The most efficient way to improve a team is to pair

Start a study group at work Read a chapter from a relevant book and discuss it

Go to a conference Share what you learned

Find a user group Attend monthly

Follow interesting developers online Google Reader is dead, but blogs aren’t and neither is Twitter

Create your own reading list Some concepts are too big for a blog post and require a book

to explore The more you know, the more you can share with your team

Page 60: Preparing to write Clean Code

How to write Clean Code:

Phase 1:Know what

Clean Code is

Phase 2:Continuous

Improvement

Phase 3:Profit!

Page 61: Preparing to write Clean Code

Visit the sponsors

Don’t forget rate the speakers very highly!

Page 62: Preparing to write Clean Code

Questions?

David Adsit@davidadsit

codeobsession.blogspot.com