Slide 1

Slide 1 text

BUILDING THE TIMELESS WAY OF REVOLUTION CONF 2017 VIRGINIA BEACH, VIRGINIA John Athayde @boboroshi

Slide 2

Slide 2 text

I’m Jean Valjean. WHO AM I?

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

METICULOUS

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Get our bearings here... WHAT WE’RE GONNA COVER

Slide 8

Slide 8 text

PATTERNS ARCHITECTURE
 PATTERN LANGUAGES & HISTORY ANTI-PATTERNS APPLY some THEORY

Slide 9

Slide 9 text

LET’S GET ON THE SAME PAGE “PATTERNS”

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

A design pattern systematically names, motivates, and explains a general design that addresses a recurring design problem in object-oriented systems. It describes the problem, the solution, when to apply the solution, and its consequences. It also gives implementation hints and examples. The solution is a general arrangement of objects and classes that solve the problem. The solution is customized and implemented to solve the problem in a particular context.

Slide 12

Slide 12 text

1 2 4DESIGN PATTERNS

Slide 13

Slide 13 text

1PATTERN NAME

Slide 14

Slide 14 text

2THE PROBLEM

Slide 15

Slide 15 text

3THE SOLUTION

Slide 16

Slide 16 text

4CONSEQUENCES

Slide 17

Slide 17 text

“Design patterns help you identify less-obvious abstractions and the objects than can capture them. For example, objects that represent a process or algorithm don’t occur in nature, yet they are a crucial part of flexible designs.”

Slide 18

Slide 18 text

Iterator Pattern Iterate over elements of a collection without exposing the internals...

Slide 19

Slide 19 text

.each

Slide 20

Slide 20 text

foreach

Slide 21

Slide 21 text

for x in…

Slide 22

Slide 22 text

Patterns?

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

The Three-book series

Slide 27

Slide 27 text

“How can you distribute responsibility for design through all levels of a large hierarchy, while still maintaining consistency and harmony of overall design?” — M. J. Dominus 2002 ALEXANDER’S QUEST:

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

1 3 2 4 ARCHITECTURE PATTERN: transition space between the 
 street and the front door

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

PRINCIPLES
 ARE PATTERNS

Slide 32

Slide 32 text

DRY

Slide 33

Slide 33 text

YAGNI

Slide 34

Slide 34 text

SRP SINGLE RESPONSIBILITY PRINCIPLE

Slide 35

Slide 35 text

OCP OPEN/CLOSED PRINCIPLE

Slide 36

Slide 36 text

LSP LISKOV SUBSTITUTION PRINCIPLE

Slide 37

Slide 37 text

ISP INTERFACE SEGREGATION PRINCIPLE

Slide 38

Slide 38 text

DIP Dependency inversion PRINCIPLE

Slide 39

Slide 39 text

S O L I D SRP OCP LSP ISP DIP

Slide 40

Slide 40 text

PATTERNS ALL THE WAY DOWN

Slide 41

Slide 41 text

WHERE DO PATTERNS COME FROM? ARCHITECTURE

Slide 42

Slide 42 text

1570 ITALY

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

1750 LONDON

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

1773 LONDON

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

WORKING WITHIN THE LANGUAGE OF CLASSICAL ARCHITECTURE.

Slide 64

Slide 64 text

“…[Architecture and Software patterns] give us a vocabulary to talk about how things are constructed. It is much more convenient to say, ‘this object has listeners for its properties,’ than ‘this object lets you hook callback functions that are called when properties change.’” — Federico Mena Quintero
 “Software that has the Quality Without a Name”

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

Phi Beta Kappa Hall, Wren Building, William & Mary, Wiliamsburg, Virginia

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

http://www.flickr.com/photos/cindy47452/3682879190/

Slide 71

Slide 71 text

THE LANGUAGE WE USE TO DESCRIBE OURSELVES

Slide 72

Slide 72 text

craftSmen

Slide 73

Slide 73 text

ENGINEERS

Slide 74

Slide 74 text

architects

Slide 75

Slide 75 text

BUILDERS W E F A N C Y O U R S E L V E S

Slide 76

Slide 76 text

“Engineers frequently have to make decisions of great practical consequence in the face of incomplete and uncertain knowledge.” — Walter Vincenti ON ENGINEERS:

Slide 77

Slide 77 text

PROBLEM: too many people think that “design patterns” in software means a library of Code templates.

Slide 78

Slide 78 text

“ design patterns are suggested approaches seen in the wild. - B R I A N H O G A N ”

Slide 79

Slide 79 text

http://www.patterntap.com

Slide 80

Slide 80 text

STRIVING SO WHAT ARE WE TOWARDS?

Slide 81

Slide 81 text

HAS NO NAME THE QUALITY OF A SPACE that

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

Gibellina, Italy

Slide 84

Slide 84 text

Gibellina Nuova, Italy

Slide 85

Slide 85 text

Charlottesville Downtown

Slide 86

Slide 86 text

Shops at Stonefield

Slide 87

Slide 87 text

“…the mere list of elements which are typical in a given town tells us the way of life of people there.” — Alexander, TTWoB, pp71

Slide 88

Slide 88 text

“To many software-patterns folk the quality without a name doesn’t apply to things like software anyhow. I agree that most software— at least the software I see—doesn’t have such a quality, but does that mean it couldn’t? I find it odd, though, to take so much inspiration from the simple, mechanical parts of a person’s work —the form of the pattern language and terms like forces—but to ignore the heart of it. I’m not so sure the quality without a name is irrelevant.” — Richard P. Gabriel Patterns of Software, pp 71

Slide 89

Slide 89 text

Objective Quality THIS IS AN

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

Nature = 15 Properties in common All patterns come from these properties Each property can also transform Only good design = transformation,
 one property at a time.

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

Thick Boundaries Local Symmetries Positive Space

Slide 94

Slide 94 text

TRANSFORMATION STRUCTURE-PRESERVING

Slide 95

Slide 95 text

REFACTORING

Slide 96

Slide 96 text

WELCOME TO NEGATIVE TOWN ANTIPATTERNS

Slide 97

Slide 97 text

D

Slide 98

Slide 98 text

2

Slide 99

Slide 99 text

Gibellina Nuova, Italy D

Slide 100

Slide 100 text

“Big Ball of Mud” Paper (aka Shanty Towns) D

Slide 101

Slide 101 text

D

Slide 102

Slide 102 text

Walking the Tree D

Slide 103

Slide 103 text

@account.customer.address.state D

Slide 104

Slide 104 text

class Customer < ActiveRecord::Base has_one :address has_one :account ... def state address.state end ... end @account.customer.state 2

Slide 105

Slide 105 text

2 COMPOSITION DELEGATE

Slide 106

Slide 106 text

FAT Models D

Slide 107

Slide 107 text

MODULES CONCERNS PLUGINS* GEMS ENGINES 2

Slide 108

Slide 108 text

FAT Controllers ONE CONTROLLER TO RULE THEM ALL... or not. D

Slide 109

Slide 109 text

TRANSACTIONALS before_validation before_validation on: :create after_validation after_validation on: :create before_save before_action after_save after_action 2 D

Slide 110

Slide 110 text

http://callbackhell.com D fs.readdir(source, function (err, files) { if (err) { console.log('Error finding files: ' + err) } else { files.forEach(function (filename, fileIndex) { console.log(filename) gm(source + filename).size(function (err, values) { if (err) { console.log('Error identifying file size: ' + err) } else { console.log(filename + ' : ' + values) aspect = (values.width / values.height) widths.forEach(function (width, widthIndex) { height = Math.round(width / aspect) console.log('resizing ' + filename + 'to ' + height + 'x' + height) this.resize(width, height).write(dest + 'w' + width + '_' + filename, function(err) { if (err) console.log('Error writing file: ' + err) }) }.bind(this)) } }) }) } }) CALLBACKS

Slide 111

Slide 111 text

Keep Your Code Shallow MODULARIZE (Make a library) handle every single error 2 http://callbackhell.com

Slide 112

Slide 112 text

“I USE (DRUPAL|RAILS|FRAMEWORK.NAME) TO BUILD EVERYTHING.” D

Slide 113

Slide 113 text

FRAMEWORKS ARE
 A SERIES OF VERY LARGE TUBES LIBRARIES 2 D

Slide 114

Slide 114 text

class RemoteProcess < ActiveRecord::Base scope :running, where(:state => ‘Running’) scope :system, where(:owner => [‘root’, ‘mysql’]) scope :sorted, order(“percent_cpy desc”) scope :top, lamda {|1| limit(1)} end RemoteProcess.running.sorted.top(10) RemoteProcess.running.system.sorted.top(5) sample from Rails Antipatterns pp 37 2

Slide 115

Slide 115 text

rails g model {modelname} D

Slide 116

Slide 116 text

DSL ALL THE THINGS D

Slide 117

Slide 117 text

DIV-itis PHP-itis Java-isms D

Slide 118

Slide 118 text

M V C 2

Slide 119

Slide 119 text

LOTS OF VIEW LOGIC D

Slide 120

Slide 120 text

2 TYPOGRAPHIC REFACTORING http://naildrivin5.com/blog/2013/05/17/source-code-typography.html

Slide 121

Slide 121 text

