SlideShare une entreprise Scribd logo
1  sur  61
Télécharger pour lire hors ligne
Jon Harrop, Flying Frog Consultancy
 Jon Harrop
 Started programming in 1981
BASIC, Pascal, 6502, ARM, C, C++
 At British Petroleum in 1995
UFI
 Physics and Chemistry at Cambridge
Fortran, SML, OCaml, Mathematica, F#
 Co-founded Flying Frog in 2005
◦ Sell books, software and consultancy services
◦ Over 1,100 clients in industry using OCaml & F#
 One of the world’s largest insurance
companies.
 One of the world’s largest insurance
companies.
 Actually, almost everyone else too…
1. An ordinary delivery process
2. Streamlining the delivery process
3. Technical aspects of the solution
 Automate repetition
◦ Traders in a pit
◦ Actuaries with calculators
 Use computers!
 Much better performance
◦ Latency
◦ Throughput
 More sophisticated algorithms
1. Business idea!
1. Business idea!
2. Model idea: MS Excel.
1. Business idea!
2. Model idea: MS Excel.
3. Build idea: C++/Java/C#.
1. Business idea!
2. Model idea: MS Excel.
3. Build idea: C++/Java/C#.
4. Test idea: NUnit (feedback to 2)
1. Business idea!
2. Model idea: MS Excel.
3. Build idea: C++/Java/C#.
4. Test idea: NUnit (feedback to 2)
5. Deploy production code.
Room for improvement?
Room for improvement in:
 Classic waterfall approach.
◦ Iterations are an absolute killer.
 Delivery speed and cost.
◦ This is a long journey.
So what does an iteration look like?
 First iteration highlights issues.
◦ Civilized discussion.
 First iteration highlights issues.
◦ Civilized discussion.
 Second iteration, more issues.
◦ Stressful disagreements.
 First iteration highlights issues.
◦ Civilized discussion.
 Second iteration, more issues.
◦ Stressful disagreements.
 Later iterations.
◦ Wild fighting.
Big problems:
 Accuracy.
◦ Excel/Word are too free-form.
 Complexity.
◦ Models are complicated, lots of dispatch.
 Latency.
◦ Complected testing.
Old process:
 See the forest for the trees.
◦ Don’t just rewrite code in language du jour!!!
◦ Common mistake when adopting new technologies.
 Overhaul the delivery process…
A new process:
Observations
Observations
 Separate people/jobs
◦ One person uses Tool to turn ideas into products.
◦ Another person maintains Tool.
 Separate tests
◦ Tests for the model.
◦ Unit test for the Tool.
Advantages
Advantages:
 Business people ship products themselves!
 Less contention
◦ Faster iterations
◦ Quicker time-to-market
◦ Cheaper delivery
◦ Happier employees
 Scalable delivery process
◦ Add more tool users
◦ Add more tool developers
Challenges:
 Designing bespoke Tool
◦ Hard to gather requirements:“Define the language
you dream in?”
 Training
◦ Users
◦ Developers
 Plumbing
 Deployment
Build a new tool for business users that:
 Has a great user experience.
◦ Graphical application.
◦ Interoperates with Excel.
 Creates precise specifications.
◦ Catch errors as early as possible.
 Mirrors the production environment.
◦ Code reuse.
 Integrates testing.
 Is tuned to their needs.
DSLs have a rich history but GUIs are notably
absent…
DSL Patterns by Martin Fowler
No need to ship a DSL that looks worse than
this:
No need to ship a DSL that looks worse than
this:
1974
Started with a working demo
 Developed in one week!
 Slick looking
 Easy to use
 Bespoke language
 Integrated testing
 Their own worked examples included
 Demo runs on their machines (WPF)
Final solution:
 Development effort
◦ 3 months to design
◦ 3 months to build
 Code size
◦ 10kLOC of F#
 Performance
◦ 20,000 msg/s
◦ Under 35ms door-to-door latency
A different 3 month project:
 114µs latency.
 200,000 tps.
 With fault tolerance!
 Async message passing over Infiniband
 Low-latency allocationless F# code
 Training
◦ On-the-fly
◦ 30 people
◦ 5 teams
 Emergency
◦ Valuable change came in late
◦ Estimated 9 months and £1m
◦ Completed in 24 hours
 Maintenance
◦ All done by client now
◦ After one week of F# training
◦ Ordinary developers
“Pattern matching is quite neat, as is the partial
application of functions”
“rapidly coming to appreciate the benefits
when it comes to refactoring code”
“Our plans are getting bigger each week as we
can see more and more flexibility, it’s great!”
Benefits
 Delivery speed
◦ From idea to production 100x faster
 Delivery costs
◦ Maybe 10,000x lower?!
 F# is good for programmatic GUIs
 Approach described in the F# Journal
 Custom Control union type
 Compiled to WPF Control
 Custom Editable Control
 Reuse for editable strings, unions etc.
 Compose into a UI tree
 Peek Value property to get the “rules”
Nice name!
Input
Variables
Patterns
Output
Variables
Expressions
Take a leaf out of Excel:
 Editable content:
 Display version:
Display version:
Editable content:
A bit like type checking…
type Control =
| Gap
| Label of string
| Title of string
| Dock of (Position * Control) list
| Ctrl of FrameworkElement
| …
let rec make : Control -> FrameworkElement = function
| Gap ->
let ctrl = new FrameworkElement()
ctrl.HorizontalAlignment <- HorizontalAlignment.Stretch
ctrl.VerticalAlignment <- VerticalAlignment.Stretch
ctrl
| Label s -> upcast Controls.Label(Content=s)
| Title s -> upcast Controls.TextBlock(Text=s, FontSize=24.0)
| Dock xs ->
let panel = Controls.DockPanel()
for p, ctrl in xs do
let ctrl = make ctrl
Controls.DockPanel.SetDock(ctrl, p.AsWPF)
panel.Children.Add ctrl |> ignore
upcast panel
| …
let ui =
Dock
[ Top, Title "Bespoke business rules engine"
Bottom,
Tabs
[ Label "Inputs",
Dock[ Top, Label "This version was…"
Bottom, Scroll inputs ]
Label "Rules",
Dock[ Top, Label "The following rules…"
Bottom, Scroll(Ctrl rulesView) ]]]
let StringValue(value: Value) =
let label = Controls.Label()
let textbox = Controls.TextBox()
let setContent = function
| VString text ->
label.Content <- text
textbox.Text <- text
| _ -> failwith "Invalid value"
let ctrl =
Editable<Value>(value, label, textbox, setContent)
textbox.TextChanged.Add(fun _ ->
ctrl.SetValue(Some textbox.Text
|> Option.map VString))
ctrl
let UnionValue(allCases, value: Value) =
let label = Controls.Label()
let combo = Controls.ComboBox()
let itemOf case = case, Controls.ComboBoxItem(Content=case)
let items = Map[for case in allCases -> itemOf case]
let setContent = function
| VCase case ->
label.Content <- case
combo.SelectedItem <- items.[case]
| value -> failwith "Invalid value"
let ctrl = Editable<Value>(value, label, combo, setContent)
combo.ItemsSource <- [ for KeyValue(_, ctrl) in items -> ctrl ]
for KeyValue(case, x) in items do
x.Selected.Add(fun _ -> ctrl.SetValue(Some(VCase case)))
ctrl
The expression language:
type Expr =
| EBool of bool
| ENumber of decimal
| EString of string
| EDate of System.DateTime
| ETuple of Expr list
| EVar of string
| …
The expression interpreter:
let rec eval vars expr =
match expr with
| EBool b -> VBool b
| ENumber x -> VNumber x
| EString s -> VString s
| EDate d -> VDate d
| ETuple fs -> VTuple(List.map (eval vars) fs)
| EVar v ->
match Map.tryFind v vars with
| None -> failwithf "Unknown variable '%s'" v
| Some x -> x
| …
Challenges
 Slow startup times
 Poor GUI performance (grid of numbers)
 Minor perf bugs
 Brittle .NET serialization
Startup times
Problems:
 64-bit NGEN bug
 Poor WPF Grid performance
Solutions:
 Use 32-bit client
 Custom WPF control…
Startup times
 Took two days to fix
 Startup times down from 15s to 0.1s
GUI performance
Problem:
 The WPF Grid control is:
◦ very slow to start up
◦ very slow to scroll
Solution:
 Custom FastGrid control…
 Low-level rendering in F#
◦ Calls DrawGlyphs
GUI performance
 16x faster startup than vanilla WPF.
 Solution in the F# Journal.
 Still a lot of room for improvement…
Minor perf bugs
 sprintf “%A”
 Decimal slow (but ok)
Serialization
Problem:
 .NET serialization not great for F#.
 Bloated format (includes types).
 Brittle when loading (incompatible types).
Solution:
 Custom structural serialization library.
 Handles values of all F# types.
 Solution in the F# Journal.
Serialization
write true = "<bool>True</bool>"
write {anInt=2; aReal=3.4m} = "<record><
field><name>anInt</name><value><int>2</i
nt></value></field><field><name>aReal</n
ame><value><decimal>3.4</decimal></value
></field></record>"
Structurally-typed serialization handles:
 unit
 bool
 byte, int, float, decimal
 System.DateTime
 string
 Tuples, records, unions
 Lists, arrays, sets and maps
Any questions, please contact me:
Jon Harrop <jon@ffconsultancy.com>

Contenu connexe

Similaire à Using F# to change the way we work

Gatling - Bordeaux JUG
Gatling - Bordeaux JUGGatling - Bordeaux JUG
Gatling - Bordeaux JUG
slandelle
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
elliando dias
 
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
Just In Time Scalability  Agile Methods To Support Massive Growth PresentationJust In Time Scalability  Agile Methods To Support Massive Growth Presentation
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
Eric Ries
 
Dev buchan 30 proven tips
Dev buchan 30 proven tipsDev buchan 30 proven tips
Dev buchan 30 proven tips
Bill Buchan
 

Similaire à Using F# to change the way we work (20)

De05_panagenda_Prepare-Applications-for-64-bit-Clients.pdf
De05_panagenda_Prepare-Applications-for-64-bit-Clients.pdfDe05_panagenda_Prepare-Applications-for-64-bit-Clients.pdf
De05_panagenda_Prepare-Applications-for-64-bit-Clients.pdf
 
Object Oriented Programming I
Object Oriented Programming IObject Oriented Programming I
Object Oriented Programming I
 
MWLUG 2014: ATLUG Comes To You
MWLUG 2014: ATLUG Comes To YouMWLUG 2014: ATLUG Comes To You
MWLUG 2014: ATLUG Comes To You
 
Adtech scala-performance-tuning-150323223738-conversion-gate01
Adtech scala-performance-tuning-150323223738-conversion-gate01Adtech scala-performance-tuning-150323223738-conversion-gate01
Adtech scala-performance-tuning-150323223738-conversion-gate01
 
Adtech x Scala x Performance tuning
Adtech x Scala x Performance tuningAdtech x Scala x Performance tuning
Adtech x Scala x Performance tuning
 
The Ring programming language version 1.10 book - Part 18 of 212
The Ring programming language version 1.10 book - Part 18 of 212The Ring programming language version 1.10 book - Part 18 of 212
The Ring programming language version 1.10 book - Part 18 of 212
 
Gatling - Bordeaux JUG
Gatling - Bordeaux JUGGatling - Bordeaux JUG
Gatling - Bordeaux JUG
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Agile
AgileAgile
Agile
 
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
 
Wayfair Storefront Performance Monitoring with InfluxEnterprise by Richard La...
Wayfair Storefront Performance Monitoring with InfluxEnterprise by Richard La...Wayfair Storefront Performance Monitoring with InfluxEnterprise by Richard La...
Wayfair Storefront Performance Monitoring with InfluxEnterprise by Richard La...
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
 
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
Just In Time Scalability  Agile Methods To Support Massive Growth PresentationJust In Time Scalability  Agile Methods To Support Massive Growth Presentation
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
 
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
Just In Time Scalability  Agile Methods To Support Massive Growth PresentationJust In Time Scalability  Agile Methods To Support Massive Growth Presentation
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
 
Introduction to programming - class 2
Introduction to programming - class 2Introduction to programming - class 2
Introduction to programming - class 2
 
Vba Class Level 3
Vba Class Level 3Vba Class Level 3
Vba Class Level 3
 
Евгений Руднев: "Programmers Approach to Error Handling"
Евгений Руднев: "Programmers Approach to Error Handling"Евгений Руднев: "Programmers Approach to Error Handling"
Евгений Руднев: "Programmers Approach to Error Handling"
 
Dev buchan 30 proven tips
Dev buchan 30 proven tipsDev buchan 30 proven tips
Dev buchan 30 proven tips
 

Dernier

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Dernier (20)

Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 

Using F# to change the way we work

  • 1. Jon Harrop, Flying Frog Consultancy
  • 2.  Jon Harrop  Started programming in 1981 BASIC, Pascal, 6502, ARM, C, C++  At British Petroleum in 1995 UFI  Physics and Chemistry at Cambridge Fortran, SML, OCaml, Mathematica, F#  Co-founded Flying Frog in 2005 ◦ Sell books, software and consultancy services ◦ Over 1,100 clients in industry using OCaml & F#
  • 3.  One of the world’s largest insurance companies.
  • 4.  One of the world’s largest insurance companies.  Actually, almost everyone else too…
  • 5. 1. An ordinary delivery process 2. Streamlining the delivery process 3. Technical aspects of the solution
  • 6.  Automate repetition ◦ Traders in a pit ◦ Actuaries with calculators  Use computers!
  • 7.  Much better performance ◦ Latency ◦ Throughput  More sophisticated algorithms
  • 9. 1. Business idea! 2. Model idea: MS Excel.
  • 10. 1. Business idea! 2. Model idea: MS Excel. 3. Build idea: C++/Java/C#.
  • 11. 1. Business idea! 2. Model idea: MS Excel. 3. Build idea: C++/Java/C#. 4. Test idea: NUnit (feedback to 2)
  • 12. 1. Business idea! 2. Model idea: MS Excel. 3. Build idea: C++/Java/C#. 4. Test idea: NUnit (feedback to 2) 5. Deploy production code. Room for improvement?
  • 13. Room for improvement in:  Classic waterfall approach. ◦ Iterations are an absolute killer.  Delivery speed and cost. ◦ This is a long journey. So what does an iteration look like?
  • 14.  First iteration highlights issues. ◦ Civilized discussion.
  • 15.  First iteration highlights issues. ◦ Civilized discussion.  Second iteration, more issues. ◦ Stressful disagreements.
  • 16.  First iteration highlights issues. ◦ Civilized discussion.  Second iteration, more issues. ◦ Stressful disagreements.  Later iterations. ◦ Wild fighting.
  • 17. Big problems:  Accuracy. ◦ Excel/Word are too free-form.  Complexity. ◦ Models are complicated, lots of dispatch.  Latency. ◦ Complected testing.
  • 19.
  • 20.  See the forest for the trees. ◦ Don’t just rewrite code in language du jour!!! ◦ Common mistake when adopting new technologies.  Overhaul the delivery process…
  • 22. Observations  Separate people/jobs ◦ One person uses Tool to turn ideas into products. ◦ Another person maintains Tool.  Separate tests ◦ Tests for the model. ◦ Unit test for the Tool. Advantages
  • 23. Advantages:  Business people ship products themselves!  Less contention ◦ Faster iterations ◦ Quicker time-to-market ◦ Cheaper delivery ◦ Happier employees  Scalable delivery process ◦ Add more tool users ◦ Add more tool developers
  • 24. Challenges:  Designing bespoke Tool ◦ Hard to gather requirements:“Define the language you dream in?”  Training ◦ Users ◦ Developers  Plumbing  Deployment
  • 25. Build a new tool for business users that:  Has a great user experience. ◦ Graphical application. ◦ Interoperates with Excel.  Creates precise specifications. ◦ Catch errors as early as possible.  Mirrors the production environment. ◦ Code reuse.  Integrates testing.  Is tuned to their needs.
  • 26. DSLs have a rich history but GUIs are notably absent… DSL Patterns by Martin Fowler
  • 27. No need to ship a DSL that looks worse than this:
  • 28. No need to ship a DSL that looks worse than this: 1974
  • 29. Started with a working demo  Developed in one week!  Slick looking  Easy to use  Bespoke language  Integrated testing  Their own worked examples included  Demo runs on their machines (WPF)
  • 30. Final solution:  Development effort ◦ 3 months to design ◦ 3 months to build  Code size ◦ 10kLOC of F#  Performance ◦ 20,000 msg/s ◦ Under 35ms door-to-door latency
  • 31. A different 3 month project:  114µs latency.  200,000 tps.  With fault tolerance!  Async message passing over Infiniband  Low-latency allocationless F# code
  • 32.  Training ◦ On-the-fly ◦ 30 people ◦ 5 teams  Emergency ◦ Valuable change came in late ◦ Estimated 9 months and £1m ◦ Completed in 24 hours  Maintenance ◦ All done by client now ◦ After one week of F# training ◦ Ordinary developers
  • 33. “Pattern matching is quite neat, as is the partial application of functions” “rapidly coming to appreciate the benefits when it comes to refactoring code” “Our plans are getting bigger each week as we can see more and more flexibility, it’s great!”
  • 34. Benefits  Delivery speed ◦ From idea to production 100x faster  Delivery costs ◦ Maybe 10,000x lower?!
  • 35.  F# is good for programmatic GUIs  Approach described in the F# Journal  Custom Control union type  Compiled to WPF Control  Custom Editable Control  Reuse for editable strings, unions etc.  Compose into a UI tree  Peek Value property to get the “rules”
  • 36.
  • 42. Take a leaf out of Excel:  Editable content:  Display version:
  • 44. Editable content: A bit like type checking…
  • 45. type Control = | Gap | Label of string | Title of string | Dock of (Position * Control) list | Ctrl of FrameworkElement | …
  • 46. let rec make : Control -> FrameworkElement = function | Gap -> let ctrl = new FrameworkElement() ctrl.HorizontalAlignment <- HorizontalAlignment.Stretch ctrl.VerticalAlignment <- VerticalAlignment.Stretch ctrl | Label s -> upcast Controls.Label(Content=s) | Title s -> upcast Controls.TextBlock(Text=s, FontSize=24.0) | Dock xs -> let panel = Controls.DockPanel() for p, ctrl in xs do let ctrl = make ctrl Controls.DockPanel.SetDock(ctrl, p.AsWPF) panel.Children.Add ctrl |> ignore upcast panel | …
  • 47. let ui = Dock [ Top, Title "Bespoke business rules engine" Bottom, Tabs [ Label "Inputs", Dock[ Top, Label "This version was…" Bottom, Scroll inputs ] Label "Rules", Dock[ Top, Label "The following rules…" Bottom, Scroll(Ctrl rulesView) ]]]
  • 48. let StringValue(value: Value) = let label = Controls.Label() let textbox = Controls.TextBox() let setContent = function | VString text -> label.Content <- text textbox.Text <- text | _ -> failwith "Invalid value" let ctrl = Editable<Value>(value, label, textbox, setContent) textbox.TextChanged.Add(fun _ -> ctrl.SetValue(Some textbox.Text |> Option.map VString)) ctrl
  • 49. let UnionValue(allCases, value: Value) = let label = Controls.Label() let combo = Controls.ComboBox() let itemOf case = case, Controls.ComboBoxItem(Content=case) let items = Map[for case in allCases -> itemOf case] let setContent = function | VCase case -> label.Content <- case combo.SelectedItem <- items.[case] | value -> failwith "Invalid value" let ctrl = Editable<Value>(value, label, combo, setContent) combo.ItemsSource <- [ for KeyValue(_, ctrl) in items -> ctrl ] for KeyValue(case, x) in items do x.Selected.Add(fun _ -> ctrl.SetValue(Some(VCase case))) ctrl
  • 50. The expression language: type Expr = | EBool of bool | ENumber of decimal | EString of string | EDate of System.DateTime | ETuple of Expr list | EVar of string | …
  • 51. The expression interpreter: let rec eval vars expr = match expr with | EBool b -> VBool b | ENumber x -> VNumber x | EString s -> VString s | EDate d -> VDate d | ETuple fs -> VTuple(List.map (eval vars) fs) | EVar v -> match Map.tryFind v vars with | None -> failwithf "Unknown variable '%s'" v | Some x -> x | …
  • 52. Challenges  Slow startup times  Poor GUI performance (grid of numbers)  Minor perf bugs  Brittle .NET serialization
  • 53. Startup times Problems:  64-bit NGEN bug  Poor WPF Grid performance Solutions:  Use 32-bit client  Custom WPF control…
  • 54. Startup times  Took two days to fix  Startup times down from 15s to 0.1s
  • 55. GUI performance Problem:  The WPF Grid control is: ◦ very slow to start up ◦ very slow to scroll Solution:  Custom FastGrid control…  Low-level rendering in F# ◦ Calls DrawGlyphs
  • 56. GUI performance  16x faster startup than vanilla WPF.  Solution in the F# Journal.  Still a lot of room for improvement…
  • 57. Minor perf bugs  sprintf “%A”  Decimal slow (but ok)
  • 58. Serialization Problem:  .NET serialization not great for F#.  Bloated format (includes types).  Brittle when loading (incompatible types). Solution:  Custom structural serialization library.  Handles values of all F# types.  Solution in the F# Journal.
  • 59. Serialization write true = "<bool>True</bool>" write {anInt=2; aReal=3.4m} = "<record>< field><name>anInt</name><value><int>2</i nt></value></field><field><name>aReal</n ame><value><decimal>3.4</decimal></value ></field></record>"
  • 60. Structurally-typed serialization handles:  unit  bool  byte, int, float, decimal  System.DateTime  string  Tuples, records, unions  Lists, arrays, sets and maps
  • 61. Any questions, please contact me: Jon Harrop <jon@ffconsultancy.com>