What to do if you “just don’t get” F#

by kiteason22. December 2013 08:11

You’ve heard a lot about F#, maybe watched a video, seen a presentation. Maybe even given it a spin.

And you just don’t get it.

But you’re a persistent kind of person and you don’t want to dismiss it out of hand. After all, the rapidly-growing F# community can’t all be wrong. (Can we?)

Here are a few actions you can take which might ‘unblock’ your appreciation of the language. If you give these things a try and you still think ‘meh’, well – good luck to you. Nothing is for everybody!

Unlearn OO

Many developers have grown up in an object-oriented environment. Sometimes they make the mistake of trying immediately to map simple F# syntax into an OO view of the world. (Where are my classes? Where are my encapsulation and data hiding? How do I do inheritance? Tell me now!) Don’t get me wrong: F# has a pretty complete OO story to tell, with interfaces, inheritance and all that good stuff. The trouble is that if you try and learn F# in an OO context from the get-go, you may be trying to do too much at once. Staying close to an OO (C#) view of the world will mean you’ll have the nagging feeling that ‘I could do this quicker in C# - with a single Resharper command’.

It’s better to make a clean break with OO initially. You can work back to a more class-based view of the world later (if you need to).

Action: Forget everything you know about OO to start with. Learn some basic syntax (let, |>, map). Only worry about OO features once you have that basic stuff down.

Forget the functional jargon

The F# world, and functional languages in general, are littered with terms like ‘monads’ and ‘algebraic data types’ – and of course ‘functional’ itself. These can be offputting. So forget them: you don’t need to understand them. How can I be sure? I’m a professional F# developer and I am proud to say I have only the dimmest understanding of both monads and algebraic data types – and many other terms. When you need to start understanding such things, they will come easily. But you can bash out a lot of great code before you get to that stage.

Action: Forget any terminology you might come across that isn’t directly linked to the task at hand.

Expect a Higher Code Density

F# developers tend to do a lot more per line of code than – for example – C# developers. Time after time I have sat in (or given) demos where people coming from other language traditions have clearly been thinking ‘Well that’s nice, but when is (s)he going to show me the real code’. Subconsciously at least, the audience skims over what they think is header information, when in fact they are looking at actual code. I sometimes think that people imagine we are actually ‘cheating’ in some way but nope – we are just doing a hell of a lot per line of code. Less filler, more thriller!

Action: Get used to really looking at every line of code. It’s probably doing more than you think.

Tools Support – Get Over It

Sometimes people get really scared when they learn that they aren’t going to be able to use Resharper in F# code. Relax! You are just moving one tick along the lengthy scale between ‘hipster who edits everything in Notepad’ and ‘corporate type who needs a 4GL to do anything’. Developers can succeed at many points along the scale. Sure we’d like certain basic refactorings (like ‘Rename’ – which is coming, slowly). But this is actually much less of an issue in practice than you might think. This is largely because F# codebases tend to be smaller and simpler, so need less ‘wrangling’. Maybe, just maybe, you’ll actually feel liberated without Resharper questioning your every keystroke.

Incidentally, this comment really only applies to those tools which examine and manipulate the syntax of your code (such as Resharper’s ‘convert to linq expression’). Other types of tool, notably NUnit and the magnificent NCrunch, tend to work just fine with F#.

And if there is a cherished tool which you just can’t let go of, consider requesting the authors to add F# support.  (Or pitch in yourself!)

Action: Be prepared to let go of a few cherished tools.

I hope some of these mental tricks help you get over that initial hump. If they do – welcome aboard!

Tags: ,

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

About the author

F# bore

Month List

Page List