Slide 1

Slide 1 text

BUILDING THE TIMELESS WAY OF John Athayde RUBYNATION MAY 2013

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

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

LET’S GET ON THE SAME PAGE “PATTERNS”

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 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 16

Slide 16 text

1 3 2 4 DESIGN PATTERNS

Slide 17

Slide 17 text

1PATTERN NAME

Slide 18

Slide 18 text

2 The Problem

Slide 19

Slide 19 text

3The solution

Slide 20

Slide 20 text

4consequences

Slide 21

Slide 21 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 22

Slide 22 text

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

Slide 23

Slide 23 text

.each

Slide 24

Slide 24 text

Patterns?

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

The Three-book series

Slide 29

Slide 29 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 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

PRINCIPLES ARE PATTERNS

Slide 33

Slide 33 text

DRY

Slide 34

Slide 34 text

YAGNI

Slide 35

Slide 35 text

SRP SINGLE RESPONSIBILITY PRINCIPLE

Slide 36

Slide 36 text

OCP OPEN/CLOSED PRINCIPLE

Slide 37

Slide 37 text

LSP LISKOV SUBSTITUTION PRINCIPLE

Slide 38

Slide 38 text

ISP INTERFACE SEGREGATION PRINCIPLE

Slide 39

Slide 39 text

DIP Dependency inversion PRINCIPLE

Slide 40

Slide 40 text

S O L I D SRP OCP LSP ISP DIP

Slide 41

Slide 41 text

WHERE DID PATTERNS COME FROM? ARCHITECTURE

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

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

WORKING WITHIN THE LANGUAGE OF CLASSICAL ARCHITECTURE.

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

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

Slide 61

Slide 61 text

crafstmen

Slide 62

Slide 62 text

ENGINEERS

Slide 63

Slide 63 text

architects

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

http://www.patterntap.com

Slide 68

Slide 68 text

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

Slide 69

Slide 69 text

STRIVING SO WHAT ARE WE TOWARDS?

Slide 70

Slide 70 text

HAS NO NAME THE QUALITY OF A SPACE that

Slide 71

Slide 71 text

Gibellina, Italy

Slide 72

Slide 72 text

Gibellina Nuova, Italy

Slide 73

Slide 73 text

Welcome to negative town. ANTIPATTERNS

Slide 74

Slide 74 text

D

Slide 75

Slide 75 text

2

Slide 76

Slide 76 text

Gibellina Nuova, Italy D

Slide 77

Slide 77 text

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

Slide 78

Slide 78 text

D

Slide 79

Slide 79 text

Walking the Tree D

Slide 80

Slide 80 text

Inheritance Everywhere D

Slide 81

Slide 81 text

2 COMPOSITION DELEGATE

Slide 82

Slide 82 text

@account.customer.address.state D

Slide 83

Slide 83 text

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

Slide 84

Slide 84 text

FAT Models D

Slide 85

Slide 85 text

MODULES CONCERNS PLUGINS* GEMS ENGINES 2

Slide 86

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

Slide 87 text

RAILS IS A SERIES OF VERY LARGE TUBES LIBRARIES 2 D

Slide 88

Slide 88 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 89

Slide 89 text

rails g model {modelname} D

Slide 90

Slide 90 text

DSL ALL THE THINGS D

Slide 91

Slide 91 text

DIV-itis PHP-itis Java-isms D

Slide 92

Slide 92 text

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

Slide 93

Slide 93 text

M V C 2

Slide 94

Slide 94 text

<% if location.present? %> Located in <%= @client.location %> <% else %> Location Unknown <% end %>

2

Slide 95

Slide 95 text

2

Slide 96

Slide 96 text

2

Slide 97

Slide 97 text

Untested Code D

Slide 98

Slide 98 text

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

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

So what do we do? THE KERNEL OF THE WAY

Slide 101

Slide 101 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 102

Slide 102 text

No content

Slide 103

Slide 103 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. ” — Je Atwood c. 2005

Slide 104

Slide 104 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 O N ”

Slide 105

Slide 105 text

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

Slide 106

Slide 106 text

PATTERNS THEREFORE REMEMBER THAT IT’S NOT ABOUT USING

Slide 107

Slide 107 text

LANGUAGE it’s about speaking a

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

Let’s go theory! AND YET...

Slide 110

Slide 110 text

HAS NO NAME THE QUALITY OF A SPACE that

Slide 111

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

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

Slide 113 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 114

Slide 114 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 115

Slide 115 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 116

Slide 116 text

No content

Slide 117

Slide 117 text

The Three-book series

Slide 118

Slide 118 text

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

Slide 119

Slide 119 text

No content