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.
5 Best practices for F# Development<br />
DANielmohl<br />Sommet Group<br />dmohl@yahoo.com<br />www.twitter.com/dmohl<br />blog.danielmohl.com<br />
HOW THIs will work<br />1.   Define the Best Practice<br />2.   Explain Why It’s Good<br />3.   Provide Concrete Examples<...
PROGRAMMING IN THE SMALL<br />Prefer small functions with only  one primary responsibility.<br />
Why is it good?<br />1.  Helps enable function composition<br />2.  Follows the Single Responsibility Principle (SRP)<br />
Examples<br />1.   FSharpCouch<br />2.   IoC Container<br />
Function composition<br />Prefer function composition over argument passing.<br />
Why is it good?<br />1.   Allows for function chaining<br />2.   Makes the code terse yet readable<br />
Examples<br />1.   Asynchronous Workflows<br />2.   WebSharper 2010<br />
Tail Recursive functions<br />Make sure your recursive functions are tail recursive.<br />
Why is it good?<br />1.  Without it, there’s a risk for a stack overflow<br />2.  Tail Call Optimization (TCO)<br />
Examples<br />1.  Tail Recursive vs. Non-Tail Recursive<br />2.  Polyphony (Join the Node Cluster)<br />
Verifying tail recursion<br />Not tail recursive<br />
Verifying tail recursion<br />tail recursive<br />
Active patterns<br />Prefer active patterns over multiple ‘when guards’ during pattern matching.<br />
Why is it good?<br />1.  Makes code more readable<br />2.  Supports Don’t Repeat Yourself (DRY)<br />
Type of active patterns<br />Single-Case<br />Example: let (|UpperCase|) (x:string) =…<br />Multi-Case<br />Example: let (...
Examples<br />1.  Example of Active Patterns (XML parse)<br />2.  Node Join in Polyphony (DHT)<br />
Pattern Matching<br />Prefer pattern matching to if/else syntax.<br />
Why is it good?<br />1.  Makes your code easier to extend<br />2.  Helps get you out of the procedural mindset<br />
Examples<br />1.  MVC Template (Account Controller)<br />
Daniel mohl<br />Sommet Group<br />dmohl@yahoo.com<br />www.twitter.com/dmohl<br />blog.danielmohl.com<br />
Upcoming SlideShare
Loading in …5
×

5 Best Practices For F# Development

3,363 views

Published on

F# makes it very easy to develop high performance, readable, and efficient code. However, like all things, a lack of discipline and best practice adoption can lead to a mess. In this talk we will cover 5 best practices that you can start using today to make yourself a better F# developer. We will explore each best practice, discuss the reason(s) that the described approach is preferred, and explore a few examples.

Published in: Technology, Business
  • Be the first to comment

5 Best Practices For F# Development

  1. 1. 5 Best practices for F# Development<br />
  2. 2. DANielmohl<br />Sommet Group<br />dmohl@yahoo.com<br />www.twitter.com/dmohl<br />blog.danielmohl.com<br />
  3. 3. HOW THIs will work<br />1. Define the Best Practice<br />2. Explain Why It’s Good<br />3. Provide Concrete Examples<br />
  4. 4. PROGRAMMING IN THE SMALL<br />Prefer small functions with only one primary responsibility.<br />
  5. 5. Why is it good?<br />1. Helps enable function composition<br />2. Follows the Single Responsibility Principle (SRP)<br />
  6. 6. Examples<br />1. FSharpCouch<br />2. IoC Container<br />
  7. 7. Function composition<br />Prefer function composition over argument passing.<br />
  8. 8. Why is it good?<br />1. Allows for function chaining<br />2. Makes the code terse yet readable<br />
  9. 9. Examples<br />1. Asynchronous Workflows<br />2. WebSharper 2010<br />
  10. 10. Tail Recursive functions<br />Make sure your recursive functions are tail recursive.<br />
  11. 11. Why is it good?<br />1. Without it, there’s a risk for a stack overflow<br />2. Tail Call Optimization (TCO)<br />
  12. 12. Examples<br />1. Tail Recursive vs. Non-Tail Recursive<br />2. Polyphony (Join the Node Cluster)<br />
  13. 13. Verifying tail recursion<br />Not tail recursive<br />
  14. 14. Verifying tail recursion<br />tail recursive<br />
  15. 15. Active patterns<br />Prefer active patterns over multiple ‘when guards’ during pattern matching.<br />
  16. 16. Why is it good?<br />1. Makes code more readable<br />2. Supports Don’t Repeat Yourself (DRY)<br />
  17. 17. Type of active patterns<br />Single-Case<br />Example: let (|UpperCase|) (x:string) =…<br />Multi-Case<br />Example: let (|Odd|Even|) x =…<br />Partial<br />Example: let (|DivisibleByTwo|_|) input =…<br />Parameterized<br />Example: let (|MultipleOf|_|) x input = …<br />- http://blogs.msdn.com/b/chrsmith/<br />
  18. 18. Examples<br />1. Example of Active Patterns (XML parse)<br />2. Node Join in Polyphony (DHT)<br />
  19. 19. Pattern Matching<br />Prefer pattern matching to if/else syntax.<br />
  20. 20. Why is it good?<br />1. Makes your code easier to extend<br />2. Helps get you out of the procedural mindset<br />
  21. 21. Examples<br />1. MVC Template (Account Controller)<br />
  22. 22. Daniel mohl<br />Sommet Group<br />dmohl@yahoo.com<br />www.twitter.com/dmohl<br />blog.danielmohl.com<br />

×