Alois Kraus just made this nice post about functional programming in F# and C#. I enjoyed the article very much and he even bigs up one of my own posts, which of course tickled me.<?xml:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” />/o:p

 /o:p

However, I disagree with quite a lot of what he said in his conclusion paragraph. He writes:/o:p

 /o:p

Not all concepts of functional languages should be explored by Mort and Elvis since most of them are fairly complex to understand because functional languages are very picky (just like unix) who can be their friend and who not. If Einstein does write a F# program then only a true Einstein can maintain it. When the outsourced Mort and Elvis do change his code I am sure they will screw it up/o:p

 /o:p

Mort, Elvis and Einstein are different type of programmers characterized in this blog post by Nikhil Kothari./o:p

 /o:p

I maybe being picky here as Alois doesn’t say this directly, but he seems to imply that functional programming is more complicated than imperative/object oriented programming. /o:p

 /o:p

I think here he is mixing up two subtly different things, the complexity of a language and the complexity of problem a program is try to address. If the problem is sufficiently hard then it is going to be difficult to understand what ever language it is written in. I agree that the two issues are related as the design of language can make a problem harder or easier to understand when expressed in code./o:p

 /o:p

So I feel his framing of function programming as more complex is a little unfair. In fact F# aims to be a good bit simpler that C# and in my opinion it succeeds because to write a program in F# one needs to understand few concepts that in C#. /o:p

 /o:p

To see this, let’s take a look at a simplest example we can, the hello world program./o:p

 /o:p

Version F#/o:p

do print_endline “hello world” /o:p

 /o:p

Version C#/o:p

class Prog
{
 static int main()
 {
  System.Console.WriteLine(“hello world”);
  return 0;
 }

}

 
/o:p

 /o:p

In the F# version we need to understand just three pieces of text “do” a keyword for calling functions, “print_endline” a function from the built in libraries, and “hello world” a string literal./o:p

 /o:p

The C# is more complicated. First of all we forced to define a class “Prog”, even though it does not server any purpose in this case. Next we define a method “main”; “main” is a static method meaning that doesn’t belong to any instance of the class we have defined. This static method is a special method, because it is called main and is static; it is the entry point to the program. Next comes our method body definition made up of a call to a method “WriteLine” in the class “Console” in the namespace “System”. Finally we state that we’ll return the literal “0” to the calling function. Well not quite finally as we need to remember to close all those curly brackets we opened along the way./o:p

 /o:p

I really hope Alois continues his exploration of F# and functional programming in general. /o:p

Feedback:

Feedback was imported from my only blog engine, it’s no longer possible to post feedback here.

re: Alois Kraus on F# - DeeJay

Very valid argument, and interestingly one typically used in advocation of languages such as python or ruby. In essence requiring too many concepts for achieving simple things.

Talking about the purely-functional core of a functional language… everything is based around the evaluation of expressions (no ‘execution’ of statements). No difference between values and functions (everything is first-class) so you achieve very desirable and intellectually satisfying closure properties. Giving declarative, concise and clean code through composition of functions… no threading/plumbing of values between statements. A very clean and desirable model of computation.

Ease of understanding is always so relative, but the only ones who can make an attempt at an objective comparision are those who are proficient in both… and that’s a general philosophy.

I think it’s an often enough observed result that imperative programmers who study the functional approach improve their skills. Even if they never continue on with functional programming, their imperative programming is improved.

And that’s one of the reasons I echo your sentiments; it’s in Alois’s interests to explore functional programming.

re: Alois Kraus on F# - Alois Kraus

Hi Robert I have posted my answer here:

http://geekswithblogs.net/akraus1/archive/2006/05/30/80141.aspx

Yours,
Alois Kraus