def text_field_tag(name, value = nil, options = {}) tag :input, { :type => "text", :name => name, :id => sanitize_to_id(name), :value => value }.update( end def text_field_tag(name, value = nil, options = {}) tag :input, { :type => "text", :name => name, :id => sanitize_to_id(name), :value => value }.update(options.stringify_keys) end 2 D

Slide 122

Slide 122 text

Untested Code D

Slide 123

Slide 123 text

SAMPLE EXAMPLE REFACTOR TRACTOR

Slide 124

Slide 124 text

No content

Slide 125

Slide 125 text

PHONE CALL

Slide 126

Slide 126 text

HALF CALL HALF CALL Gerard Meszaros “Pattern; Half Object + Protocol”

Slide 127

Slide 127 text

HALF CALL HALF CALL Gerard Meszaros “Pattern; Half Object + Protocol”

Slide 128

Slide 128 text

HALF CALL HALF CALL cALL

Slide 129

Slide 129 text

HALF CALL HALF CALL HALF CALL cALL

Slide 130

Slide 130 text

REFACTOR NOT THE GREAT REWRITE

Slide 131

Slide 131 text

SO WHAT DO WE DO? THE KERNEL OF THE WAY

Slide 132

Slide 132 text

No content

Slide 133

Slide 133 text

“The best way to learn to write simple code is to write simple code! Patterns, like all forms of complexity, should be avoided until they are absolutely necessary. That’s the first thing beginners need to learn. Not the last thing. ” — Jeff Atwood c. 2005

Slide 134

Slide 134 text

“ You cannot say that you are correctly applying a design pattern unless you are confronting the problem that the pattern is supposed to solve – R U S S O L S E N ”

Slide 135

Slide 135 text

“...mediocre developers never even ask why. They just arrive at the first solution that works and keep plowing ahead.” — Jeff Atwood, c.2005

Slide 136

Slide 136 text

PATTERNS THEREFORE REMEMBER THAT IT’S NOT ABOUT USING

Slide 137

Slide 137 text

LANGUAGE it’s about speaking a

Slide 138

Slide 138 text

No content

Slide 139

Slide 139 text

LET’S GO THEORY! AND YET…

Slide 140

Slide 140 text

HAS NO NAME THE QUALITY OF A SPACE that

Slide 141

Slide 141 text

“To many software-patterns folk the quality without a name doesn’t apply to things like software anyhow. I agree that most software— at least the software I see—doesn’t have such a quality, but does that mean it couldn’t? I find it odd, though, to take so much inspiration from the simple, mechanical parts of a person’s work —the form of the pattern language and terms like forces—but to ignore the heart of it. I’m not so sure the quality without a name is irrelevant.” — Richard P. Gabriel Patterns of Software, pp 71

Slide 142

Slide 142 text

“Indeed this ageless character has nothing, in the end, to do with languages. The language, and the processes which stem from it, merely release the fundamental order which is native to us.” — The Timeless Way of Building, Chapter 27

Slide 143

Slide 143 text

“They do not teach us, they only remind us of what we know already, and of what we shall discover time and time again, when we give up our opinions, and do exactly what emerges from ourselves.” — The Timeless Way of Building, Chapter 27

Slide 144

Slide 144 text

“To make a building egoless, the builder must let go of all his willful images, and start with 
 a void. You are able to do this only when you no longer fear that nothing will happen, and you can therefore afford to let go of your images.” — The Timeless Way of Building, Chapter 27

Slide 145

Slide 145 text

“Yet , at the very moment when you first relax, and let the language generate the buildings in your mind, you will begin to see how limited your language is. One place can have good patterns in it and be dead. Another place can be without the patterns which apply to it, and yet still be alive. ” — The Timeless Way of Building, Chapter 27

Slide 146

Slide 146 text

“The pattern ALCOVE–which first functioned as an intellectual crutch–is no longer necessary to you. You see reality directly, like an animal. You make the alcove as an animal might make an alcove–not because of the concept–but directly, simply because it is appropriate.” — The Timeless Way of Building, Chapter 27

Slide 147

Slide 147 text

REFACTORING STRUCTURE-PRESERVING TRANSFORMATIONS =

Slide 148

Slide 148 text

LANGUAGE LEARN TO speak THE

Slide 149

Slide 149 text

EVOLVES SOFTWARE THAT

Slide 150

Slide 150 text

HAS NO NAME THE QUALITY OF SOFTWARE that

Slide 151

Slide 151 text

No content

Slide 152

Slide 152 text

The Three-book series

Slide 153

Slide 153 text

@boboroshi THANK YOU [email protected] https://speakerdeck.com/boboroshi SLIDE DECK AVAILABLE: