Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Monoids, 
. 'lVlnoids everywherg
ean mag tell
lliflerenee?
r-
‘U

/5;‘

” i  *7‘?
This talk is
“IE EIIISWGI
(dedicated to @ziobrando'

htt : //rosshirt. b|o s ot. fr/
Passionate
developer

PARIS
Since 1999

@cyriux
Cyrille Martraire
T

. . I-1-o! A.. «.s. .w , . . 

. . . . r .4 u,  .. ... ‘.

   

. ... ..u. ~

1,‘: -.f/ b*: .: *‘; a1*.1-ihiihv/ r

5’-...
The illlllliflillll SIIIIW features
Illl Sllfllilalllllaf Sllllll,  Illl IWB
Bllllillll,  lllllll trivial Java BIIIIB. 

Vll...
a bit personal
Adopted 2005
Still in love
What do DDD 8 FP
have in common?
"My first encounter
with FP concepts
was from DDD"
Fp= ?
@ Clojure
lscala

Haskell

A Purely Functional Language
http: //www. 'aider. net/ archives/609-intro-to-functional-programming/
KJJ IH ILHIT
So what do
DDD 8 FP
have in
common?
Value Objects . ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .....
DDD+F P
Example
’ I ii. » I. 

it



F‘ ‘K7
 iwfi
Closure
Associativity
Neutral Element
ilifli Sii ll?   WQFH

Mi ism  li»lili! SEll~lSE
only 3
numbers in
programming
“9 19
Monoid: 
encapsulate
diversity inside
Operation
Neutral Element 

t‘,  I,  MANY

I

Element
Encapsulate
special cases

—> simple again
Battle against
complexity
X
COO

K
X
COO

K
Applied often: 
—> scalable process

—> can grow to
high complexity
Scalable in
complexity
oo FTW’

For a given interface I
find myself doing
often o,  1, Many
Composite
Null0biect 

t‘,  I,  MANY

I

lmplementation(s)
Identity Element
=  Null0bi ect

VatCa1cu1at1’on. NONE
Example
Numbers
int+int= int
(3+s)+z=3+(s+z)
0
Lists

(-)"'(-7-)= (-9-9-)
(a)"'(b, C)= (a, b)"'(C)

()
Strings

"hello"+"world"
I| CY| |+| |riI| +I| ]-J-ell
look simplistic; 
the key to very
complex behavior
The key to infinite
scalability! 

(space)
The key to infinite
incremental
computing! 

(time)
Hadoop x Storm
Composeability
Abstractions in
the small that
compose at large
Monoids it reduce
Monoids if domain
Monoids it do O
Monoids: 
typical FP
FP: 
Everything is a
value
Therefore: 
Monoids are
values!
Immutable
Equals by value
Value Object

A DDD pattern
to import FP-ish
values in 00
languages
Not Anemic
Change -> new instance

public Temperature add(Ternperature other) i"5ta"°e

return new Temperature(va1ue + other. toielsi...
SIDE-EFFECT
-TTBE

FUNCTIONS
lmmutability
8

Side-effect-free
functions!
“Functional-First” style

 _ V
a Aaron Erickson *'

Aa rm n E r:  C H5 0 n

I have heard the meme of "functional first"
pro...
“Functional-First” style

90%
Money
(25, EUR)
+

(30, EUR)

(55, EUR)
(25, EUR)
+

(30, USD)

exception
Money

<<ValueObject>>

amount
currency

add (Money) :  Money
itAY<1’N FovLe&

 

Intro Design Agie Refactorlng NOSOL DSL Delivery About Me

Quantity

Represent dimensioned values with...
Cashflows
(Payments)
(25, EUR,  today)
+

(30, EUR,  today)

(55, EUR,  today)
(25, EUR,  today)
+

(30, EUR,  next day)

exception
)CashFlow| 

<<ValueObject>>

amount

currency
date

add Cas F ow : »
ciogunr
OPERATION
Cashflows
Sequences
Cashflow Sequence
+

Cashflow Sequence

Cashflow Sequence
Obiect

Arithmetics

 

V
This is how domain
experts THINK

about it /  

SKETCH SAY
I U C
5 I
1 I

. rl. v-. «.rr. -at —, Ul= .«: .l“= _.«’! ur. rl'-. »:
Ranges
[1, 31

Union *
[2, 41

[1,-41

* for a bounding box-kind definition of union
Predicates
Filter
AND
Filter

Filter
Filter
OR
Filter

Filter
Grants
Read,  Write,  Execute

"most secure wins"

r
W + x =  W
Configuration
Maps
IC

.  as as
+ __

 

Default esk s ecif
Default Desk-s - ecific
Non-Linear Stuff
(average,  std dev, 
K-clustering, 
barycenters. ..)
Average + Average = 
WRONG
Average + Average
Not Composeable!
lost‘ 0 r W lrlrlilrlis
ml}  DID WDUESD
avg =  sum I count

avg =  sum I count
avg =  sum I count

; |-'
avg =  sum I count
avg =  sum I count

+ +
avg =  sum I count
avg =  sum I count

+ +
avg =  sum I count

avg =  sum I count
(sum,  count)

+
(sum,  count)

sum,  count)
rage

  
 

A
(sum,  sum2, count)
+

(sum,  sum2, count)

(sun 5 m2, count)
Can model as a
monoid even non-
linear stuff!
C
I
3 : . '—;  I

. '.'. '2"_ll'—. ‘.'J'—_:  '2. '. 'jI. ll 3:’.
Monoid several times. ..

MailingList

toString() :  String

union (MailingList) :  Mailing ist
intersection(MailingList) ...
average temperature
=  t1.add(t2)
. sca1e(1/2
Change -> new instance

public Temperature add(Temperature other) {
return new Temperature(value + othentoie-lsius(). valu...
Space Vector

Temperature

toCelsius() :  Temperature
toFarenheit() :  Temperature
add(Temperature) :  Temperatu e

scale ...
Why

is it useful?
Cashflow Sequence
+

Cashflow Sequence

Cashflow Sequence
This is how domain
experts THINK

about it /  

SKETCH SAY
IlEI}ll| Iil| TI| lE

STYIE
Much less code
Much less bugs
.. . ,  ..  . .  .. . Tx. ...  . 3 . . . , ,  , .  . ,  .,  ..  :.  .
.  . . . .  ,  .  .. 
. A . , .  ,.  . I , . F .  , ...
//  without monoiols
PaymentsFees (.  . . )
Paymenl: sFeesl/ lithOptions (.  . . )
PaymentsFeesl/ lithInsuranceAnolC
Payme...
//  with monoiols

fees (.  . .  ) :  Payments
options (.  . . ) :  Payments
insurance(.  . .  ) 2 Payments

Payments. ado...
Very easy to test

side—effect—

free
operation

 

input output
Much less stuff to
learn
Cashflow Sequence
+

Cashflow Sequence

Cashflow Sequence
Definition [ed t]

A monoid is a set.  S,  together with a binary operation  (pronounced "dot‘ or “times ') that satisfies ...
Literature
Documented
MailingList

@Monoic1(neu‘i: ral= "emp'tyLis't")
intersection (MailingList) :  Mail'ngList

  
 

emptyL: i.st() :  Mailin...
IIIIING

Il00|lMEN'I'l| 'I'ION
Write code that
tells the business
domain stories
generic naming

MailingList

@Monoid(neutral= "emptyList")
intersection(MailingList) :  MailingList

emptyList() :  Mailin...
Domain-Specific naming

MailingList

@Monoid(neutral= "nobody")
overlapping(MailingList) :  MailingList

nobody() :  Maili...
Sill‘-
EKPIAINING

IIMIIES
T  WE WANT: 

Traceability
of processing
No worry!
Just enrich our
types
Just enrich our
types

public Temperature add(Temperature other) {
return new TempIroture(value 4 other. toCelsius(). volu...
Just enrich our
types

label field

<termInatea> TemperatureTest UUIIIII

zero 4 65°F 4 14°C " 0.5
Monad-ish

No logging needed

Each value stores
its history

<t8l'fT| ll'I8tCd> TCWIDCYEIUVETCSI UUflit]

zero 4 65°F 4 14°...
"$4:-I v. 

     

 

1»
,1 . '
7.~/ 
‘ .1
at’, 
"' : .
‘tfvrv ,  M.  .
‘I ' ‘ K ' 1 ’. 
I ’ "ml at .  . ‘ 3” . 
. pt. ‘ ,...
In Closing
Composeability
Composeability
Composeability
Composeability
Composeability
Composeability
Invest time: 

Learn DDD,  and get
free FP exposure
A paradox: 

FP influence helps
craft better Obi ect-
Oriented code!
So simple, 
most people
have no

appreciation
of that!
Monoids

are good: 
Eat Them!
Also learn other
maths structures
WIKIPEDIA

Espafiol
La ei". c~cl'opect. a l| .'3r‘e
$80 000- artlculcs

English
The Free E r‘-c_. =ci'o_oed~a
-‘ 200 000- a...
TDD

Taste-Driven
Development

@cyriux
‘ ‘K
 3*’

WHEN GOOD TFISTE GOES BED PETS HBE OFTEN THE FIRST TO SUFFEFI FROM SUCH SFID TfiSTE FIHILUBE
Questions?  Did you try
similar things too? 

Let's discuss! 

@cyriux
Follow me @cyriux

Slides:  slideshare. net/ cyriux
Blog:  cyrille. martraire. com

In Paris?  Join OFO/ /Q!
<  
’ “-4 ' ' I‘ ‘I. 
f ‘ ' ’v 
‘ «‘V‘°“§  
1‘ ' l '_*: ~


 g  . 
     an - 
J * r0'ii’: ie 4 ‘  S“

‘ .  . 15¢‘ a _
D S°...
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Upcoming SlideShare
Loading in …5
×

Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015

749 views

Published on

Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015

Published in: Software
  • Be the first to comment

Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015

  1. 1. Monoids, . 'lVlnoids everywherg
  2. 2. ean mag tell lliflerenee?
  3. 3. r-
  4. 4. ‘U /5;‘ ” i *7‘?
  5. 5. This talk is “IE EIIISWGI
  6. 6. (dedicated to @ziobrando' htt : //rosshirt. b|o s ot. fr/
  7. 7. Passionate developer PARIS Since 1999 @cyriux Cyrille Martraire
  8. 8. T . . I-1-o! A.. «.s. .w , . . . . . . r .4 u, .. ... ‘. . ... ..u. ~ 1,‘: -.f/ b*: .: *‘; a1*.1-ihiihv/ r 5’- I «-~--: ' ' '. ¢. _~_. - M
  9. 9. The illlllliflillll SIIIIW features Illl Sllfllilalllllaf Sllllll, Illl IWB Bllllillll, lllllll trivial Java BIIIIB. Vllll can re-create III re-enact at Illllllfl Willi Illl danger.
  10. 10. a bit personal
  11. 11. Adopted 2005 Still in love
  12. 12. What do DDD 8 FP have in common?
  13. 13. "My first encounter with FP concepts was from DDD"
  14. 14. Fp= ?
  15. 15. @ Clojure lscala Haskell A Purely Functional Language
  16. 16. http: //www. 'aider. net/ archives/609-intro-to-functional-programming/
  17. 17. KJJ IH ILHIT
  18. 18. So what do DDD 8 FP have in common?
  19. 19. Value Objects . ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... . . . 19 intention-Revealing Interfaces . ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. . . 28 Side-Effect-Free Functions . ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. . . 29 Assertions . ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. 30 (C) 2011 Domain Language, inc. 2 K Standalone Classes . ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... . . . 31 Closure of Operations . ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. 32 Declarative Design . ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. . . 33 A Declarative Style of Design . ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... . . . 33 Drawing on Established Formalisms . ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. 34
  20. 20. DDD+F P
  21. 21. Example
  22. 22. ’ I ii. » I. it F‘ ‘K7 iwfi
  23. 23. Closure Associativity Neutral Element
  24. 24. ilifli Sii ll? WQFH Mi ism li»lili! SEll~lSE
  25. 25. only 3 numbers in programming
  26. 26. “9 19
  27. 27. Monoid: encapsulate diversity inside
  28. 28. Operation Neutral Element t‘, I, MANY I Element
  29. 29. Encapsulate special cases —> simple again
  30. 30. Battle against complexity
  31. 31. X COO K
  32. 32. X COO K
  33. 33. Applied often: —> scalable process —> can grow to high complexity
  34. 34. Scalable in complexity
  35. 35. oo FTW’ For a given interface I find myself doing often o, 1, Many
  36. 36. Composite Null0biect t‘, I, MANY I lmplementation(s)
  37. 37. Identity Element = Null0bi ect VatCa1cu1at1’on. NONE
  38. 38. Example
  39. 39. Numbers int+int= int (3+s)+z=3+(s+z) 0
  40. 40. Lists (-)"'(-7-)= (-9-9-) (a)"'(b, C)= (a, b)"'(C) ()
  41. 41. Strings "hello"+"world" I| CY| |+| |riI| +I| ]-J-ell
  42. 42. look simplistic; the key to very complex behavior
  43. 43. The key to infinite scalability! (space)
  44. 44. The key to infinite incremental computing! (time)
  45. 45. Hadoop x Storm
  46. 46. Composeability
  47. 47. Abstractions in the small that compose at large
  48. 48. Monoids it reduce
  49. 49. Monoids if domain
  50. 50. Monoids it do O
  51. 51. Monoids: typical FP
  52. 52. FP: Everything is a value
  53. 53. Therefore: Monoids are values!
  54. 54. Immutable Equals by value
  55. 55. Value Object A DDD pattern to import FP-ish values in 00 languages
  56. 56. Not Anemic
  57. 57. Change -> new instance public Temperature add(Ternperature other) i"5ta"°e return new Temperature(va1ue + other. toielsius(). va1ue, TemperatureUnit. C£LSIUS);
  58. 58. SIDE-EFFECT -TTBE FUNCTIONS
  59. 59. lmmutability 8 Side-effect-free functions!
  60. 60. “Functional-First” style _ V a Aaron Erickson *' Aa rm n E r: C H5 0 n I have heard the meme of "functional first" programming a few times now. i. e. you start with functional, and do state by exception. I like. {A Reply ti Retweeted * Favorite = ET~; '~. EET~3 5 I I Bill from Romeoville, IL 1 1] DE. F'l. l — ‘1E~ l. Zl= :t ‘l '1 41.3 wet: Er‘r1l: aed this Tweet
  61. 61. “Functional-First” style 90%
  62. 62. Money
  63. 63. (25, EUR) + (30, EUR) (55, EUR)
  64. 64. (25, EUR) + (30, USD) exception
  65. 65. Money <<ValueObject>> amount currency add (Money) : Money
  66. 66. itAY<1’N FovLe& Intro Design Agie Refactorlng NOSOL DSL Delivery About Me Quantity Represent dimensioned values with both their amount and their unit There are many cases where we want computers to represent dimensioned quantities: values such as six feet. or thirty kilograms. Usually these are represented as bare numbers. mainly because that is the best we can do in the limited type systems that languages give us.
  67. 67. Cashflows (Payments)
  68. 68. (25, EUR, today) + (30, EUR, today) (55, EUR, today)
  69. 69. (25, EUR, today) + (30, EUR, next day) exception
  70. 70. )CashFlow| <<ValueObject>> amount currency date add Cas F ow : »
  71. 71. ciogunr OPERATION
  72. 72. Cashflows Sequences
  73. 73. Cashflow Sequence + Cashflow Sequence Cashflow Sequence
  74. 74. Obiect Arithmetics V
  75. 75. This is how domain experts THINK about it / SKETCH SAY
  76. 76. I U C 5 I 1 I . rl. v-. «.rr. -at —, Ul= .«: .l“= _.«’! ur. rl'-. »:
  77. 77. Ranges
  78. 78. [1, 31 Union * [2, 41 [1,-41 * for a bounding box-kind definition of union
  79. 79. Predicates
  80. 80. Filter AND Filter Filter
  81. 81. Filter OR Filter Filter
  82. 82. Grants
  83. 83. Read, Write, Execute "most secure wins" r W + x = W
  84. 84. Configuration Maps
  85. 85. IC . as as + __ Default esk s ecif
  86. 86. Default Desk-s - ecific
  87. 87. Non-Linear Stuff (average, std dev, K-clustering, barycenters. ..)
  88. 88. Average + Average = WRONG
  89. 89. Average + Average Not Composeable!
  90. 90. lost‘ 0 r W lrlrlilrlis
  91. 91. ml} DID WDUESD
  92. 92. avg = sum I count avg = sum I count
  93. 93. avg = sum I count ; |-' avg = sum I count
  94. 94. avg = sum I count + + avg = sum I count
  95. 95. avg = sum I count + + avg = sum I count avg = sum I count
  96. 96. (sum, count) + (sum, count) sum, count) rage A
  97. 97. (sum, sum2, count) + (sum, sum2, count) (sun 5 m2, count)
  98. 98. Can model as a monoid even non- linear stuff!
  99. 99. C I 3 : . '—; I . '.'. '2"_ll'—. ‘.'J'—_: '2. '. 'jI. ll 3:’.
  100. 100. Monoid several times. .. MailingList toString() : String union (MailingList) : Mailing ist intersection(MailingList) : ailing nobody() : MailingList everybod_y() : MailingList
  101. 101. average temperature = t1.add(t2) . sca1e(1/2
  102. 102. Change -> new instance public Temperature add(Temperature other) { return new Temperature(value + othentoie-lsius(). value, TemperatureUnit. C£L$IUS); } public Temperature scale-(double factor) { i"5ta"Ce return new Temperature(value ’ factor, unit); }
  103. 103. Space Vector Temperature toCelsius() : Temperature toFarenheit() : Temperature add(Temperature) : Temperatu e scale ou le : Temperature
  104. 104. Why is it useful?
  105. 105. Cashflow Sequence + Cashflow Sequence Cashflow Sequence
  106. 106. This is how domain experts THINK about it / SKETCH SAY
  107. 107. IlEI}ll| Iil| TI| lE STYIE
  108. 108. Much less code Much less bugs
  109. 109. .. . , .. . . .. . Tx. ... . 3 . . . , , , . . , ., .. :. . . . . . . , . .. . A . , . ,. . I , . F . , . .». to} . k . . ~. , v , , L . .. . 7 _ . H, .. . . . . . e _ . ... 1 . . . l ,1, . . _. . . M . ., . i . I . . . . . I. .. 1 _ (3 . . . . 5 . .. . . . .3 . .w 3,, rl. ,. . : .. . in l ! Y. . . . , s . . _ w . .. l . . 4 v. . . . F . ., . , . . J. . . __ . .. . . . . . . . . .. . _. . . . , . _ l . , _ u . ‘ i L . . . , a . l. _ W 1 . .. ..l, . . . . l.. .., J. ,. _, .raKtcriwm, ememw§. .€ri . H . . A. .. . . h. ... ... . . i l we m. 1 l. . . n. . , _ , ... . . . . .. .. w. ... Ua. i. . w l u 1.3.). .. wnrr: _. _. 1
  110. 110. // without monoiols PaymentsFees (. . . ) Paymenl: sFeesl/ lithOptions (. . . ) PaymentsFeesl/ lithInsuranceAnolC PaymentsFeesl/ xlithlnsurance(. . . 1loFeesButInsurance(. . . )
  111. 111. // with monoiols fees (. . . ) : Payments options (. . . ) : Payments insurance(. . . ) 2 Payments Payments. adol(Payments) Payments
  112. 112. Very easy to test side—effect— free operation input output
  113. 113. Much less stuff to learn
  114. 114. Cashflow Sequence + Cashflow Sequence Cashflow Sequence
  115. 115. Definition [ed t] A monoid is a set. S, together with a binary operation (pronounced "dot‘ or “times ') that satisfies the following three axiom: Closure For all a. b in S. the result cl the operation a ~ b is also in S. Associativity For all a. band c in S. the equation (a - b) - c - a - (b - c) holds. Identity element There exists an element e in S. such that lor all elements a in S. the equation e - a — a - e — a holds. And in mathematical notation we can write these as - Closure: Va. b E S : (1-b 6 S. ~ A$S°CiativilvIVa. b.c E S: (a -b) - c = (1-(b-c)and - Identityelementac E S ; Va 6 S ; (1 - (1 : (1 . 5 : (1.
  116. 116. Literature Documented
  117. 117. MailingList @Monoic1(neu‘i: ral= "emp'tyLis't") intersection (MailingList) : Mail'ngList emptyL: i.st() : MailingList
  118. 118. IIIIING Il00|lMEN'I'l| 'I'ION
  119. 119. Write code that tells the business domain stories
  120. 120. generic naming MailingList @Monoid(neutral= "emptyList") intersection(MailingList) : MailingList emptyList() : MailingList
  121. 121. Domain-Specific naming MailingList @Monoid(neutral= "nobody") overlapping(MailingList) : MailingList nobody() : MailingList
  122. 122. Sill‘- EKPIAINING IIMIIES
  123. 123. T WE WANT: Traceability of processing
  124. 124. No worry!
  125. 125. Just enrich our types
  126. 126. Just enrich our types public Temperature add(Temperature other) { return new TempIroture(value 4 other. toCelsius(). volue, TernperotureUnit. C£L$1U$, label 4 " 4 " 4 other. lobel); } public Temperature scole(double factor) { return new Temperoture(volue ‘ factor, unit, label 4 " ‘ " 4 factor); }
  127. 127. Just enrich our types label field <termInatea> TemperatureTest UUIIIII zero 4 65°F 4 14°C " 0.5
  128. 128. Monad-ish No logging needed Each value stores its history <t8l'fT| ll'I8tCd> TCWIDCYEIUVETCSI UUflit] zero 4 65°F 4 14°C ‘ 0.5
  129. 129. "$4:-I v. 1» ,1 . ' 7.~/ ‘ .1 at’, "' : . ‘tfvrv , M. . ‘I ' ‘ K ' 1 ’. I ’ "ml at . . ‘ 3” . . pt. ‘ , -7 , . V . l I. ' . , » J ‘- ~. « 1;: ' ; _ ' - so. V_x _ > ‘aoan. ___, , >4": -.; — ‘I’. ‘ 4 ' , —— : f’*'‘-, '. ''n'. I ‘w "' _ _-sup , — ‘ .4 -*" 4 , _ . -.— __ ,4. __(»: /‘ I 4 , x I . » 1 I ‘ ~ l l I i l ' , l 4. . ' ! ' i r’ / ‘ . A l “ . ~ ’ ‘ z . ; ‘ ’ } K httgz/ t/étularlcook. fi| es. wordpresscom/2010/11/happy-monkeyfipg I ‘ r
  130. 130. In Closing
  131. 131. Composeability Composeability Composeability Composeability Composeability Composeability
  132. 132. Invest time: Learn DDD, and get free FP exposure
  133. 133. A paradox: FP influence helps craft better Obi ect- Oriented code!
  134. 134. So simple, most people have no appreciation of that!
  135. 135. Monoids are good: Eat Them!
  136. 136. Also learn other maths structures
  137. 137. WIKIPEDIA Espafiol La ei". c~cl'opect. a l| .'3r‘e $80 000- artlculcs English The Free E r‘-c_. =ci'o_oed~a -‘ 200 000- articles El $33 A . V Deutsch ‘—_"(': §?3'§j““ A ‘ 4‘ _ ‘Vt ‘ : —~ ‘ A De freie t'(ru~'l<l‘opéd»e 5? 1/. -El 0” ts” 7”’! 5' A A A’ ‘°‘ 5/ t T‘=700f'/ ‘(V A} l ' _) v 4 I ‘ ’ ye air’ I J *3 '‘‘‘'< J_ i) l ’ i ( ~< ~~ gzis ( . Ceofioéaafi : «~. ~u»: 'fo= ec'. *us - - A ' l_e. "~c_r~‘c»’opedle l’l. ‘3r'e sec 000- c‘ra'rei" A la ifmc fi—amr: les ‘ a 4 as , ,.i . < (‘N crclge. l"I-, Va ' ‘ ‘ -4‘ ‘ 5 I] . a . 5,, .00‘, .da 5 1020 000- -‘CC-I 950 000- nasal Portugués : |J3{ A er-‘. c.r: .’oAoéd-3 EEHB"]§l5l$§ 770 000- amgcs . . . . . .
  138. 138. TDD Taste-Driven Development @cyriux
  139. 139. ‘ ‘K 3*’ WHEN GOOD TFISTE GOES BED PETS HBE OFTEN THE FIRST TO SUFFEFI FROM SUCH SFID TfiSTE FIHILUBE
  140. 140. Questions? Did you try similar things too? Let's discuss! @cyriux
  141. 141. Follow me @cyriux Slides: slideshare. net/ cyriux Blog: cyrille. martraire. com In Paris? Join OFO/ /Q!
  142. 142. < ’ “-4 ' ' I‘ ‘I. f ‘ ' ’v ‘ «‘V‘°“§ 1‘ ' l '_*: ~ g . an - J * r0'ii’: ie 4 ‘ S“ ‘ . . 15¢‘ a _ D S°£hV3T€ imi |

×