210 likes | 324 Views
F
E N D
1. F#: The Business CaseAaron Erickson, MVP, C#Technical Solution SpecialistMagenic
2. F# - What is it? Designed and Built by Microsoft Research
Functional/OO Hybrid Language
Strongly Typed
Inspiration for LINQ?
3. The “F” stands for “Functional” Functional Programming – aka “FP”
Immutability – In pure FP, you don’t manage state.
Why is this good?
4. The “F” stands for “Functional” Functional Programming – aka “FP”
Immutability – In pure FP, you don’t manage state.
Why is this good?
Parallelism!
5. Why Parallelism? What Ghz was your CPU 3 years ago?
What is it today?
The trend is more cores, which means…
Scalability in the future depends on ability to split processing across multiple cores… especially for the most interesting apps!
6. State Makes Parallelism Hard Sync & Lock
About 1 in 100 developers are able to write good multi-threaded code (source: Rocky Lhotka)
Another Threading Bug? @#$&&@! (source: Aaron Erickson and almost everyone else who has struggled with multi-threaded code)
Debugging Multi-Threaded Apps is a Simple and Easy Experience… NOT!
7. Automatic Parallelism: MapReduce “A programming model and an associated implementation for processing and generating large data sets.”
Source: http://labs.google.com/papers/mapreduce.html
Basically, the thing that makes Google actually work. In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”
8. F# - What is it? Hybrid OO and Functional Language
Similar Syntax to OCaml
Strongly Typed (none of that dynamic typing hocus pocus those hippies are smoking - ?)
All values are immutable by default – special effort must be taken to create a mutable value
Functions are first class – you pass around functions just like you do values (similar to C# Lambdas) In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”
9. F# - Where is it going? Will be mainstreamed in Visual Studio vNext
(source: http://blogs.msdn.com/somasegar/archive/2007/10/17/f-a-functional-programming-language.aspx)
But the big question… is why? Well, that is the basis for today’s talk.
10. F# - Business Case For: “We need to increase our transactions per second this system can process”
“This calculation takes 6 hours to complete”
“We would like to try to compute that, but our current hardware just can’t support it”
… basically, the interesting, high-value work. In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”
11. Lets not kid ourselves… Apps that, for the most part, spend most of their time pushing and pulling things from databases are only, to be kind, moderately interesting at best.
In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”
12. Business Value In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”
13. Business Value In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”
14. Business Value In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”
15. Business Value In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”
16. Business Value Most CIOs get it. Hitching F# to this train == HappinessMost CIOs get it. Hitching F# to this train == Happiness
17. C# Lambdas to F# Functions C# Lambdas are the “gateway drug” to F#
Func<int, int, bool> something = (x,y) => x + y;
let something = (x,y) -> x + y
You can do it in C#, but the language is just a little more terse and limiting
F# version does something that C# version simply can’t – automatic generalization.
In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”
18. F# - Always Generalizing Code in F# will automatically generalize as far as possible, unless you specifically say otherwise.
(* generic adder that adds any two addable things *)
let adder = (x,y) -> x + y
In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”
19. F# will allow state But it sticks out….
let mutable res = 1
for n = 2 to n do res <- res * n
(* the <- operator is used to change a mutable value. It is not an accident that the operator sticks out like a sort thumb... *)
In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”
20. F#/C# Integration Sample Scandal Generation Engine…
In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”
21. Learning F# Give yourself time
Similar mindset as when you went from Procedural to OO
Just like C# still lets your write procedural code, F# still lets you write object code
Corollary: Just because its F# doesn’t mean its functional
Challenge yourself – Write a routine that compute a sum of an array using no mutable variables
In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”In the mapreduce algorithm, they scale index processing over thousands of commodity machines. This is entirely made possible by techniques from FP that operate in a “land without state”
22. Resources and Links F#: http://research.microsoft.com/fsharp/
Everything F# (aggregated feed) http://feeds.feedburner.com/planet_fsharp
My blog – covers this and other F# and .NET topics: http://blog.magenic.com/blogs/aarone/
Copy of this presentation: Email aarone@magenic.com