How to build quality software

Post on 15-Jul-2015

724 views 3 download

Transcript of How to build quality software

BEYOND HACKINGCrafting Quality Software

HOW IS SOFTWARE BUILT IN SMALL TEAMS?

WHY DOES THAT APPROACH NOT SCALE?

WHAT IS QUALITY?

HOW CAN WE ACCOMPLISH IT?

FROM CLEAN CODE - A HANDBOOK OF AGILE SOFTWARE CRAFTMANSHIP BY ROBERT C. MARTIN

Development Speed

Issues

WHAT IS QUALITY?

BUILDING SOFTWARE IN SMALL TEAMS

App

1. Code

2. Deploy

<Code>

V 1.0 V 1.0.1 V 1.1 V 1.1.1

Add FeatureFix Bug Fix Bug

LIFE IS SIMPLE LIFE IS GOOD

YOU ARE SHIPPING FAST

BUT SOMETHING FEELS WRONG

def update(post, title) @user = User.first

if @user.logged_in if @user.type == "admin" @user.type.permissions.each do |permission| { if (permission == "update_permission") { if post begin post.title = title post.save rescue display_error("This horrible code is not workin!") end else display_error("No Post provided") end } } elsif @user.type == "other" return else display_error("Invalid User Type") end else #What do here? end end

BAD CODE

TEAMS GROW, SOFTWARE GROWS

Rock Bottom

t

code complexitydev velocityissues

App

1. Code

2. Deploy

<Code>

?

?

!

!

!

?

?

!

WHAT NOW?

IT’S TIME TO REFACTOR

WHERE’S THE SPEC FOR ALL FEATURES?

HOW CAN WE AVOID THIS?

AS SOFTWARE AND TEAM GROW - ADD PROCESS

AND AUTOMATION

HOW CAN WE AVOID CHAOS?

Specification

Automated Testing

Continous Integration

Coding guidelines / Code Analysis

Reproducible development environment

(1) SPECIFY YOUR APPLICATION

TESTS CAN ACT AS SPECIFICATION!

BDD FRAMEWORKS CAN BE USED TO SPECIFY SOFTWARE

Cucumber Framework: http://cukes.info/

Feature: Search courses Courses should be searchable by topic Search results should provide the course code

Scenario: Search by topic Given there are 240 courses which do not have the topic "biology" And there are 2 courses, A001 and B205, that each have "biology" as one of the topics When I search for "biology" Then I should see the following courses: | Course code | | A001 | | B205 | Acceptance Test

(2) WRITE AUTOMATED TESTS (BEFORE WRITING APPLICATION CODE)

HOW SHOULD WE TEST?

ACCEPTANCE TEST

When it fails, it tells you that the application is not doing what the

customer expects it to do

UNIT TEST

When it fails, it tells you what piece of your code needs to be fixed

EXAMPLE

SignupService.POST(User:"Ben-G", PW:"&47-:#sdö").expect(200) SignupService.POST(User:"Ben-G", PW:”").expect(400)

SignupService.POST(User:"Ben-G", PW:"&47-:#sdö").expect(200)

PasswordValidator.testPassword("&47-:#sdö").expect(true) PasswordValidator.testPassword(“”).expect(false)

UsernameValidator.testUsername("Ben-G").expect(true)

PasswordValidator

SignupService

testPassword:Bool

HTTP POST User: Ben-G

PW: &47-:#sdö

UsernameValidator

testUsername:Bool

SignupService.POST(User:"", PW:"&47-:#sdö").expect(401) UsernameValidator.testUsername("").expect(false)

Acceptance Tests Unit Tests

(3) MEASURE CODE COVERAGE

CODE COVERAGE = % OF CODE COVERED BY TEST

(4) PROVIDE CODING

STYLEGUIDES, AUTOMATE CODE QUALITY TESTING

GITHUB RUBY STYLEGUIDE: https://github.com/styleguide/ruby

RUBOCOP, OCLINT, JSLINT TOOLS THAT MEASURE CONFORMANCE TO CODING GUIDELINES + FIND CODE SMELLS

“static analyzers”

CODE CLIMATE

STATIC ANALYZER AS

A SERVICE

(5) USE A CONTINUOUS

INTEGRATION SERVER

CONTINOUS INTEGRATION Every time code is pushed: • Run Static Analyzer • Run All tests • Measure Code Coverage • Run the Build Process

Working product can be shipped at any time!If anything breaks we find out right away

(6) PROVIDE REPRODUCIBLE

DEVELOPMENT ENVIRONMENT

?

But it works on my local machine…

MINIMUM CONFIGURATIONgit clone git@github.com:MakeGamesWithUs/www-makeschool.git

./server start

./server test

start rails serverrun test suite

• Git repository contains the definition of a Docker container+ a Fig configuration describing services

• App runs in Virtual Machine providing the same environment for all developers

+VM

define

Rails App

MongoDB

Postgres

PUTTING IT ALL TOGETHER

Code Coverage Measurements

Unit Tests

enforce

Acceptance Tests

Specification

Low Issue Count

define

support

Refactoring

enable

High Code Qualitydrives

enables

Automated CodeQuality Analysis

drives

drives

Development Speed

Reproducible DevelopmentEnvironment

drives

enables

support

ContinousIntegration{

automates

QUALITY SOFTWARE =

SLEEP WELL AFTER PUSHING NEW CODE TO MILLIONS OF USERS

QUALITY SOFTWARE

t

code complexitydev velocityissues

benji@makeschool.com

THANK YOU!