Slide 1

Slide 1 text

What is good code? Evaluating code quality Daniel Carral Barcelona on Rails (@ XING), 02/15/2018

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

github.com/dcarral/good-code

Slide 4

Slide 4 text

Agenda ➔ Intro ➔ Craft Let’s solve the problem! ➔ Show & discuss Which approach did you use? Why? ➔ Evaluate Opinion vs facts What do the numbers say? ➔ Retrospective

Slide 5

Slide 5 text

What is good?

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Good?

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Good? Better?

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Craft Coding Dojo

Slide 12

Slide 12 text

How many dojos?

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

TDD & refactoring

Slide 16

Slide 16 text

Pair programming

Slide 17

Slide 17 text

Simple design

Slide 18

Slide 18 text

Kata 99 bottles of beer

Slide 19

Slide 19 text

Clone & code :) github.com/dcarral/99bottles-polyglot

Slide 20

Slide 20 text

(until 20:30h) Clone & code :) github.com/dcarral/99bottles-polyglot

Slide 21

Slide 21 text

Time over :)

Slide 22

Slide 22 text

Show & discuss (or not ;)

Slide 23

Slide 23 text

How did you solve it? Why? Reminder The goal is not to judge our coding skills. We’re discussing how to evaluate code quality.

Slide 24

Slide 24 text

github.com/dcarral/99bottles-solutions

Slide 25

Slide 25 text

Agenda ➔ Intro ➔ Craft Let’s solve the problem! ➔ Show & discuss Which approach did you use? Why? ➔ Evaluate Opinion vs facts What do the numbers say? ➔ Retrospective

Slide 26

Slide 26 text

Evaluating code quality

Slide 27

Slide 27 text

Based on opinion

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

In your opinion, what is “good code”? ● “Easy to understand and read. Easy to test.” ● “SOLID” ● “Passes the squint test :)” ● “Quality transcends description”

Slide 30

Slide 30 text

Based on facts

Slide 31

Slide 31 text

Software metrics “A software metric is a standard measure of a degree to which a software system possesses some property.”

Slide 32

Slide 32 text

Why measure? “You cannot control what you cannot measure.”* — Tom DeMarco * Apparently, he regrets having said this (thanks David!)

Slide 33

Slide 33 text

Some metrics ● Ca 1960: LOC ● 1976: Cyclomatic complexity ● 1997: ABC size

Slide 34

Slide 34 text

ABC ● Assignments ● Branches (of control) ● Conditions

Slide 35

Slide 35 text

“Confessions of a Ruby Sadist”

Slide 36

Slide 36 text

4 more solutions

Slide 37

Slide 37 text

What do the numbers say? Solution LOC Flog total Flog worst bit #1 Incomprehensibly concise 19 42.5 36.2 (#verse) #2 Speculatively general 63 54.8 28.5 (lambdas) #3 Concretely abstract 92 67 15.3 (#challenge) #4 Shameless green 34 25.6 19.3 (#verse)

Slide 38

Slide 38 text

Why metrics? “Metrics are fallible but human opinion is no more precise. Checking metrics regularly will keep you humble and improve your code.” — Sandi Metz, Katrina Owen

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

sandimetz.com/99bottles/postcard

Slide 41

Slide 41 text

* Disclaimer: Some people don’t like it (at all). Think twice before purchasing it ;)

Slide 42

Slide 42 text

Retro time

Slide 43

Slide 43 text

… surprised me. I’ve learnt… I’d like to start doing… Feedback :)

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

● Coding dojos ● TDD ● Refactoring ● Pair programming ● Simple design ● Zen & the art of motorcycle maintenance ● Clean Code ● eXtreme Programming explained ● 99 bottles of OOP ● Beautiful code ● Software metrics ● LOC ● Cyclomatic complexity ● ABC size @dcarral dcarral.org