ndc 2011 - the fluid principles

Post on 05-Dec-2014

4.643 Views

Category:

Technology

8 Downloads

Preview:

Click to see full reader

DESCRIPTION

The slides from Kevlin Henney and Anders Norås introduction of the FLUID principles at The Norwegian Developer's Conference June 8th 2011.

TRANSCRIPT

ndc 2011

FLUIDThe

PrinciplesKevlin HenneyAnders Norås

FLUID

SOLIDcontrasts with

SOLID

SOL

ingle Responsibility Principle

pen / Closed Principle

iskov’s Substitution Principle

nterface Segregation Principle

ependency Inversion Principle

ID

Bob might not be your uncle

By A. NORÅS &K. HENNEY

Ut enim ad minim veniam, quis nostrud exerc. Irure dolor in reprehend incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse molestaie cillum. Tia non ob ea soluad incommod quae egen ium improb fugiend. Officia deserunt mollit anim id est laborum Et harumd dereud.

Neque pecun modut nequeConsectetuer arcu ipsum ornare pellentesque vehicula, in vehicula diam, ornare magna erat felis wisi a risus. Justo fermentum id. Malesuada eleifend, tortor molestie, a fusce a vel et. Mauris at suspendisse, neque aliquam faucibus adipiscing, vivamus in. Wisi mattis leo suscipit nec amet, nisl fermentum tempor ac a, augue in eleifend in venenatis, cras sit id in vestibulum felis. Molestie ornare amet vel id fusce, rem volutpat platea. Magnis vel, lacinia nisl, vel nostra nunc eleifend arcu leo, in dignissim lorem vivamus laoreet.

Donec arcu risus diam amet sit. Congue tortor cursus risus vestibulum commodo nisl, luctus augue amet quis aenean odio etiammaecenas sit, donec velit iusto, morbi felis elit et nibh. Vestibulum volutpat dui lacus consectetuer ut, mauris at etiam suspendisse, eu wisi rhoncus eget nibh velit, eget posuere sem in a sit.

Sociosqu netus semper aenean suspendisse dictum, arcu enim conubia leo nulla ac nibh, purus hendrerit ut mattis nec maecenas, quo ac, vivamus praesent metus eget viverra ante. Natoque placerat sed sit hendrerit, dapibus eleifend velit molestiae leo a, ut lorem sit et lacus aliquam. Sodales nulla erat et luctus faucibus aperiam sapien. Leo inceptos augue nec pulvinar rutrum aliquam mauris, wisi hasellus fames ac, commodo eligendi dictumst, dapibus morbi auctor.

Ut enim ad minim veniam, quis nostrud exerc. Irure dolor in reprehend incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse molestaie cillum. Tia non ob ea soluad incommod quae egen ium improb fugiend. Officia deserunt mollit anim id est laborum Et harumd dereud.

Etiam sit amet est

The Software Dev Times“ALL THE NEWS THAT’S FIT TO DEPLOY” LATE EDITION

VOL XI...NO 12,345 OSLO, WEDNESDAY, JUNE 8, 2011 FREE AS IN BEER

SHOCK-SOLID!MYSTERIOUS SOFTWARE CRAFTSMAN

COINED THE SOLID ACRONYM!

NO COMMENT. The software craftsman claimed to have discovered that a set of principles could be abbreviated “SOLID”, declined to comment on the matter.

Bob might not be your uncle

By A. NORÅS &K. HENNEY

Ut enim ad minim veniam, quis nostrud exerc. Irure dolor in reprehend incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse molestaie cillum. Tia non ob ea soluad incommod quae egen ium improb fugiend. Officia deserunt mollit anim id est laborum Et harumd dereud.

Neque pecun modut nequeConsectetuer arcu ipsum ornare pellentesque vehicula, in vehicula diam, ornare magna erat felis wisi a risus. Justo fermentum id. Malesuada eleifend, tortor molestie, a fusce a vel et. Mauris at suspendisse, neque aliquam faucibus adipiscing, vivamus in. Wisi mattis leo suscipit nec amet, nisl fermentum tempor ac a, augue in eleifend in venenatis, cras sit id in vestibulum felis. Molestie ornare amet vel id fusce, rem volutpat platea. Magnis vel, lacinia nisl, vel nostra nunc eleifend arcu leo, in dignissim lorem vivamus laoreet.

Donec arcu risus diam amet sit. Congue tortor cursus risus vestibulum commodo nisl, luctus augue amet quis aenean odio etiammaecenas sit, donec velit iusto, morbi felis elit et nibh. Vestibulum volutpat dui lacus consectetuer ut, mauris at etiam suspendisse, eu wisi rhoncus eget nibh velit, eget posuere sem in a sit.

Sociosqu netus semper aenean suspendisse dictum, arcu enim conubia leo nulla ac nibh, purus hendrerit ut mattis nec maecenas, quo ac, vivamus praesent metus eget viverra ante. Natoque placerat sed sit hendrerit, dapibus eleifend velit molestiae leo a, ut lorem sit et lacus aliquam. Sodales nulla erat et luctus faucibus aperiam sapien. Leo inceptos augue nec pulvinar rutrum aliquam mauris, wisi hasellus fames ac, commodo eligendi dictumst, dapibus morbi auctor.

