preparing to write clean code

Post on 23-Jun-2015

247 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

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.

TRANSCRIPT

Preparing to write Clean Code

The Clean Code Manifesto

Preparing to writeClean Code

David Adsit@davidadsit

codeobsession.blogspot.com

How to write Clean Code:

How to write Clean Code:

Phase 1:Know what Clean

Code is

Phase 2:???

Phase 3:Profit!

What is Clean Code?

What is Clean Code?

What is 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

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

What is Clean Code?

CleanCode

LegacyCode

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

Attributes of Clean Code

Names of Classes and Methods should Reveal Intention

Comments should be rare and only used to explain why

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

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

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

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

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

Attributes of Clean Code

TESTED!

The Full Test Suite

The Full Test Suite

Unit Tests

Integration Tests

Acceptance Tests

UI Tests

The Full Test Suite

Unit Tests

Integration Tests

Acceptance Tests

UI Tests

The Full Test Suite

Unit Tests

Integration Tests

Acceptance Tests

UI Tests

The Full Test Suite

Unit Tests

Integration Tests

Acceptance Tests

UI Tests

That all sounds great but…

That all sounds great but…

That all sounds great but…

That all sounds great but…

The Boy Scout Rule (for Code)

Leave the code cleaner than you found it.

How to write Clean Code:

Phase 1:Know what

Clean Code is

Phase 2:Continuous

Improvement

Phase 3:Profit!

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

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

Kindred Spirits

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 )

The Utah SC Group Meeting

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

The Utah SC Group Meeting

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

Discussion Large or small groups

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

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!

As Seen on TV!!

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.

Professionalism

Responsibility Do no harm to function Do no harm to structure

Professionalism

Responsibility Do no harm to function Do no harm to structure

Honesty Yes No Estimates

Professionalism

Responsibility Do no harm to function Do no harm to structure

Honesty Yes No Estimates

Readiness Study Practice

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

3 Great Virtues

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

- Larry Wall

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.

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.

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.

Make the Computer do the Work

Use source control There’s no excuse not to

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

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

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

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

Teamwork

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

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

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

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

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

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

How to write Clean Code:

Phase 1:Know what

Clean Code is

Phase 2:Continuous

Improvement

Phase 3:Profit!

Visit the sponsors

Don’t forget rate the speakers very highly!

Questions?

David Adsit@davidadsit

codeobsession.blogspot.com

top related