I’ve been reading documentation on F# lately. It sounds really cool, but it just rubs me the wrong way when people start comparing it with C#. I understand the differences that F# is a functional-orientated language and C# is object-orientated. Each have their own advantages and disadvantages in various situations.
But what really gets my goat is when people compare lines of code between the two because they inflate the C# line count. One, they introduce unnecessary methods, properties, etc. Two, braces on their own line are included in the line count. Three, they suddenly forget about anonymous delegates and lamda statements. Let’s look at this F# example (I got this one from http://2009.scandevconf.se/db/FSharp-Intro-v1.ppt):
let data = (1, 2, 3)
let f(a, b, c) =
let sum = a + b + c
let g(x) = sum + x * x
g(a), g(b), g(c)
Now, let’s write it in C#:
var data = new[] { 1, 2, 3 };
static void F(int a, int b, int c) {
var sum = a + b + c;
var g = delegate(int x) { sum + x * x; };
g(a); g(b); g(c);
}
F# does have the ability to be more concise than C# (I do have to admit that), but don’t try to skew the numbers!