Ut enim ad minim veniam, quis nostrud exerc. Irure dolor in reprehend incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse molestaie cillum. Tia non ob ea soluad incommod quae egen ium improb fugiend. Officia deserunt mollit anim id est laborum Et harumd dereud.

Etiam sit amet est

The Software Dev Times“ALL THE NEWS THAT’S FIT TO DEPLOY” LATE EDITION

VOL XI...NO 12,345 OSLO, WEDNESDAY, JUNE 8, 2011 FREE AS IN BEER

SHOCK-SOLID!MYSTERIOUS SOFTWARE CRAFTSMAN

COINED THE SOLID ACRONYM!

NO COMMENT. The software craftsman claimed to have discovered that a set of principles could be abbreviated “SOLID”, declined to comment on the matter.

eBristol

Dictionaryof

ConciseEnglish

prin·ci·ple /ˈprinsəpəl/ Noun

1. a fundamental truth or proposit ion that serves as the foundation for a system of belief or behaviour or for a chain of reasoning.2. morally correct behaviour and attitudes.3. a general scienti"c theorem or law that has n u m e r o u s s p e c i a l applications across a wide "eld.

4. a natural law forming t h e b a s i s f o r t h e construction or working of a machine.

para·skevi·de·katri·a·pho·bia /ˈpærəskevidekaˈtriəˈfōbēə/ Adjective, Noun

1. fear of Friday the 13th. Etymology: e word was devised by Dr. Donald Dossey who told his patients that "when you learn to pronounce it, you're cured.

FLUIDThe

PrinciplesKevlin HenneyAnders Norås

FLUIDThe

Kevlin HenneyAnders Norås

Guidelines

F L U I DWhat are the

Guidelines?

F

L

U

I

D

F

L

U

I

D

Functional

public class HeatingSystem { public void turnOn() ... public void turnOff() ... ...}

public class Timer { public Timer(TimeOfDay toExpire, Runnable toDo) ... public void run() ... public void cancel() ... ...}

Java

public class TurnOn implements Runnable { private HeatingSystem toTurnOn; public TurnOn(HeatingSystem toRun) { toTurnOn = toRun; } public void run() { toTurnOn.turnOn(); }}public class TurnOff implements Runnable { private HeatingSystem toTurnOff; public TurnOff(HeatingSystem toRun) { toTurnOff = toRun; } public void run() { toTurnOff.turnOff(); }}

Java

Timer turningOn = new Timer(timeOn, new TurnOn(heatingSystem));Timer turningOff = new Timer(timeOff, new TurnOff(heatingSystem));

Java

Timer turningOn = new Timer( timeToTurnOn, new Runnable() { public void run() { heatingSystem.turnOn(); } });Timer turningOff = new Timer( timeToTurnOff, new Runnable() { public void run() { heatingSystem.turnOff(); } });

Java

void turnOn(void * toTurnOn){ static_cast<HeatingSystem *>(toTurnOn)->turnOn();}void turnOff(void * toTurnOff){ static_cast<HeatingSystem *>(toTurnOff)->turnOff();}

C++

Timer turningOn(timeOn, &heatingSystem, turnOn);Timer turningOff(timeOff, &heatingSystem, turnOff);

C++

class Timer{ Timer(TimeOfDay toExpire, function<void()> toDo); void run(); void cancel(); ...};

C++

Timer turningOn( timeOn, bind( &HeatingSystem::turnOn, &heatingSystem));Timer turningOff( timeOff, bind( &HeatingSystem::turnOff, &heatingSystem));

C++

public class Timer{ public Timer( TimeOfDay toExpire, Action toDo) ... public void Run() ... public void Cancel() ... ...}

C#

Timer turningOn = new Timer( timeOn, () => heatingSystem.TurnOn() );Timer turningOff = new Timer( timeOff, () => heatingSystem.TurnOff() );

C#

Timer turningOn = new Timer( timeOn, heatingSystem.TurnOn );Timer turningOff = new Timer( timeOff, heatingSystem.TurnOff );

C#

F

L

U

I

D

unctional

F

L

U

I

D

unctional

Loose

OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I'm not aware of them.

•Allan Kay

#include <windows.h> #include <stdio.h> typedef int (__cdecl *MYPROC)(LPWSTR); VOID main(VOID) { HINSTANCE hinstLib; MYPROC ProcAdd; BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; hinstLib = LoadLibrary(TEXT("echo.dll")); if (hinstLib != NULL) { ProcAdd = (MYPROC) GetProcAddress(hinstLib, "echo"); if (NULL != ProcAdd) { fRunTimeLinkSuccess = TRUE; (ProcAdd) (L"Hello my world!\n"); } fFreeResult = FreeLibrary(hinstLib); } if (!fRunTimeLinkSuccess) printf("Hello everybody's world!\n"); }

C

