Top Banner
F# AS OUR DAY JOB BY 2016 Oslo/NDC Oslo Tomas Jansson 19/06/2015
77

F# as our day job by 2016

Aug 04, 2015

Download

Technology

Tomas Jansson
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: F# as our day job by 2016

F# AS OUR DAY JOB BY 2016

Oslo/NDC OsloTomas Jansson19/06/2015

Page 2: F# as our day job by 2016

THIS IS ME!

Tomas JanssonManager & Practice Lead .NETBEKK Oslo

@[email protected]/mastojslideshare.net/mastojblog.tomasjansson.com

Page 3: F# as our day job by 2016

http://www.eatsleepcoderepeat.de/beitraege_2013_10.htm

Page 4: F# as our day job by 2016

Sad & misundersto

od

Page 5: F# as our day job by 2016

C#95%

F#5%

Programming at work in 2015

Page 6: F# as our day job by 2016

I want to be the hero!

Page 7: F# as our day job by 2016

C#50%

F#50%

Programming at work in 2016

Page 8: F# as our day job by 2016

Why change?

Page 9: F# as our day job by 2016

Time

Awesomeness

TOMAS’ GRAPH OF AWESOMENESS

No change

Page 10: F# as our day job by 2016

Time

Awesomeness

TOMAS’ GRAPH OF AWESOMENESS

No change

Change

Page 11: F# as our day job by 2016

Time

Awesomeness

TOMAS’ GRAPH OF AWESOMENESS

No change

Change

You can’t improve without change!

Page 12: F# as our day job by 2016

Application

Page 13: F# as our day job by 2016

With plumbing

Application

Page 14: F# as our day job by 2016

Extra complexity

Application

Page 15: F# as our day job by 2016

Application

Extra complexity

Page 16: F# as our day job by 2016

Why do I like F#?

The facts!

What can you

do?

Page 17: F# as our day job by 2016

Why do I like F#?

Page 18: F# as our day job by 2016

#1: Good habits

Page 19: F# as our day job by 2016

#2: Separation

Page 20: F# as our day job by 2016

#2: Separation

"Objects are not data structures. Objects may use data structures; but the manner in which those data structures are used or contained is hidden. This is why data fields are private. From the outside looking in you cannot see any state. All you can see are functions. Therefore Objects are about functions not about state."

Uncle Bob - http://blog.cleancoder.com/uncle-bob/2014/11/24/FPvsOO.html

Page 21: F# as our day job by 2016

#2: Separation

"Objects are not data structures. Objects may use data structures; but the manner in which those data structures are used or contained is hidden. This is why data fields are private. From the outside looking in you cannot see any state. All you can see are functions. Therefore Objects are about functions not about state."

Uncle Bob - http://blog.cleancoder.com/uncle-bob/2014/11/24/FPvsOO.html

Page 22: F# as our day job by 2016

#3: Null handling

Page 23: F# as our day job by 2016

#3: Null handling

Null References: The Billion Dollar Mistake

- Sir Charles Antony Richard Hoare http://tinyurl.com/TheBillionDollarMistake

Page 24: F# as our day job by 2016

#3: Null handling

type Order = {OrderId: int; Total: int}

let getOrder orderId = match orderId with | 0 -> None | _ -> Some { OrderId = orderId Total = 23*orderId }

let printOrder order = match order with | Some o -> printfn "Order id: %i, Total: %i« o.OrderId o.Total | None -> printfn "No order"

Page 25: F# as our day job by 2016

#3: Null handling

type Order = {OrderId: int; Total: int}

let getOrder orderId = match orderId with | 0 -> None | _ -> Some { OrderId = orderId Total = 23*orderId }

let printOrder order = match order with | Some o -> printfn "Order id: %i, Total: %i« o.OrderId o.Total | None -> printfn "No order"

Returns Order option

Page 26: F# as our day job by 2016

#3: Null handling

type Order = {OrderId: int; Total: int}

let getOrder orderId = match orderId with | 0 -> None | _ -> Some { OrderId = orderId Total = 23*orderId }

let printOrder order = match order with | Some o -> printfn "Order id: %i, Total: %i« o.OrderId o.Total | None -> printfn "No order"

Returns Order option

Explicit null

handling!

Page 27: F# as our day job by 2016

#3: Null handling

public class Order{ public int OrderId { get; set; } public int Total { get; set; }}

public Order GetOrder(int orderId){ if (orderId == 0) return null; return new Order() { OrderId = orderId, Total = 23*orderId };}

public void PrintOrder(Order order){ Console.WriteLine("Order id: {0}, Total: {1}", order.OrderId, order.Total);}

Page 28: F# as our day job by 2016

#3: Null handling

public class Order{ public int OrderId { get; set; } public int Total { get; set; }}

public Order GetOrder(int orderId){ if (orderId == 0) return null; return new Order() { OrderId = orderId, Total = 23*orderId };}

public void PrintOrder(Order order){ Console.WriteLine("Order id: {0}, Total: {1}", order.OrderId, order.Total);}

How do I differ

success from

failure?

Page 29: F# as our day job by 2016

#3: Null handling

public class Order{ public int OrderId { get; set; } public int Total { get; set; }}

public Order GetOrder(int orderId){ if (orderId == 0) return null; return new Order() { OrderId = orderId, Total = 23*orderId };}

public void PrintOrder(Order order){ Console.WriteLine("Order id: {0}, Total: {1}", order.OrderId, order.Total);}

How do I differ

success from

failure?

What about null?

Page 30: F# as our day job by 2016

#4: Types

Page 31: F# as our day job by 2016

#4: Types

type Customer = { CustomerId: Guid FirstName: string LastName: string }

Page 32: F# as our day job by 2016

#4: Types

public class Customer { public Guid CustomerId { get; private set; } public string FirstName { get; private set; } public string LastName { get; private set; }

public Customer(Guid customerId, string firstName, string lastName) { CustomerId = customerId; FirstName = firstName; LastName = lastName; }

protected bool Equals(Customer other) { return CustomerId.Equals(other.CustomerId) && string.Equals(FirstName, other.FirstName) && string.Equals(LastName, other.LastName); }

public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; if (obj.GetType() != this.GetType()) return false; return Equals((Customer) obj); }

public override int GetHashCode() { unchecked { var hashCode = CustomerId.GetHashCode(); hashCode = (hashCode*397) ^ (FirstName != null ? FirstName.GetHashCode() : 0); hashCode = (hashCode*397) ^ (LastName != null ? LastName.GetHashCode() : 0); return hashCode; } }}

Page 33: F# as our day job by 2016

#5: Type providers

Strongly typed «ORM»

SQL JSON XML WCF …

Page 34: F# as our day job by 2016

#5: Type providers

Page 35: F# as our day job by 2016

#6: Readability

Page 36: F# as our day job by 2016

#6: Readability

Page 37: F# as our day job by 2016

#6: Readability

Page 38: F# as our day job by 2016

#6: Readability

Page 39: F# as our day job by 2016

#6: Readability

Page 40: F# as our day job by 2016

#6: Readability

Page 41: F# as our day job by 2016

#6: Readability

Page 42: F# as our day job by 2016

#6: Readability

Page 43: F# as our day job by 2016

#6: Readability

Page 44: F# as our day job by 2016

#6: Readability

Page 45: F# as our day job by 2016

#6: Readability

Page 46: F# as our day job by 2016

#6: Readability

Page 47: F# as our day job by 2016

#6: Readability

Page 48: F# as our day job by 2016

#6: Readability

Page 49: F# as our day job by 2016

#6: Readability

Page 50: F# as our day job by 2016

#6: Readability

Page 51: F# as our day job by 2016

#6: Readability

// Version 1let executeCommand command = command |> validate |> log |> execute |> loglet result = executeCommand command

// Version 2let executeCommand = validate >> log >> execute >> loglet result = executeCommand command

Page 52: F# as our day job by 2016

#6: Readability

// Version 1public ExecutionResult ExecuteCommand(Command command){ return Log(Execute(Log(Validate(command))));}var result = ExecuteCommand(new Command());

// Version 2public ExecutionResult ExecuteCommand(Command command){ var validationResult = Validate(command); Log(validationResult); var executionResult = Execute(validationResult); Log(executionResult); return executionResult;}var result = ExecuteCommand(new Command());

Page 53: F# as our day job by 2016

The facts!

Page 54: F# as our day job by 2016

@simontcousins

@ScottWlaschin

http://tinyurl.com/CyclesInTheWild

http://tinyurl.com/DoesTheLanguageMakeADifference

Page 55: F# as our day job by 2016

Cycles

Compared 10 C# projects with 10 F# projects

Compared «top-level» types

Top-level type: “a type that is not nested and which is not compiler generated”

@ScottWlaschin

http://tinyurl.com/CyclesInTheWild

Page 56: F# as our day job by 2016

PROJECTS

Mono.Cecil, which inspects programs and libraries in the ECMA CIL format

NUnit

SignalR for real-time web functionality

NancyFx, a web framework

YamlDotNet, for parsing and emitting YAML

SpecFlow, a BDD tool

Json.NET

Entity Framework

ELMAH, a logging framework for ASP.NET

NuGet itself

Moq, a mocking framework

NDepend, a code analysis tool

FSharp.Core, the core F# library.

FSPowerPack.

FsUnit, extensions for NUnit.

Canopy, a wrapper around the Selenium test automation tool.

FsSql, a nice little ADO.NET wrapper.

WebSharper, the web framework.

TickSpec, a BDD tool.

FSharpx, an F# library.

FParsec, a parser library.

FsYaml, a YAML library built on FParsec.

Storm, a tool for testing web services.

Foq, a mocking framework.

C#

F#

Page 57: F# as our day job by 2016
Page 58: F# as our day job by 2016
Page 59: F# as our day job by 2016
Page 60: F# as our day job by 2016
Page 61: F# as our day job by 2016

SpecFlow

Page 62: F# as our day job by 2016

SpecFlow

I do think SpecFlow is great tool!

Page 63: F# as our day job by 2016

TickSpec

Page 64: F# as our day job by 2016

Does your language matter?

Application to assist in maintaining the stability and security of the electricity supply in the UK

Existing solution almost fully implemented in C#

Rewritten in F#

@simontcousins

http://tinyurl.com/DoesTheLanguageMakeADifference

Page 65: F# as our day job by 2016
Page 66: F# as our day job by 2016
Page 67: F# as our day job by 2016

“The C# project took five years and peaked at ~8 devs. It never fully implemented all of the contracts.

The F# project took less than a year and peaked at three devs (only one had prior experience with F#). All of the contracts were fully implemented.”

http://tinyurl.com/DoesTheLanguageMakeADifference

Page 68: F# as our day job by 2016

THE LANGUAGE YOU USE MAKE A DIFFERENCE

Encapsulated small types

Less top-level dependencies

Less «leaky» abstractions

Types and functions must be defined

Prevents cycles

Encapsulation

Much easier to do in F#

Linear

Generics

Page 69: F# as our day job by 2016

What can you

do?

Page 70: F# as our day job by 2016

Read

Code

Page 71: F# as our day job by 2016
Page 73: F# as our day job by 2016

http://www.peoplevine.com/page/peoplevine-for-startups

Start small, but think

big!

Page 74: F# as our day job by 2016

Demo?

Page 75: F# as our day job by 2016

RESOURCES

http://fsharpforfunandprofit.com/

http://tinyurl.com/DoesTheLanguageMakeADifference

http://www.meetup.com/OsloFSharp/ (if you live in Oslo)

http://fsharp.org/

Page 76: F# as our day job by 2016

Questions?

Page 77: F# as our day job by 2016

Thank you!

@TomasJansson

Vote!