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.

Real World F# - SDD 2015

826 views

Published on

Real World F# talk presented at the SDD conference at the Barbican, London in May 2015

Published in: Software
  • Be the first to comment

  • Be the first to like this

Real World F# - SDD 2015

  1. 1. REAL-WORLD F# Phil Trelford SDD, 2015
  2. 2. F# TAGLINE F# is a practical, functional-first language that lets you write simple code to solve complex problems
  3. 3. CASE STUDY Phil Trelford, @ptrelford #SDDConf, 2015
  4. 4. I am still waiting for the first bug to come in, E-On
  5. 5. ANALYSIS OF 2 SIMILAR APPS C# 8 developers peak 5 years Requirements not met F# 2 developers peak < 1 year Requirements met
  6. 6. LINES OF CODE Implementati on 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
  7. 7. CODE PATHOGENS Logging Exception handling
  8. 8. SUMMARY I can fit the whole F# solution in the blank lines of the C# solution with 7,000 lines to spare. WTF C#! OMG F#! I have spent most of my life writing buggy, bloated software that was impossible to reason about. What was I thinking?
  9. 9. LIVE DEMOS Phil Trelford, @ptrelford #SDDConf, 2015
  10. 10. THOUGHTWORKS TECH RADAR 2012 F# “F# is excellent at concisely expressing business and domain logic.” Languages
  11. 11. CURRENCY CONVERSIONS [<Measure>] type EUR [<Measure>] type GBP let rateEurGbp = 0.783M<GBP/EUR> // Converts amount in EUR to GBP let euroToPounds (eur:decimal<EUR>) = eur * rateEurGbp
  12. 12. UNITS IN CELLS type formula = | Neg of formula | Exp of formula * formula | ArithmeticOp of formula * arithmetic * formula | LogicalOp of formula * logical * formula | Num of UnitValue | Ref of int * int | Range of int * int * int * int | Fun of string * formula list
  13. 13. UNITS OF MEASURE
  14. 14. SQL TYPE PROVIDER
  15. 15. AUTOMATING 2048 WITH CANOPY start firefox url "http://gabrielecirulli.github.io/2048/ press up press left press right let score = element ".score-container" printfn "Score %s" score.Text
  16. 16. MARIO TUTORIAL
  17. 17. FUNCTIONAL C# Phil Trelford, @ptrelford #SDDConf, 2015
  18. 18. FUNCTIONAL C# - MAP/REDUCE using System; using System.Collections.Generic; public class Enumerable { public static IEnumerable<TResult> Map<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> func) { foreach(var item in source) { yield return func(item); } } public static TAccumulate Reduce<TSource,TAccumulate>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate,TSource,TAccumulate> func) { var current = seed; foreach(var item in source) { current = func(current, item); } return current; } }
  19. 19. HIGHER ORDER FUNCTIONS – C# MAP public static IEnumerable<TResult> Map<TSource, TResult>(this IEnum { foreach(var item in source) { yield return func(item); } }
  20. 20. HIGHER ORDER FUNCTIONS – F# MAP/REDUCE let map func items = for item in items do func item let reduce func seed items = let mutable acc = seed for item in items do acc <- func acc acc
  21. 21. INTEGRATING F# Phillip Trelford SDD, 2015
  22. 22. F# COMPONENT DESIGN GUIDELINES
  23. 23. C#/F# INTEROP (MOSTLY IT JUST WORKS) C# friendly Classes Interfaces Modules Records Tuples(*) F# specific Discriminated unions Function arguments Curried arguments Option Async
  24. 24. CONTINUOUS INTEGRATION F# Project - FSharp.Core App.config – Binding Redirect <?xml version="1.0" encoding="utf-8"?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /> </startup> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
  25. 25. RESOURCES Phillip Trelford SDD, 2015
  26. 26. F# Software Foundation http://www.fsharp.org software stacks trainings teaching F# user groups snippets mac and linux cross-platform books and tutorials F# community open-source MonoDevelop contributions research support consultancy mailing list
  27. 27. F# KOANS [<Koan>] let SquareEvenNumbersWithPipelineOperator() = (* In F#, you can use the pipeline operator to get the benefit of the parens style with the readability of the statement style. *) let result = [0..5] |> List.filter isEven |> List.map square AssertEquality result __
  28. 28. TRY IT BEFORE YOU BUY IT
  29. 29. BUY THE BOOK
  30. 30. QUESTIONS? Twitter  @ptrelford Blog  http://trelford.com/blog F# eXchange:  http://tinyurl.com/fsharpex

×