class HeatingSystem { def turnOn() { ... } def turnOff() { ... }}def heater = new HeatingSystem()def timer = new Timer()def action = "turnOn"timer.runAfter(1000) { heater."$action"()}

Groovy

class DiyStore{ private $_bucket; public function getPaintBucket() { if ($this->_bucket === null) { $this->_bucket = $this->fillPaintBucket(); } return $this->_bucket; } private function fillPaintBucket() { // ... }}

PHP

NullObject.new().say().hello().to().any().method_call().you().like()

Ruby

FLUIDThe

PrinciplesKevlin HenneyAnders Norås

FLUIDThe

Kevlin HenneyAnders Norås

Suggestions

F

U

L

I

D

unctional

oose

U

F

L

I

D

unctional

oose

Unit Testable

function GetNextFriday13th($from) { [DateTime[]] $friday13ths = &{ foreach($i in 1..500) { $from = $from.AddDays(1) $from } } | ?{ $_.DayOfWeek -eq [DayOfWeek]::Friday -and $_.Day -eq 13 } return $friday13ths[0]}

PowerShell

[DateTime[][]] $inputsWithExpectations = ("2011-01-01", "2011-05-13"), ("2011-05-13", "2012-01-13"), ("2007-04-01", "2007-04-13"), ("2007-04-12", "2007-04-13"), ("2007-04-13", "2007-07-13"), ("2012-01-01", "2012-01-13"), ("2012-01-13", "2012-04-13"), ("2012-04-13", "2012-07-13"), ("2001-07-13", "2002-09-13")

PowerShell

$inputsWithExpectations | ?{ [String] $actual = GetNextFriday13th($_[0]) [String] $expected = $_[1] $actual -ne $expected}

PowerShell

F

L

U

I

D

unctional

oose

nit Testable

F

L

U

I

D

unctional

oose

nit Testable

Introspective

(define (eval exp env) (cond ((self-evaluating? exp) exp) ((variable? exp) (lookup-variable-value exp env)) ((quoted? exp) (text-of-quotation exp)) ((assignment? exp) (eval-assignment exp env)) ((definition? exp) (eval-definition exp env)) ((if? exp) (eval-if exp env)) ((lambda? exp)) (make-procedure (lambda-parameters exp) (lambda-body exp) env)) ((begin? exp) (eval-sequence (begin-actions exp) env)) ((cond? exp) (eval (cond->if exp) env)) ((application? exp) (apply (eval (operator exp) env) (list-of-values (operands exp) env))) (else (error "Unknown expression type -EVAL" exp))))

Scheme

function Shoebox() { var things = ["Nike 42", "Adidas 41", "Adidas 43", "Paul Smith 41"]; def(this, "find", function(brand) { var result = []; for (var i=0; i<things.length; i++) { if (things[i].indexOf(brand) !== -1) result.push(things[i]); } return result; }); def(this, "find", function(brand,size) { var result = []; for (var i=0; i<things.length; i++) { if (things[i].indexOf(brand) !== -1 || parseInt(things[i].match(/\d+/),10) === size) result.push(things[i]); } return result; });}

function def(obj, name, fn) { var implFn = obj[name]; obj[name]=function() { if (fn.length === arguments.length) return fn.apply(this,arguments); else if (typeof implFn === "function") return implFn.apply(this,arguments); };};

JavaScript

Public Class Book <Key> _ Public Property ISBN() As String ' ... End Property

<StringLength(256)> _ Public Property Title() As String ' ... End Property

Public Property AuthorSSN() As String ' ... End Property

<RelatedTo(RelatedProperty := Books, Key := AuthorSSN, RelatedKey := SSN)> _ Public Property Author() As Person ' ... End PropertyEnd Class

Visual Basic

F

L

U

I

D

unctional

oose

nit Testable

ntrospective

F

L

U

I

D

unctional

oose

nit Testable

ntrospective

‘Dempotent

Asking a question s h o u l d n o t c h a n g e t h e answer.

“•Betrand Meyer

Asking a question s h o u l d n o t c h a n g e t h e answer.

“•Betrand Meyer

, and nor should asking it twice!

Retweeted by @kevlinhenney

(1 to 10).foldLeft(0)(_ + _)Scala

F

L

U

I

D

unctional

oose

nit Testable

ntrospective

dempotent‘

e venerable master Qc Na was walking with his student, Anton.Hoping to prompt the master into a discussion, Anton said "Master, I have heard that objects are a very good thing — is this true?" Qc Na looked pityingly at his student and replied, "Foolish pupil — objects are merely a poor man's closures." Chastised, Anton took his leave from his master and returned to his cell, intent on studying closures. He carefully read the entire "Lambda: e Ultimate..." series of papers and its cousins, and implemented a small Scheme interpreter with a closure-based object system. He learned much, and looked forward to informing his master of his progress. On his next walk with Qc Na, Anton attempted to impress his master by saying "Master, I have diligently studied the matter, and now understand that objects are truly a poor man's closures." Qc Na responded by hitting Anton with his stick, saying "When will you learn? Closures are a poor man's object." At that moment, Anton became enlightened.

http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html

@anoras@kevlinhenney

top related