techdaysnl 2015 - ddd with f#
TRANSCRIPT
![Page 1: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/1.jpg)
![Page 2: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/2.jpg)
DDD with F#Ronald Harmsen
![Page 3: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/3.jpg)
"Focus on the domain and domain logic rather
than technology” Eric Evans
![Page 4: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/4.jpg)
DDD F#
![Page 5: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/5.jpg)
Why?
![Page 6: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/6.jpg)
![Page 7: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/7.jpg)
“First, it’s almost certainly true that functional programming is the next big thing. “
Robert C. Martin
![Page 8: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/8.jpg)
“Object oriented programming makes code understandable by encapsulating moving parts. Functional programming makes code understandable by minimizing moving parts.“
Michael Feathers
![Page 9: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/9.jpg)
“F# is excellent at concisely expressing business and domain logic.Developers trying to achieve explicit business logic within an Application may opt to express their domain in F# with the majority of plumbing code in C#.”
![Page 10: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/10.jpg)
Functional programming
• Declarative
• Clearity
• Composability
• Immutability
![Page 11: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/11.jpg)
Characteristic Imperative approach Functional approach
Programmer focus How to perform tasks (algorithms) how to track changes in state.
What information is desired and what transformations are required.
State changes Important. Non-existent.
Order of execution Important. Low importance.
Primary flow control Loops, conditionals, and function (method) calls. Function calls, including recursion.
Primary manipulation unit Instances of structures or classes. Functions as first-class objects
data collections.
![Page 12: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/12.jpg)
Characteristic C# F#
Programmer focus How to perform tasks (algorithms) how to track changes in state.
What information is desired and what transformations are required.
State changes Important. Non-existent.
Order of execution Important. Low importance.
Primary flow control Loops, conditionals, and function (method) calls. Function calls, including recursion.
Primary manipulation unit Instances of structures or classes. Functions as first-class objects
data collections.
![Page 13: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/13.jpg)
Why F# ?
• Functional-first
• Very strong type inference
• Integrate with other .NET technologies
• Windows, Web, Xamarin iOS & Android, Linux
The functional language in .NET
![Page 14: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/14.jpg)
DDDBut first a small introduction to functions in F#
![Page 15: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/15.jpg)
FunctionsEverything is a function
![Page 16: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/16.jpg)
let a = 10
int a () {return
10;}
![Page 17: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/17.jpg)
let sum a b = a + b
int sum (int a, int b) {return a + b;
}
![Page 18: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/18.jpg)
Composability
![Page 19: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/19.jpg)
Chaining
Chaining functions makes a service,
Chaining services makes an use-case
![Page 20: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/20.jpg)
public static class Calc {
public static decimal Square(decimal n){
return n * n;}
public static decimal MultiplyByPi(decimal n) {
return n*3.14m;}
public static decimal AreaOfCicle(decimal r){
return MultiplyByPi(Square(r));}
}
![Page 21: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/21.jpg)
module Calclet square n = n ** 2.0
let multiplyByPi n = n * 3.14
let areaOfCircle r = multiplyByPi (square (r))
![Page 22: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/22.jpg)
module Calclet square n = n ** 2.0
let multiplyByPi n = n * 3.14
let areaOfCircle r = r |> square |> multiplyByPi
![Page 23: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/23.jpg)
DDDIt’s all about modelling types
![Page 24: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/24.jpg)
Types
type Email = string
type SimplePerson = Name * Email
type AnotherPerson = { Name: string; Age: int }
![Page 25: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/25.jpg)
public class AnotherPerson{
public AnotherPerson(string name, int age){
Name = name;Age = age;
}
public string Name { get; private set; }public int Age { get; private set; }
public override int GetHashCode(){
return Name.GetHashCode() + Age.GetHashCode();}
public override bool Equals(object obj){
return Equals(obj as AnotherPerson);}
public bool Equals(AnotherPerson other){
if (other == null)return false;
return Name == other.Name && Age == other.Age;}
}
![Page 26: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/26.jpg)
module CardGameBoundedContext =
type Suit = Club | Diamond | Spade | Heart type Rank = Two | Three | Four | Five | Six
| Seven | Eight | Nine | Ten
| Jack | Queen | King | Ace
type Card = Suit * Rank type Hand = Card list type Deck = Card list type Player = {Name:string; Hand:Hand} type Game = {Deck:Deck; Players: Player list} type Deal = Deck -> (Deck * Card) type PickupCard = (Hand * Card)-> Hand
![Page 27: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/27.jpg)
module MoreTypes
type IPrintable = abstract member Print : unit -> unit
type SomeClass () = interface IPrintable with member this.Print () = printfn “Hello”
type AnotherClass (i: int) = member this.Value = imember val this.Mutable: int with get, set
![Page 28: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/28.jpg)
Demo
![Page 30: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/30.jpg)
Your feedback is important!Scan the QR Code and let us know via the TechDays App.
Laat ons weten wat u van de sessie vindt!Scan the QR Code via de TechDays App.
Bent u al lid van de Microsot Virtual Academy?! Op MVA kunt u altijd iets nieuws leren over de laatste technologie van Microsoft. Meld u vandaag aan op de MVA Stand. MVA biedt 7/24 gratis online training on-demand voor IT-Professionals en Ontwikkelaars.
![Page 31: TechDaysNL 2015 - DDD with F#](https://reader033.vdocuments.site/reader033/viewer/2022042819/55c996babb61eb4c328b470f/html5/thumbnails/31.jpg)