6th Feb
Category: Programming , Industry news

F# vs C# - what is this programming key change all about?

At Webigence we currently use C# coding for all the programming we do now. C# is the main ASP.NET programming languages and generally regarded one of the best programming languages available. However, we are just getting into using F# to build an app for a client using Xamarin and we are enjoying exploring what it can do. Although it has been around for a while, it is not yet mainstream, so we thought we’d explore the benefits of F# versus C# code and see where the future is going and share some of that with you.  


Firstly, what is F#? Developed by the F# Software Foundation, Microsoft and open contributors it is an open source, cross-platform, strongly typed, functional-first, multi-paradigm programming language. It is seemingly the next jump up from the C# programming language (widely used in ASP.NET web solutions).


What are the benefits of F#  (F sharp) over C# (C sharp) code?

F# is more compact or succinct in how it is written allowing developers to be faster and more productive, whereas C# can be convoluted with semicolons or curly brackets etc. This also makes the F# code simpler for new developers to pick up and therefore you reduce your ramp-up time as well as lower maintenance costs.

What F# does is enforce good convention in terms of lots of little functions. F# uses strict type checking along with having an interactive window where you can test the code immediately meaning the developer can test each bit of code as they go along resulting in less bugs overall. This fact alone is great and surely enough for everyone to switch to using F# immediately as we all know that Web Testing and QA is not as straight forward as you think!

Scott Wlaschin in his article on ‘Why am I so enthusiastic about F#?’ mentions that F# is a leader in the area of information-rich programming.

“F# type providers allow you to talk directly to data combining the power of dynamic code generation, the safety of static types, and the ease of use of intellisense.”

F# has been around for a while so the risk associated with learning and incorporating ‘new technology’ does not apply here.

“F# is a safe choice — cross platform, fully supported, and with a great community.”

Scott Wlaschin also mentions in his article ‘Four Key Concepts' that there are a few major differences between F# and C# coding, namely that F# is;

Function-oriented rather than object-oriented

Expressions rather than statements

Algebraic types for creating domain models

Pattern matching for flow of control


Others on Stack Overflow (a question and answer site for professional and enthusiast programmers) also seem to rave about the benefits of F# saying

“You can formulate many problems much easier, closer to their definition and more concise in a functional programming language like F# and your code is less error-prone (immutability, more powerful type system, intuitive recurive algorithms). You can code what you mean instead of what the computer wants you to say.”

F#, being open source is supported by industry-leading companies (such as Microsoft) and an active community allowing it to be used on a wide range of applications.

The F# Software Foundation is a dedicated website where you can find out more about the F# coding language.

“From the business perspective, the primary role of F# is to reduce the time-to-deployment for analytical software components in the modern enterprise.”

From a client perspective it means that there would be less issues/bugs with their sites and in theory (and in time) cheaper/quicker developments when an application is first built and ongoing we should be able to pass on these savings to clients.

One of our senior developers has just started using F# and he notes one thing that stands out so far is that it is possible to achieve a lot of mathematical operations in a lot less code. He says

“I can’t see that it could completely replace C# code when it comes to ASP.NET development, although I may be wrong – C# being an OOP language, it integrates perfectly with front end technologies such as JavaScript / JQuery and the bridge between them (i.e. the transport mechanism that make front end and back end code interoperable) such as JSON. It may be that F# can be used in a OOP manner, in which case there is a much wider scope for it to integrate into the existing frameworks for ASP.NET / MVC development.” 


An example of how we at Webigence are beginning to use F# on a client project is that we have created a separate F# project as part of the solution. The proposal is that this F# project will produce a library with a limited number of functions in it that will be used to calculate whether or not some pre-defined rules are satisfied when it comes to users logging their data (such as making sure that the limits for the user data are not exceeded). So the nature of this logic is very mathematical, which should be achievable in a more concise manner in F# than in C#. All the F# code is going to do is get passed a set of times / dates, perform some calculations and return an answer. We won’t use it to do things like access a database, make web service calls to a restful API etc, these will will handle in the C# based projects.

The big question is will F# become mainstream and take over from C# entirely? What are your thoughts?

Blog written by Natalie Wiggins