Why it’s better to use the functional paradigm for creating aviation models

Jorge Martin

2017-11-22 10:05:44
Reading Time: 2 minutes

Are you working with legacy code to describe the system behaviour using software development paradigms such as imperative programming or object oriented programming? Have you experienced any issues when translating your mathematical models into code? Functional programming can alleviate those issues.

The functional programming paradigm consist of declaring the system’s behaviour using only functions and expressions to reproduce the system dynamics. The simulation of your system is then driven by data you provide as arguments to the expressions.

Functional code is easier to extend as complex systems are often described as mathematical models, and to represent those models in functional code is fairly straightforward. Also, the modularity of the code is usually greatly improved as it is easier to create a function with a single responsibility than a method. Having a mix of functional code for defining the model, and some imperative code for other auxiliary tasks, should be acceptable if only the various paradigms are isolated into separate functions or modules in order to iteratively replace imperative code into functional code. It may require more than one person to maintain a code with different programming paradigms embedded as mastering both paradigms at the same time is a challenge.

Do you feel your code takes too much time to execute or your data size is becoming too large? Consider migrating your code into a functional program and use any available software platform to execute your code in a cluster. These tools that will help you to partition data as well as dispatch tasks to different computers in parallel in order to solve expressions of the model. Even highly dependent complex models can be run in parallel in some steps of their simulation. If this is not your case, then your model might run in a cheaper computer as only the data used in the function has to be allocated in the machine instead of having a large workbench of allocated data.

Testing is the most important for modelling system behaviour, as the system consists of several interacting components, so any coding error would have a great impact in the results of the model. Functional code is easier to test as single behaviours are isolated in functions, thus the range of cases that must be validated is always smaller that validating other algorithms developed in imperative languages. Also, imperative methods usually have ‘side effects’ that are difficult to disable when testing, pure functions do not have this issue as it encourages use of immutable structures (state-less data) that generate a new element as a result of a function.

Once the model is sufficiently tested then is time to deploy the software in a production infrastructure. Functional code is usually more robust than other general purpose languages as it usually works better with weak typing and any coding errors can be isolated into a small subset of functions.

Are you considering using functional programming in an upcoming project? Subscribe to our blog and you’ll receive some examples of functional programming in the upcoming months.

Author: Jorge Martin

© datascience.aero