Jack
Jack

Reputation: 133577

Learning .NET from F# without C#

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# allow me to easily use 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 hole.. if F# is able to use the same resources as C# without the need to learn C# syntax I would really consider that.. is 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

Upvotes: 18

Views: 1741

Answers (6)

Liang Wu
Liang Wu

Reputation: 1822

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.

Upvotes: 1

James Hugard
James Hugard

Reputation: 3236

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

Upvotes: 1

TechNeilogy
TechNeilogy

Reputation: 1281

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.

Upvotes: 3

Brian
Brian

Reputation: 118865

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.

Upvotes: 7

Yin Zhu
Yin Zhu

Reputation: 17119

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.

Upvotes: 5

Mau
Mau

Reputation: 14468

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.

Upvotes: 14

Related Questions