What I like most about F#.

 

I was on the fence on F# until I watched Scott Wlaschin talk on Railway Oriented Programming, a functional approach to error handling.   In that talk,  he showed how to implement error handling in both F# and C#.

Here is the use case:

image

Here is the C# Code without the Error Handling:

image

And here is the F# Code without Error Handling:

image

Not much of a difference in terms of readability, right?

Then he showed this.

C# Code with Error Handling

image

F# Code with Error Handling

image

With error handling in place, the C# code became a bit harder to read. In contrast, the F# code remained the same!  What? How? Even before the talk was over, I was sold on F#.  If you want to see how it is done,  I highly recommend that you watch the video too.

There are so many things in the F# language that I like.  Its concise,  immutable by default,  the ability to chain and compose  functions,  type providers, FSI, and more. But what I like most about it, is that it helps me write code that is easy to read and understand.

One of the tips that I heard from a lightning talk at CodeMash is, “Try to write code that even non-programmers can read”. If you take a second look at the F# Code above.  Do you think even non-programmers can understand it?

In my opinion, I definitely think they can.

A C# developer by day and F# developer by night with JavaScript sprinkled in between. I am a Catholic, proudly Filipino and married to my beautiful classmate from college with 3 kids. I am currently a Senior Software Developer at Epitec.

Leave a Reply

Your email address will not be published. Required fields are marked *