views:

772

answers:

4

Possible Duplicate:
What are the benefits of using C# vs F# or F# vs c#?

My team is currently using C# .NET to develop enterprise applications for our company. We have a history of Winforms dev, but are now moving over toward SilverLight.

My boss recently saw a video on F# and thought it looked pretty exciting, and he has asked me to check it out. My question is this - what advantages would a functional language (like F#) give over an OO language (like C#) in the realm of enterprise application development?

I really want to see if there are any compelling reasons to even begin contemplating a shift. Some F# and C# comparison code might be nice to see as well.

+5  A: 

Check out this question.

Chance
Yes, looks like that answers it pretty well. It didn't come up in my search, for some reason.
CraigS
+3  A: 

I just ordered the Manning 'Real World Functional Programming' which does a fantastic job of explaining all of the nooks and crannies of F#, functional programming, and especially how it compares to C#, and OOP

What I'm coming down to is that functional programming in general increases the 'rigor' of your programs, assuming you conform to the principles of side-effect free functions, and immutability.

Additionally, there seem to be benefits to thinking about code in a declaritive sense, rather than an imperative sense. In OOP I tend to think of the steps it takes to accomplish something, but in FP it seems like you're more concerned with how you want to apply functions to data to obtain results.

John Weldon
+4  A: 

You can express a lot of concepts much more concisely in a functional language like F#.

Functions are first class objects, and can be applied directly to collections to perform transformations/filtering much more efficiently.

Immutably is encouraged in functional languages, and this makes (for instance) multi-threaded code much more reliable (you know data structures aren't changing under you).

By being able to write multi-threaded code more reliably and more easily it's much easier to take advantage of multiple processors/cores (increasingly important now Moore's law doesn;t apply so much).

Note that you can use your existing C# objects within F#. As such, you may want to write certain parts of your code in F# and other parts in C#. You should be able to mix and match according to your requirements and the suitability of each approach.

Brian Agnew
+1 Multithreading is trivial without side effects. After all, if you aren't writing state, there's no need to lock anything.
Joel
+1  A: 

firstly you ask "functional language (like F#) give over an OO language (like C#) i" f# is both functional and OO. any thing you would write in c# can be directly translated to f#. F# is a multi paradigm language but the advantage comes from the functional part in my opinion. f# and other functional langauge are a clear winner when it comes to writing multi threaded applications due to the higher possibilities for the compiler to reason about what can safely be run in parallel.

When it comes to web development f# has a very cool tool kit that allows you to write all code (as in server side and client side) in the same language aka f#. the client side will be translated into JavaScript by the web toolkit.

Rune FS
While both modes of usage are supported, F# is a functional language with imperative features, and C# is an imperative language with functional features. It would be exceedingly tedious to put 'mutable' in each declaration. Also, imperative programming inhibits the ability of F# to do pattern matching and type inference.
Joel
@Joel well according to Don Syme one of the main architects of F# my statement about F# being multiparadigm is true. Im simply paraphrasing his book expert F# and your imcorrect on the mutable you don't need that for doing OO in F# only if you wish things to be mutable and lastly you're also wrong on the pattern matching. OO in F# _can_ be combined with pattern matching. One of the mail goals of F# was to combine the Worlds of OO and FP and btw type inference works even with non F# classes.
Rune FS