Download - 5 Best Practices For F# Development
![Page 1: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/1.jpg)
5 BEST PRACTICES FOR F# DEVELOPMENT
![Page 3: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/3.jpg)
1. Define the Best Practice
2. Explain Why It’s Good
3. Provide Concrete Examples
HOW THIS WILL WORK
![Page 4: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/4.jpg)
Prefer small functions with only one primary responsibility.
PROGRAMMING IN THE SMALL
![Page 5: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/5.jpg)
1. Helps enable function composition
2. Follows the Single Responsibility Principle (SRP)
WHY IS IT GOOD?
![Page 6: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/6.jpg)
1. FSharpCouch
2. IoC Container
EXAMPLES
![Page 7: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/7.jpg)
Prefer function composition over argument passing.
FUNCTION COMPOSITION
![Page 8: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/8.jpg)
1. Allows for function chaining
2. Makes the code terse yet readable
WHY IS IT GOOD?
![Page 9: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/9.jpg)
1. Asynchronous Workflows
2. WebSharper 2010
EXAMPLES
![Page 10: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/10.jpg)
Make sure your recursive functions are tail recursive.
TAIL RECURSIVE FUNCTIONS
![Page 11: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/11.jpg)
1. Without it, there’s a risk for a stack overflow
2. Tail Call Optimization (TCO)
WHY IS IT GOOD?
![Page 12: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/12.jpg)
1. Tail Recursive vs. Non-Tail Recursive
2. Polyphony (Join the Node Cluster)
EXAMPLES
![Page 13: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/13.jpg)
VERIFYING TAIL RECURSION
NOT TAIL RECURSIVE
![Page 14: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/14.jpg)
VERIFYING TAIL RECURSION
TAIL RECURSIVE
![Page 15: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/15.jpg)
Prefer active patterns over multiple ‘when guards’ during pattern matching.
ACTIVE PATTERNS
![Page 16: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/16.jpg)
1. Makes code more readable
2. Supports Don’t Repeat Yourself (DRY)
WHY IS IT GOOD?
![Page 17: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/17.jpg)
1. Single-CaseExample: let (|UpperCase|) (x:string) =…
2. Multi-CaseExample: let (|Odd|Even|) x =…
3. PartialExample: let (|DivisibleByTwo|_|) input
=…
4. ParameterizedExample: let (|MultipleOf|_|) x input = …
- http://blogs.msdn.com/b/chrsmith/
TYPE OF ACTIVE PATTERNS
![Page 18: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/18.jpg)
1. Example of Active Patterns (XML parse)
2. Node Join in Polyphony (DHT)
EXAMPLES
![Page 19: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/19.jpg)
Prefer pattern matching to if/else syntax.
PATTERN MATCHING
![Page 20: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/20.jpg)
1. Makes your code easier to extend
WHY IS IT GOOD?
2. Helps get you out of the procedural mindset
![Page 21: 5 Best Practices For F# Development](https://reader036.vdocuments.net/reader036/viewer/2022062419/5585b916d8b42a5e5a8b4b39/html5/thumbnails/21.jpg)
1. MVC Template (Account Controller)
EXAMPLES