My experience of F# is that I wouldn't prefer it for anything where there is strong tool support for C# - ie. GUI's, database interfaces, Sharepoint,...

The differences in the power of the languages are more than outweighed by the power of the tools (in favour of C#).

On the other hand, if the project was heavily scientific, or involved lots of text processing, then F# starts to shine.

Over the years the standard response to this question has been to recommend the mixed language project.

By on 2/16/2010 9:33 PM ()

I have been using both C# and IronPython. I like how quickly I can prototype in IronPython but I lose the strong typing and don't find bugs until the code executes and have to spend more time writing tests. F# is my new favorite language for utilities because I get quick implementation and prototyping with strong typing and compiled code. I still at times miss the Visual tools of C# but that's near the end of implementation when I have to create the UI. I still use all 3 languages but usually prefer F#.

By on 2/18/2010 12:04 PM ()

In addition to the other excellent answers offered, you may also want to look at John Hughes' excellent essay "Why Functional Programming Matters." This is not really addressing the subject of F# vs. C# but it's giving a general flavor of what sorts of benefits functional can offer in general.

By on 2/15/2010 6:14 PM ()

Don Syme makes a few comparisons between OO (C#) and functional (F#)

code in his recent web lecture,

[link:channel9.msdn.com]

These comparisons show how you can get more work done with less coding, by using a functional language.

Maybe Don's presentation could be of use to you?

By on 2/15/2010 2:06 PM ()

Here are my thoughts (in no particular order)...

The first thing I think you need to consider is that .NET development is NOT an all-or-nothing model when it comes to choosing a language. I routinely build apps where I mix languages. The whole benefit of the .NET platform (or any CLR, for that matter) is that you can use the right (language) tool for a given problem, and interoperate easily between solutions. So, I'd say question one is inaccurate/irrelevant.

Question two has many (somewhat subjective) answers. But my favorite is based on the Sapir-Whorf hypothesis, otherwise known as the linguistic relativity principle ([link:en.wikipedia.org] Put simply, a language's syntax and semantics encourage (or restrict) different patterns of thought. So, the more language's you understand, the more mental models you can leverage to articulate a given solution. For example, LInQ (in C#/VB.NET) would not have been possible if the folks at Microsoft had no understanding of Monadic theory.

As for question three, here's woefully incomplete partial listing:

- type inference at many levels

- true first-class functions (a delegate is NOT a first-class function!)

- implicit currying

- automatic partial application

- easier (better) mutation control

- the ability to model things with structures other than a class

- useful container literals (tuple, record, list, etc.)

- ultra concise ways of handling traditional OO constructs (discriminated unions, object expressions, etc.)

- sequence comprehensions

- pattern matching

- active patterns

- computation expressions (see also: workflows or monads)

- quotations (in other words: we can meta-program our whole language, not just a targeted sub-set)

I am sure I'm forgetting a few things, but this should enough for most nay-sayers.

Question four can not be answered without a better understanding of the problem domain under scrutiny.

The answer to question five is definitely: YES! Just Google for examples; people are using F# with WebForms, MCV, and Silverlight (whether or not they SHOULD be is a separate discussion). Alternately, (for non-Microsoft solutions) you might look at Intellifactory's WebSharper product (www.intellifactory.com), or the Bistro project ([link:bistroframework.org] Neither are really my "cup of tea" (for different reasons), but both definitely deliver an F#-centric web development experience for ASP.NET.

Lastly, if you are going to be recommending F# to clients, you should probably keep the answers to these (and many other typical questions) close at hand. Of course, without fully understanding the language, you may be trying to use it in situations where another language would be a better choice. So, a solid working knowledge of the language is going to be more useful (in the long-term), than a list of bullet points.

I hope this is helpful.

By on 2/15/2010 10:14 AM ()

With no details about the client/domain, it's hard to offer any advice. In any case, C# versus F# can be a false dichotomy - it doesn't have to be either-or, you can use both languages together as part of your entire solution. (This helps a lot with adoption barriers; rather than writing a whole app in a new language, you might just write one component in F# to get your feet wet and try out the language; this helps mitigate the risks of doing something completely new.)

Anyway, you might want to start by reading

[link:blogs.msdn.com]

and then consider a plethora of somewhat-similar language-comparison questions like

[link:stackoverflow.com]
[link:stackoverflow.com]
[link:stackoverflow.com]
[link:stackoverflow.com]
[link:stackoverflow.com]
...

Don't just jump on board because something is new & interesting; try out F# to get a sense of its strengths and weaknesses, and then you can give reasonably informed advice on the trade-offs between the costs of investing in something new and the benefits it make have for a (portion of a) particular client's application.

By on 2/15/2010 9:45 AM ()

Thanks brianmcn,

Your reply gave a new dimension to my whole thinking process.

And the links were very helpful...

By on 2/16/2010 3:00 AM ()

I believe one of the key advantage of F#(and Haskell/Ocaml etc.) is that it is in many cases closer to the user problem domain(C style looping and OO may not be as natural as we think for people not coming from a programming background). For example, Excel is quite functional in nature and Ocaml is used heavily in the financial field. In other words, for many problem domains, it is easier to communicate with end users about the solution.

Though another advantage of F# is, you don't need to give up the familiar abstraction model even you are firmly in the C# camp. Brian's latest blog about the word warm problem is IMO a good example of mix metaphore programming. It would be quite easy to translate that back into C# if needed. And if you follow that thread(referring back to the original more FP style), it actually shows a typical pattern in the form of "do it in the FP way to get the solution, then refactor may be in a more imperative manner when it fits better in certain part, usually for performance reason".

I see this pattern a lot in Haskell solutions too. It is usually faster to come up with a solution(which becomes the real spec) then enhance. The reverse would be harder(reasoning C# code to get the intend).

By on 2/15/2010 11:27 AM ()

@Brian: Someday I'll figure out how you manage to reply to everything so quickly. Its like you don't sleep, or something.

;-)

By on 2/15/2010 10:16 AM ()

@Brian: Someday I'll figure out how you manage to reply to everything so quickly. Its like you don't sleep, or something. ;-)

He's got TOOLS!

By on 2/16/2010 2:49 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper