tags:

views:

347

answers:

6

Hello, I'm a Java/C++ developer that never spent time in learning C# and the relative .NET foundation.

Then I learned OCaml because I had to use it for my master thesis so I heard about F# and wondered: will F# allows me to use easily the .NET API to build fully featured applications (that may involve GUIs, sockets, whatever) without any problem?

I ask this because it seems that F# syntax and concepts are quite similar to OCaml and when they are different it's just because a more OOP approach is used so Java knowledge would help me in filling that holes.. if F# is able to use same resources as C# without the need to learn C# syntax I would really consider that.. does it worth trying?

Apart from that, are the books available on Amazon for F# (mainly one book from O'Reilly and 3-4 books from Apress) good to learn advanced techniques? Because now I'm quite fond of functional programming but never worked on .NET platform so I really don't know where to start from.

Thanks in advance

+10  A: 

If you know a few languages already like you say, Expert F# 2.0 by Don Syme is an excellent in depth view of F#.

Mostly you'll struggle with learning the libraries, but the MSDN reference is pretty good.

I think it's most definitely worth trying. Knowing C# won't give you any great advantages in learning F#, apart from the experience with the framework.

Mau
+1 - Expert F# was easily the most interesting book I read last year.
Alex Humphrey
+4  A: 

In my experience, you need some C# to learn F#, especially for the .Net part.

Similar to your situation, I didn't know any .Net and C# before learning F#. The first hard part for me is asynchronous IO programming. I get a full understanding of it until I read the async chapter of CLR via C#. And I soon found that what bited me was not computation expression/monads, it is .NET. Then I continue to read CLR via C#, e.g. I know that in .Net 1d array is efficient, however 2d array is not that efficient. I also get to know delegates and events in .Net.

.Net is imperative. C# is the mother tone for .Net. IMHO, learning C# (at least reading C#) is required for an F# programmer.

Yin Zhu
+5  A: 

will F# allows me to use easily the .NET API to build fully featured applications (that may involve GUIs, sockets, whatever) without any problem?

I expect to see a few different perspectives here; I'll offer mine.

There are a few aspects to a 'language' that affect how easily/smoothly you can build 'fully-featured' applications with it:

  • the language itself
  • the library/framework it is paired with
  • the tooling capabilities (IDE integration)
  • outside support (samples, 3rd-party libraries, community)

F# is a terrific language, whose core is based on OCaml. It shares the same library/framework (.NET) as C#, and so with regards to the first two bullets, F# is as capable as C# for building such apps.

F# is a number of years younger than C# though, so both the Visual Studio tooling and the community/samples are not as mature as that of C#. Right now, there are fewer 'project templates' and 'designers' that work with F# in the VS box, and it is harder to find samples/libraries. The F# community is great, and is rapidly starting to fill in the holes of the 4th bullet (and even some of the third), but for building apps that would rely heavily on the 3rd and 4th bullets above, C# still has an advantage today (July 2010). Yes, you can build anything you like today with F#, but there are still cases, wher the end-to-end experience with C# will be smoother/easier.

Brian
+2  A: 

One thing still missing from F# in Visual Studio are the tools which help automate the user interface design process. These are quite sophisticated in the case of C#, but in F# you'll have to do all the plumbing by hand. So if your goal is to learn to produce WPF (etc.) applications, C# is currently a better bet. If your goal is to learn the mechanical details of .NET, WPF (etc.), either language will do.

An even better approach, in my opinion, is to learn the two -- F# and C# -- in tandem. Your experience with Java and OCaml gives you a good head start on both C# and F#. Use the C# to take care of the UI, and the F# to do the underlying work.

TechNeilogy
You mean that it's possible to easily mix up C# and F# and let C# care about GUI (for example) while F# is used for the program logic? They can interface one with the other seamlessly?
Jack
@Jack "seamlessly" might be a little too strong a word. You will need to keep your F# in a separate assembly (like a Java package) from your C# and GUI.You will also probably face a few minor challenges where the two interface with each other.
Mike Schenk
There is some F# functionality which is specifically designed to work with that language, and is difficult to use from C#, but F# is a full-fledged .NET language. As such, it is fairly simple to write classes and functions which look no different than referenced functions from any other .NET language, whether C#, MC++, or VB. The portable parts of the functionality are fairly simple to learn and keep straight. An F# book or online F# examples will provide example of intermixing F# and C#. Maybe not perfectly seamless, but at least painlessly seamless, lol.
TechNeilogy
+1 Agreed1. Microsoft actually recommends C# (rather than F#) for web and desktop front ends, because of the designer support.2. Whenever you search the web for solutions to particular .Net problems, you are likely to get a C# solution. It usually easier to just cut and paste this, than translate to F#
Javaman59
A: 

The simple answer is: "yes", F# has full access to all .NET libraries and can both consume and produce code written in or for any other .NET language, as well as direct interfacing with COM and native DLL's.

That said, the tooling support for F# is not as mature as that for C#. While you might find it a bit easier to learn .NET using C#, you won't be inherently limited by starting with F#.

Most significantly, the GUI builder cannot presently produce F# code, one cannot produce strongly-typed ASP.NET codebehind pages (but can create weakly typed ones), and there is no direct support for creating tests in F# (but plugins exist which do).

However, one can easily write GUI code by hand in F#, and it is often easier to do so and quite a bit more terse than equivalent C#. For example, properties can be set on the constructor; e.g., let f = new Form(Text="Window Title") and lambda functions are converted to delegates automatically; e.g., event.Add( fun e -> doSomething() ).

It is also possible to, for example, create a DSL for describing the UI. For a bit more information, see http://stackoverflow.com/questions/1054763/f-is-there-no-ui-like-wpf-for-it

A recommended style, as pointed out by TechNeilogy, is to write the logic in F# as a library, and call that from a GUI created in C#.

James Hugard
Oh, and F#'s support for writing asynchronous and parallel code is simply wonderful. It is *far* easier to write correct non-blocking IO in F# than in any other language I've worked with.
James Hugard
One exception to the "interface with anything" is that there is currently no language-level support for dynamic objects created in, say, IronPython or IronRuby. While it may be possible to interface with such objects, this won't be as easy as, say, using VB or C#.
James Hugard
+1  A: 

I will say "No". The challenging of learning F# is to change your mindset of programming, recursion, high order function, pattern matching, etc. Very importantly, you need to think to program in a "functional" way, not imperative as C# or Java. Learning API is always easy, but learning how to design application is not.

That is my 2 cents.

Liang Wu
Just to point it out, the OP already knows OCaml, which is a sister language to F#, so writing code in largely compatible F# should not pose any challenge.
James Hugard