f# for bloba, by brandon d'imperio

23
F# for BLOBA It isn’t just for Science and Financial Domains Boring Line Of Business Applications

Upload: maslowb

Post on 29-Apr-2015

77 views

Category:

Software


0 download

DESCRIPTION

The prevalent wisdom seems to be that FSharp is only for Math, Science and Engineering. F# for Boring Line of Business Apps aims to show why it's capable of far more than that.

TRANSCRIPT

Page 1: F# for BLOBA, by brandon d'imperio

F# for BLOBAIt isn’t just for Science and Financial DomainsBoring Line Of Business Applications

Page 2: F# for BLOBA, by brandon d'imperio

imaginarydevelopment.blogspot.com @maslowjax

Brandon D’Imperio

Page 3: F# for BLOBA, by brandon d'imperio

A team that peaked at 3 developers (only one of which knew F#) finished in 1 year what a team that peaked at 8 developers couldn’t do in 5.

A Team of 3 Devs Beat a Team of 8

Page 4: F# for BLOBA, by brandon d'imperio

● @TachyusCorp - From zero to shipping product in 12 weeks ( $28 million within 26 months)

● Princeton University - F# ... made it trivial ... ( Graduate courses on Parallelism)

But That’s Just One Company Rave

Page 5: F# for BLOBA, by brandon d'imperio

Define WinImplementation C# F#

Braces 56,929 643

Blanks 29,080 3,630

Null Checks 3,011 15

Comments 53,270 487

Useful Code 163,276 16,667

App Code 305,566 21,442

Test Code 42,864 9,359

Total Code 348,430 30,801

Page 6: F# for BLOBA, by brandon d'imperio

In most ways yes.C#, F#● Test Code Ratio 14%, 44%● Useful Code Ratio 53%, 78%

o Almost half the c# code was noise● The C# was not finished and often failed to

reach near-real-time

LoC is a Terrible Metric

Page 7: F# for BLOBA, by brandon d'imperio

● Could you find bugs more easily in 1/5th of the code? 1/10th?

● OOP SOLID and Design patterns become a thing of the past o Design patterns are language bug reports -

(paraphrased) - Peter Norvigo DI is not even relevant

What Does This Mean to Me?

Page 8: F# for BLOBA, by brandon d'imperio

A Code Break - What’s Wrong? (with both)

C#

public class Contact {public string FirstName {get;set;}public string MiddleInitial {get;set;}public string LastName {get;set;}public string EmailAddress {get;set;}// true if ownership of email address

is confirmedpublic bool IsEmailVerified {get;set;}

}

F#

type Contact = {FirstName: stringMiddleInitial: stringLastName: stringEmailAddress: string// true if ownership of email address

is confirmedIsEmailVerified: bool

}

Page 9: F# for BLOBA, by brandon d'imperio

Which are optional?What are the constraints? (are all strings allowed to be unlimited length?)Which fields have a relationship?What is the domain logic?

What’s Wrong?

Page 10: F# for BLOBA, by brandon d'imperio

● Express requirements clearly

Desired Features of BLOBA Development

Page 11: F# for BLOBA, by brandon d'imperio

● Express requirements clearly - Is the flow of the code clearer with less noise?

Desired Features of BLOBA Development

Page 12: F# for BLOBA, by brandon d'imperio

● Express requirements clearly● Rapid development cycle

o Built-in REPLo Far less boilerplate codeo Production-ready code capability for non-f# devs in

2-4 weeks

Desired Features of BLOBA Development

Page 13: F# for BLOBA, by brandon d'imperio

● Express requirements clearly● Rapid development cycle● High quality deliverables

o Why don’t we sub-type ints? (Primitive Obsession)o Is that int the Id of a user or the Id of something

else?

Desired Features of BLOBA Development

Page 14: F# for BLOBA, by brandon d'imperio

● Express requirements clearly● Rapid development cycle● High quality deliverables● Fun (Ruby anyone?)

Desired Features of BLOBA Development

Page 15: F# for BLOBA, by brandon d'imperio

● No null● Extended strong typing● Enums (DU), Records (no more mapping

code), Units of Measure, Strongly typed strings!o Type Providerso Design-time checking of string formats

Features not to be missed

Page 16: F# for BLOBA, by brandon d'imperio

Units of Measure

[<Measure>]type MemberId[<Measure>]type m // meters[<Measure>]type milelet mPerMile: float<m/mile> = 1609.34<m/mile>let milesToMeters (mi:float<mile>) = mi * mPerMile

Page 17: F# for BLOBA, by brandon d'imperio

● Inheritance● Mutability● Accidental Recursion● Cyclic Dependencies

o In C# Very do-able via Web References Very do-able within an assembly

Features We’d Like to Forget

Page 18: F# for BLOBA, by brandon d'imperio

● Pattern matching● Composition over inheritance● typedefof<> and typeof<>

Features Worth Mentioning

Page 19: F# for BLOBA, by brandon d'imperio

Methods

C#public void Main(string[] args){ /* … */ }

F# ● let Main (args: string[]) = ...● let Main (args: string array) = …● let Main args = ...

Page 20: F# for BLOBA, by brandon d'imperio

Method calling options

let HelloWorld a b c = …let HelloWorld (a,b,c) = …let HelloWorld (a,b) c = … // different// more concretelet ProcessName first m last = …

Page 21: F# for BLOBA, by brandon d'imperio

● Compiler comparisono LoC

Roslyn C# - almost 500k lines of code F# - 150k lines of code over half the C# lines are non-useful

o Cycles 899 mutually dependent classes vs ZERO

More stats

Page 22: F# for BLOBA, by brandon d'imperio

Warts● (args:string[]) [] means array here every other context in F# [ ] would be a

list.● required fun! fun e -> e instead of C#’s e => e● printfn with [<Measure>] (fixed in next version most likely)● this. everywhere inside a type● no protected members● Property syntaxes ( immutable, mutable) (auto option)

o member this.MyProp = foo //immutable o member this.MyProp with get() = … // mutable o member val MyProp = “” // auto immutableo member val MyProp = “” with get,set // auto mutable

Page 23: F# for BLOBA, by brandon d'imperio

Links● My blog

o http://imaginarydevelopment.blogspot.com/o Why am I so enthusiastic about F#? -

http://imaginarydevelopment.blogspot.com/2014/06/why-am-i-so-enthusiastic-about-f.html● F# cheat sheet - http://dungpa.github.io/fsharp-cheatsheet/● Domain Driven Design using the F# type system -

https://www.slideshare.net/slideshow/embed_code/28992749 - Scott Wlaschin● Does the language you use make a difference (revisited) -

http://simontcousins.azurewebsites.net/does-the-language-you-use-make-a-difference-revisited/● What about inheritance? -

http://codewonderings.blogspot.com/2012/09/what-about-inheritance.html● SOLID: the next step is Functional

http://blog.ploeh.dk/2014/03/10/solid-the-next-step-is-functional/ - Mark Seemann