Slide 1

Slide 1 text

BUILDING THE TIMELESS WAY OF John Athayde MOUNTAIN WEST RUBY CONFERENCE MARCH 2014

Slide 2

Slide 2 text

I’m Jean Valjean. WHO AM I?

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

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 3 2 4 DESIGN PATTERNS

Slide 13

Slide 13 text

1PATTERN NAME

Slide 14

Slide 14 text

2 The 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

Patterns?

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

The Three-book series

Slide 25

Slide 25 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 26

Slide 26 text

No content

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

PRINCIPLES
 ARE PATTERNS

Slide 30

Slide 30 text

DRY

Slide 31

Slide 31 text

YAGNI

Slide 32

Slide 32 text

SRP SINGLE RESPONSIBILITY PRINCIPLE

Slide 33

Slide 33 text

OCP OPEN/CLOSED PRINCIPLE

Slide 34

Slide 34 text

LSP LISKOV SUBSTITUTION PRINCIPLE

Slide 35

Slide 35 text

ISP INTERFACE SEGREGATION PRINCIPLE

Slide 36

Slide 36 text

DIP Dependency inversion PRINCIPLE

Slide 37

Slide 37 text

S O L I D SRP OCP LSP ISP DIP

Slide 38

Slide 38 text

WHERE DID PATTERNS COME FROM? ARCHITECTURE

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

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

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

WORKING WITHIN THE LANGUAGE OF CLASSICAL ARCHITECTURE.

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

crafstmen

Slide 60

Slide 60 text

ENGINEERS

Slide 61

Slide 61 text

architects

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

http://www.patterntap.com

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

STRIVING SO WHAT ARE WE TOWARDS?

Slide 68

Slide 68 text

HAS NO NAME THE QUALITY OF A SPACE that

Slide 69

Slide 69 text

Gibellina, Italy

Slide 70

Slide 70 text

Gibellina Nuova, Italy

Slide 71

Slide 71 text

Welcome to negative town. ANTIPATTERNS

Slide 72

Slide 72 text

D

Slide 73

Slide 73 text

2

Slide 74

Slide 74 text

Gibellina Nuova, Italy D

Slide 75

Slide 75 text

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

Slide 76

Slide 76 text

D

Slide 77

Slide 77 text

Walking the Tree D

Slide 78

Slide 78 text

@account.customer.address.state D

Slide 79

Slide 79 text

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

Slide 80

Slide 80 text

2 COMPOSITION DELEGATE

Slide 81

Slide 81 text

FAT Models D

Slide 82

Slide 82 text

MODULES CONCERNS PLUGINS* GEMS ENGINES 2

Slide 83

Slide 83 text

CALLBACKS ! before_validation before_validation on: :create after_validation after_validation on: :create before_save before_create after_create after_save 2 D

Slide 84

Slide 84 text

RAILS IS A SERIES OF VERY LARGE TUBES LIBRARIES 2 D

Slide 85

Slide 85 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 86

Slide 86 text

rails g model {modelname} D

Slide 87

Slide 87 text

DSL ALL THE THINGS D

Slide 88

Slide 88 text

DIV-itis PHP-itis Java-isms D

Slide 89

Slide 89 text

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

Slide 90

Slide 90 text

M V C 2

Slide 91

Slide 91 text

Untested Code D

Slide 92

Slide 92 text

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

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

So what do we do? THE KERNEL OF THE WAY

Slide 95

Slide 95 text

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

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 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 98

Slide 98 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 99

Slide 99 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 100

Slide 100 text

PATTERNS THEREFORE REMEMBER THAT IT’S NOT ABOUT USING

Slide 101

Slide 101 text

LANGUAGE it’s about speaking a

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

Let’s go theory! AND YET...

Slide 104

Slide 104 text

HAS NO NAME THE QUALITY OF A SPACE that

Slide 105

Slide 105 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 106

Slide 106 text

HAS NO NAME THE QUALITY OF A SPACE that

Slide 107

Slide 107 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 108

Slide 108 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 109

Slide 109 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. At this stage, the building’s life will come directly from your language.” — The Timeless Way of Building, Chapter 27

Slide 110

Slide 110 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 111

Slide 111 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 112

Slide 112 text

No content

Slide 113

Slide 113 text

The Three-book series

Slide 114

Slide 114 text

@boboroshi | @therailsview THANK YOU AthaydeWilliamsRailsView BOOK CODE FOR 25% OFF AT www.pragprog.com/titles/warv: [email protected]