Like a lot of Atoms, I’m a bit of a programming language nerd. (For the record, I’m also a bit of a human language nerd.) So it was very natural that, after working in .NET using C# for a several months, I wanted to give F# a try.
For those unfamiliar with F#, it is a “functional first” language in the .NET family that is most similar to OCaml or Haskell. It is compiled and statically typed, but the type inference is really powerful and removes almost all of the boilerplate you see in languages like C# or Java.
I recently spent several days familiarizing myself with the basics of F#. For convenience, here are the ones I found most helpful.
After I learned the basics from Try F#, I found this wikibook to be immensely helpful in providing more formal definition of the various data structures and patterns of the language. Concepts were explained in simple but precise language, and the examples were easy to follow. I was also pleasantly surprised to find helpful exercises suggested at the bottom of some entries. At one point I had two tabs open — one to the recursion page on the wikibook and one to Try F# — attempting to complete the exercise on the wikibook. (Note to those who would follow suit: recursion in F# is not always tail call optimized, and bad things will happen if the browser-based REPL gets a stack overflow.)
fsharp.org is the official site for the F# Software Foundation, an organization that promotes open source F# development. Their website has several helpful pages, for example there are instructions on how to run F# on platforms besides Windows (Mac, Linux, iOS, Android, etc.). It also links to the F# GitHub page, which contains repositories for the open source F# compiler, FAKE (an F# build system like Make or Rake), and some testing related libraries.
Of course, no overview of a programming language made by an Atom is complete without talking a bit about testing. In fact one of the first things I tried out in F# was testing, specifically to see if it was practical to write tests in F# against code written in C#. This may sound a little odd, but I think there are a number of potential benefits:
- Using multiple languages can help keep your brain nimble and creative while developing.
- Project constraints might force you to develop the code base in C#, but the testing code might not be similarly constrained. So in a situation where you’d rather write everything in F#, but the realities of the project exclude it, you might at least be able to write the tests that way.
- F#’s excellent type inference can remove some of the boilerplate and pain from testing C# code. Ironically, this is more relevant when testing C# code than F# code, because it comes in to play with frequently with mocking — something you will probably do a lot less of in F#.
I found this post to be a good starting point for testing in F#: F# as a Unit Testing Language. Additionally I layered FsUnit on top of NUnit to make the tests look much prettier and more natural. (Using NUnit by itself makes your tests look like there are still in C#.)
I hope these resources prove as helpful to you as they were to me. F# seems like an interesting language, and given the relative prominence of .NET and the increasing popularity of functional languages, I think it has a lot of potential for the future.