views:

2567

answers:

5

In the microsoft and .net world, is there an industry trend towards F# and functional programming, moving away from C# and VB.NET?

What is it about F# that is so special? What does it provide that C# does not provide? Does it mean you can code solutions faster and build in more features in the same time frame? Can you code more reliably, with fewer bugs, in F# versus C#? What makes F# better than the current languages available in the .net world?

+15  A: 

My basic understanding is that it supports the C# (i.e. imperative) paradigm while being primarily functional. Functional programming is very useful for complex math and business rules (see the first answer in the FAQ below) because it strongly discourages side effects, which make it easier to analyze the code and to prove a program's soundness. As @pmlarocque indicated, this also makes it excellent for concurrent programming.

From the F# FAQ:

What application areas are envisaged for F#?

There are several key application areas for a language like F# on the .NET platform. In particular, such languages excel at mathematically-oriented programming, and, given the right libraries and visualization tools, a range of scientific and engineering tasks as well. These languages are also well known to be extremely powerful when used to implement sophisticated symbolic analyses such as hardware verification, software verification, optimization, machine learning and compilation.

Why is F# distinctive as a .NET programming language?

The minimal technical requirements for a powerful scientific and data-intensive .NET programming language are as follows:

  • High performance
  • Succinctness
  • Simplicity
  • Interactive scripting and visualization
  • A rich developer experience (intellisense, codesense, debug, tools)
  • Support for .NET component development
  • Easy, efficient access to .NET libraries
  • Alignment with key for emerging technical trends such as multi-core computing, web services and data-oriented meta-programming.

Here are some of the things that make F# highly distinctive in this arena:

  • Its inherent technical strengths as a multi-paradigm programming language, and in particular the added productivity benefits of functional programming.
  • The use of type inference and automatic generalization to achieve both succinctness and performance.
  • The F# toolset for interactive visualization and development
  • Its support for LINQ and LINQ-style meta-programming.
  • The support of Microsoft Research for a credible, stable reputation and as a focal point for the F# community and as a key source of high-impact users at Microsoft.
  • The inherent importance of functional programming in the emerging multi-core world.
bdukes
@bdukes: +1, or the simple answer 'sometimes F# is the right tool for the job'.
sixlettervariables
+3  A: 

I don't think the world is going away from C#, we are going toward a world where you use the right tools for the right jobs, not just resolve every problem with the tool you know even if it's not well-suited for the task.

F# simplify a lot concurrency, with immutable datatype. Once you set a variable it keep the same value for it's lifetime. So there no risk of having 2 threads modifying the variables (well the memory address) at the same time. Functionnal language are well geared for scientific problems where object-oriented oftently don't make sense, but where we just want high performance(parrallel) computation of functions.

If you are interested on the subject I am currently reading this book : Real World Functional Programming and I think it's really good.

pmlarocque
I generally program business oriented applications for the web, using asp.net and class libraries. I'm not sure F# is really the "tool of choice" for this. For me I'm not yet convinced F# is better for what I need than C#. Granted I need to learn more about F# before I can really decide. Thanks!
Jon
F# requires a paradigm shift just as OOP requires procedural programmers to learn a new worldview. A good way to get into it is via C# 3.0 and LINQ.
Mark Cidade
I went through that paradigm shift some 6 years ago, moving from the old world of classic asp/VB6 to c#, asp.net and the .net framework. Time to soon shift again, or at least add another tool to the tool belt.
Jon
+6  A: 

F# is the first primarily functional language sanctioned by Microsoft. It targets the .NET framework and is integrated with Visual Studio.

Although the your skill level is the overriding factor in these kinds of things, with F# you can code solutions faster and build in more features in the same time frame, more reliably, and with fewer bugs than C#.

If you know F# well then the language will get out of your way moreso than C#.

The key thing is skill level combined with time frame. You can quickly write a lot of features with minimally buggy code in C#, but you will need a custom ad-hoc library beforehand to do the things that F# gives you out of the box. Same thing for preventing bugs: F# makes it easier to write side-effect free code, including use of immutable data types.

See Paul Graham's essay, Beating The Averages.

Mark Cidade
Ok, so assuming equally skilled C# and F# programmers, given the same spec for an application to code. The F# programmer will be able to produce more features with fewer bugs in a shorter amount of time?
Jon
Yes, using only the standard language-specific facilities and standard .NET libraries. This is my opinion, just as I think a C# will outperform a Java programmer if they're otherwise equally skilled.
Mark Cidade
Except where you need tools that have not yet been implemented for F#, I agree.
Jon Harrop
+3  A: 

Please have a look at this. Might help you get some idea about the significance of F#.

Vijesh VP
Thanks Vijesh, our questions are similar in nature.
Jon
+1  A: 

Compared to C#, F# has type inference while retaining static typing. This allows for more concise code without loss of clarity since Visual Studio will tell you the inferred types. I think this combination of type inference and static typing creates more maintainable code, as you can easily change your mind about your interfaces and let Visual Studio tell you where your assumptions break. I elaborate on other points in a reflection on why I like F#.

namin