Fabulous: Functional App Development | Xamarin Blog

Fabulous: Functional App Development | Xamarin Blog

Object-oriented programming (OOP) is widely used today. However, in this post, we will elaborate on how FP can also be an awesome tool for building apps.

his is a guest blog by Timothé Larivière. Timothé is the maintainer of [Fabulous_](https://github.com/fsprojects/Fabulous?WT.mc_id=fabulous-blog-jamont) and a Microsoft MVP. You can find him on Twitter [@Tim_Lariviere_](https://twitter.com/Tim_Lariviere).

Fabulous App Development

Fabulous is an open-source framework for building mobile & desktop apps using functional programming (FP) with F#, a .NET functional-first programming language. It is available on GitHub at https://github.com/fsprojects/Fabulous.

Applications built with Fabulous use the MVU design pattern (Model-View-Update, also known from the origin The Elm Architecture). These app also use declarative views written directly in F#.

This may already feel familiar to you if you have played with frameworks like React-Redux, Flutter, or SwiftUI.

Object-oriented programming (OOP) is widely used today. However, in this post, we will elaborate on how FP can also be an awesome tool for building apps.

A few apps made with Fabulous for Xamarin.Forms, from left to right: [FabulousWeather_](https://github.com/fsprojects/Fabulous/tree/master/Fabulous.XamarinForms/samples/FabulousWeather?WT.mc_id=fabulous-blog-jamont)[FabulousContacts_](https://github.com/TimLariviere/FabulousContacts?WT.mc_id=fabulous-blog-jamont)_ and [FabulousPlanets_](https://github.com/TimLariviere/FabulousPlanets?WT.mc_id=fabulous-blog-jamont)

Image FabulousWeatherImage FabulousContacts

Fundamentals of MVU

Note: We will see MVU as defined by Elm, which is the definition used by many F## libraries.

The upcoming MAUI will integrate a different variant of it.

Before diving in, let’s expand on what the MVU pattern is and how it differs from more traditional MVVM apps.

Image of MVU

Credits: Beginning Elm (https://elmprogramming.com)

The idea is to have a state (also called Model) that is immutable and can only be changed through messages (Msg) that are processed by the update function. Those messages are then sent when users interact with the application or when external factors happen. Such as async request completes, push notifications, and switching between dark and light modes. Each time the state is updated, Fabulous will ask for the matching UI state and will transition between them transparently.

MVU provides several advantages over MVVM:

  • Immutable state

In MVVM, the ViewModel (which holds the state) is mutable and is usually changed in multiple methods in reaction to what happens. When the app grows bigger, make extra effort and be careful when adding new changes to not break existing behaviors unknowingly. In MVU, the immutability of the app state ensures that it won’t ever be changed outside of the dedicated update function, without a dedicated message. This makes it very simple to add new features without worrying about breaking something.

  • Centralization & explicitness
  • The structure of MVU is really simple and enforces explicitness.
  • The state can only be initialized in the init function and changed in the update function only for declared Msgs, the UI can only be declared in the view function.
  • This makes it really easy to welcome new developers to the codebase and makes debugging a lot easier.
  • If it breaks, there’s only one place.
  • No concurrency issues
  • The user navigates, data gets loaded, animations end, … Reacting to one event is easy, but when you need to handle multiple events at the same time, it becomes tricky.
  • This can lead to obscur errors, very hard to understand and sometimes impossible to reproduce.
  • Fabulous helps you avoid this kind of problem by applying concurrent messages one after the other.
  • Also, Fabulous lets you monitor its MVU loop so you can know what happened in which order.
  • Easy to replay that one corner case!
  • Ease of testing
  • A best practice in FP is to write functions that only depend on their parameters and not on the global context, much like static methods.
  • Those functions are called pure and are really easy to test, for the same parameters you’ll always get the exact same output.
  • With MVU, the initupdate and view functions are pure by default. Meaning you can unit test them super easily, including your UI!
  • You can see an example here.

developers xamarin.forms app development f# fabulous mobile applications mobile apps mvu

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How long does it take to develop/build an app?

This article covers A-Z about the mobile and web app development process and answers your question on how long does it take to develop/build an app.

ECommerce Mobile App Development | Ecommerce Mobile App Development Services

We are leading ecommerce mobile application development company. Hire our ecommerce mobile app developer for your custom Ecommerce project at competitive rates. **Know about [Top ECommerce Mobile App Development...

Top 10 Mobile App Development Companies in India

The mobile application scenario has been continually changing over the years. In recent years India has become a center for mobile app development companies. The increase of smartphones has instantly increased the requirements for these apps. Every year new technological trends occur due to contin

List Of The Top Pittsburgh Mobile App Development Companies

Detailed client reviews of the leading Pittsburgh mobile application development companies. Hire the best iPhone/iOS or Android developer in The Steel City.

Mobile Applications Development Vancouver

Mobile Applications Development Vancouver Evidently, the great presence of technology has turned the spectrum of businesses and various industries an extremely competitive space, wherein organizations hailing from many industry verticals are embracin...