Twelve Ways to Make Code Suck Less Venkat Subramaniam - - PowerPoint PPT Presentation

twelve ways to make code suck less
SMART_READER_LITE
LIVE PREVIEW

Twelve Ways to Make Code Suck Less Venkat Subramaniam - - PowerPoint PPT Presentation

Twelve Ways to Make Code Suck Less Venkat Subramaniam venkats@agiledeveloper.com @venkat_s Why should we care about code quality? We cant be agile if our code sucks Lowering quality lengthens development time.First Law of


slide-1
SLIDE 1

Twelve Ways to Make Code Suck Less

Venkat Subramaniam

venkats@agiledeveloper.com

@venkat_s

slide-2
SLIDE 2

Why should we care about code quality?

slide-3
SLIDE 3

We can’t be agile if

  • ur code sucks
slide-4
SLIDE 4
slide-5
SLIDE 5

“Lowering quality lengthens development time.”—First Law of Programming.

http://c2.com/cgi/wiki?FirstLawOfProgramming

slide-6
SLIDE 6

What’s Quality Code?

slide-7
SLIDE 7

The quality of code is inversely proportional to the effort it takes to understand it.

http://blog.agiledeveloper.com/2010/05/thoughts-through-tweets_15.html

slide-8
SLIDE 8

Twelve ways We can Help

slide-9
SLIDE 9
  • 12. Schedule Time to Lower

Technical Debt

slide-10
SLIDE 10

What’s Technical Debt?

http://c2.com/cgi/wiki?WardExplainsDebtMetaphor

Ward Cunningham

slide-11
SLIDE 11

Example of Technical Debts

slide-12
SLIDE 12

Low quality is not technical debt

slide-13
SLIDE 13

What Causes Technical Debt?

slide-14
SLIDE 14

Not “All or Nothing”

slide-15
SLIDE 15

Schedule Time

slide-16
SLIDE 16

Development Vacation/sickness Meetings Paying Technical Debt Slack time

Planning…

slide-17
SLIDE 17

Linda Rising

slide-18
SLIDE 18
slide-19
SLIDE 19

Development Vacation/sickness Meetings Paying Technical Debt Slack time

Planning…

slide-20
SLIDE 20
  • 11. Favor High Cohesion
slide-21
SLIDE 21

Narrow, focused, does only one thing well

slide-22
SLIDE 22

Why?

slide-23
SLIDE 23

Think about frequency of change

slide-24
SLIDE 24

low cyclomatic complexity high cohesion ==

slide-25
SLIDE 25
  • 10. Favor Loose Coupling
slide-26
SLIDE 26

Tight coupling make code hard to extend hard to test

slide-27
SLIDE 27

Lower coupling Loose vs. tight coupling Eliminate where possible

slide-28
SLIDE 28

Excessive Mocking to Test This Non deterministic Dependency

slide-29
SLIDE 29

Light Mocking to Test This Non deterministic Dependency No Mocking to Test This

slide-30
SLIDE 30
  • 9. Program with Intention
slide-31
SLIDE 31

http://stackoverflow.com/questions/184618/what-is-the-best- comment-in-source-code-you-have-ever-encountered

slide-32
SLIDE 32

Beck’s Rule for Simple Design

http://martinfowler.com/bliki/BeckDesignRules.html

slide-33
SLIDE 33

Programming Deliberately

  • When you write test before writing code…
slide-34
SLIDE 34
  • 8. Avoid Primitive Obsession
slide-35
SLIDE 35
slide-36
SLIDE 36
slide-37
SLIDE 37

It’s code like this that prematurely turns programmers into managers

slide-38
SLIDE 38
slide-39
SLIDE 39
slide-40
SLIDE 40

http://blog.agiledeveloper.com/2015/08/the-functional-style.html

slide-41
SLIDE 41
  • 7. Prefer Clear Code
  • ver Clever Code
slide-42
SLIDE 42
slide-43
SLIDE 43

10% of the time, we write ugly code for performance reasons, the other 90% of the time, we write ugly code to be consistent.

http://blog.agiledeveloper.com/2010/05/thoughts-through-tweets_15.html

slide-44
SLIDE 44

http://blog.agiledeveloper.com/2010/05/thoughts-through-tweets_15.html

Those who sacrifice quality to get performance may end up getting neither.

slide-45
SLIDE 45

“There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies and the other is to make it so complicated that there are no

  • bvious deficiencies”— Tony Hoare

“There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies and the other is to make it so complicated that there are no

  • bvious deficiencies”— Tony Hoare
slide-46
SLIDE 46
  • 6. Apply Zinsser's Principle on

Writing

slide-47
SLIDE 47
slide-48
SLIDE 48

Simplicity Clarity Brevity Humanity

slide-49
SLIDE 49
  • 5. Comment Why, not What
slide-50
SLIDE 50

Don’t comment to cover up bad code

slide-51
SLIDE 51

Write Expressive Self-Documenting Code

slide-52
SLIDE 52

A good code is like a good joke

http://blog.agiledeveloper.com/2006/01/comments-on- comments.html

Writing comments is like explaining a joke

slide-53
SLIDE 53
slide-54
SLIDE 54
slide-55
SLIDE 55
  • rder(3) 3 cups?…
  • rder(CoffeeSize.LARGE)
  • rder(3) // large coffee
slide-56
SLIDE 56

https://media.pragprog.com/titles/pad/PAD-pulloutcard.pdf

slide-57
SLIDE 57
  • 4. Avoid Long Methods—Apply

SLAP

slide-58
SLIDE 58

Perils of Long Methods

slide-59
SLIDE 59

How long is long?

slide-60
SLIDE 60

Turns out long is not about length

  • f code, but levels of abstraction
slide-61
SLIDE 61
  • 3. Give Good Meaningful Names
slide-62
SLIDE 62
slide-63
SLIDE 63
slide-64
SLIDE 64
slide-65
SLIDE 65

Variable Names Represent Abstractions

slide-66
SLIDE 66
slide-67
SLIDE 67
  • 2. Do Tactical Code Reviews
slide-68
SLIDE 68

Peer reviews catch 60% of defects. Perspective-based reviews catch 35% more defects than nondirected reviews. Peer reviews complement testing. Technical and social activity.

https://www.cs.umd.edu/projects/SoftEng/ESEG/papers/82.78.pdf

slide-69
SLIDE 69

Facilitating Tactical Code Reviews

slide-70
SLIDE 70
  • 1. Reduce State & State Mutation
slide-71
SLIDE 71
slide-72
SLIDE 72
slide-73
SLIDE 73
slide-74
SLIDE 74

Twelve Ways to Make Code Suck Less

slide-75
SLIDE 75
  • 12. Schedule Time to Lower Technical Debt
  • 11. Favor High Cohesion
  • 10. Favor Loose Coupling
  • 9. Program with Intention
  • 8. Avoid Primitive Obsession
  • 7. Prefer Clear Code over Clever Code
  • 6. Apply Zinsser's Principle on Writing
  • 5. Comment Why, not What
  • 4. Avoid Long Methods—Apply SLAP
  • 3. Give Good Meaningful Names
  • 2. Do Tactical Code Reviews
  • 1. Reduce State & State Mutation
slide-76
SLIDE 76
slide-77
SLIDE 77

http://agiledeveloper.com/downloads.html

slide-78
SLIDE 78

Thank you

http://agiledeveloper.com/downloads.html venkats@agiledeveloper.com @venkat_s