F# eXchange — 2019 summary

F# eXchange is a 2-day conference in London. I spent there a great time and I can recommend it. Subscriptions for 2020 are already opened!

Where you can use F#?

F# is used in the .NET world and in JavaScript using Fable transcompiler.
F# has its own application development stack called SAFE (Saturn-Azure-Fable-Elmish). It allows the F# developer to write programs for full-stack development. You can use F# across cross-platform in the cloud and make beautiful UI.
F# can improve the work of research engineers. The strong type system helps them with proper modelling and computations.

About writing code

Alfonso (@alfonsogcnunez) had a great talk about communication. He starts from the statement “I am a writer” not an engineer. He referred it to the communication process between the writer and reader of the code.
This communication can happen through 3 main points: semantics, readability and structure.
We tend to go to the extremes which reveal in the tension between economy and expressiveness. We want to express our intention in less code and as much correct as possible. At the same time, making our intention as clear as possible, we tend to produce too much verbose code. Good balance is a key success.
To make the code more readable — we can try to express meaning through some convention or relationship. In his mind formatting is not so much important as some of us think it is. He gave jumbled letters as an example of the human mind to deal with some not well-formatted code. It’s essential to think about code according to the relationships. For example, missing information or redundant information. Both cases are wrong and we should bear them in mind during writing the code.
It’s also important to have a structured code. It makes our communication much clearer. In object-oriented design, the structure can happen through classification (hierarchy of inheritance). In functional programming, it can be harder to achieve. But still possible with proper use of modules and patterns. For example MVU for UI design.
Read more how to organizing modules in F#.

Elmish architecture

Elmish architecture is MVU pattern which stands from Model-View-Update. It solves problems of other MV approaches like MVC, MVVM, MVP. The main advantage of this approach is that it has the ultimate golden source of truth where is the state. The state is in the model and nowhere else!
Other letters stand for 2 functions:

  • view function — to generate virtual UI
  • update function — to make changes to the current model.

Because these functions are pure (they depend only on what was passed in and don’t have side effect) we can notice these benefits:

  • it’s easy to test your view because you test your view function
  • you can forget about UI cross-threads. The update function will change the state of the model and cause a change in UI to depend on it.
  • it’s easy to reproduce a problem if you get your model. Model is enough to reproduce everything.

Elmish owes its name from language ELM language. MVU pattern can be applied anywhere. In the web using Fable. In desktop and mobile apps using the Fabulous framework. The fabulous framework is built on top of Xamarin.

Why use F# in research

Evelina Gabasova (@evelgab) had presented how F# can be useful in research. She defined the skills of a research software engineer as interleaving domains: computer science, math & statistics, business knowledge.
The most important thing for researches is reproducibility. If you can’t reproduce your result your studies your work is pointless.
She presented the projects on which she worked and showed how F# helped her:

  1. “The (mis)informed citizen” — web page to provide human annotations with marking source references in articles. The project has the aim to recognise fake news.
    Because F# can be used to write web it helped her in a short period of time write a robust web page for providing annotations.
  2. “Air traffic simulation” — visualisation of an aircraft simulation (the part written in F#). The main idea to navigate control to avoid loss of separation. Because in aeroplane domain there are a lot of measures like longitude and latitude, meters, and so on. The F# feature “unit of measure” helped her a lot. Unit of measure is an annotation on number type. It corresponds exactly to measures used in the real world. You can’t add different units of measure, because it will give you a compile-time error, for example:
    1<m>+2<ft> //it will not compile
    But you can multiply and divide numbers with measures. As a result, you will get a new measure, for example:
    1<m>/1<s> = 1<m/s>

Why use F# in the cloud?

It’s important to mark that whole Azure is adapted to use F#. There were mentioned two F# features which help in daily work with Azure:
1) Type-provider for Azure storage SDK
All challenges in C# world were opposed to provided type-provider.

You can’t easily explore data. -> You can explore data with type provider. It will give you all relevant suggestions by simply putting a dot near a type. Using it in F# REPL you can invoke queries to check more interesting facts.

Mismatched types. -> It also detects data in a table column to provide you with a proper type. For example optionality of some column.

”String” typed data. -> You can notice failure after 3 steps from the issue origin -> everything is checked in compile time.

”Unusual” API design — not supported exceptions in runtime. -> All relevant suggestions are provided.

Read more about Azure Storage Type Provider
2) Computation-expressions “Orchestrator”
It’s a tool which organizes invocation of stateless independent functions into high-level workflows. It invokes under the hood Azure activities and gathers results and triggers other functions.
Read more here

Summary

I hope that I aroused your curiosity and proved the utility of F#. All videos from the conference are available online on skillsmatters website.
It’s true that it’s not a mainstream language, but currently, none of the functional languages is mainstream. It’s worth learning because it can provide a lot of unique features and can be mixed with C#. It can help in your daily work more often than you would expect.

Presentations used in the article

You need to sign in to skillsmatters website (you can do it for free 🙂 )

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s