Alois Kraus on F#

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.

 

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

 

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

 

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

 

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.

 

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.

 

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#.

 

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

 

Version F#

do print_endline "hello world" 

 

Version C#

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

}

 

 

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.

 

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.

 

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

Bookmark
dotnetkicks+, digg+, reddit+, del.icio.us+, dzone+, facebook+

Print | posted @ Monday, May 29, 2006 11:59 PM

Comments on this entry:

Gravatar # re: Alois Kraus on F#
by DeeJay at 5/30/2006 1:13 AM

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.
Gravatar # re: Alois Kraus on F#
by Alois Kraus at 5/31/2006 1:52 PM

Hi Robert I have posted my answer here:

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

Yours,
Alois Kraus

Your comment:

(Note: all comments are moderated so it may take sometime to appear)

Title:
Name:
Email:
Website:
 
Italic Underline Blockquote Hyperlink
 
 
Please add 3 and 4 and type the answer here:
 

Links

 Subscribe in a reader
Twitter Follow me on Twitter
FaceBook View my Facebook
LinkedIn View my LinkedIn Profile Viadeo Viadeo Profile (Français)

Badges



Disclaimer

The views expressed on this weblog are mine and do not necessarily reflect the views of my employer.

All postings are provided "AS IS" with no warranties, and confer no rights.