# MATLAB? But but Python/R/C++/COBOL

**URL:** <https://uqworld.org/t/matlab-but-but-python-r-c-cobol/147>\
**Category:** Developers Corner\
**Tags:** stefanos-blog\
**Created:** [May 8, 2019, 10:06am UTC](https://uqworld.org/t/matlab-but-but-python-r-c-cobol/147 "2019-05-08T10:06:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ste](https://uqworld.org/user_avatar/uqworld.org/ste/32/122_2.png) [@ste](https://uqworld.org/u/ste)\
**Post date:** [May 8, 2019, 10:06am UTC](https://uqworld.org/t/matlab-but-but-python-r-c-cobol/147/1 "2019-05-08T10:06:33Z")

</div>

Hi everyone, Stefano from the UQLab Dev Lair here.

Here’s another post to answer a personal “all times FAQ” about one of the core design choices behind UQLab: its programming language. As you know, our choice back in 2013, when we started the architectural design of UQLab, was to use [MATLAB](https://www.mathworks.com). In this post I’d like to share with you the thought process that led to our choice of going with MATLAB.

MATLAB is seen by some scientific communities as a questionable choice on two main grounds:

- It is a slow language that can only be used for quick prototyping, but it’s not good for complex computational tasks
- It is non-free, hence it should not be used for academic/research purposes

Here I will try to give you my 5 cents on those two topics, as well as adding some more food for thought on other aspects of the problem.

_ **MATLAB is slow** _

> This is an argument most often heard from experienced modellers used to develop their codes in C, C++ or FORTRAN. And, when working on strictly non-vectorizable code (e.g. FDTD solvers, N-body simulations etc.), it is to some degree true. A `for` loop in MATLAB can\[1\] be significantly slower than a similar one in a compiled language that supports advanced loop control optimizations (e.g. C).  
> However, when dealing with linear algebra, which in uncertainty quantification (UQ) constitutes the overwhelming majority of the actual computational costs, such a margin is extremely reduced. This is due to the innate vectorized nature of matrix operations, _the very building blocks of MATLAB ([MATrix LABoratory](https://mathworks.com/company/newsletters/articles/the-origins-of-matlab.html))_. Indeed most matrix operations make use of a compiled version of the [LAPACK](http://www.netlib.org/lapack/) libraries\[2\], which are FORTRAN based. On properly designed code, the performance difference between MATLAB and other “faster” languages is in the one-digit percentage range.

_ **MATLAB is neither free nor open source** _

> Yup, MATLAB is not free nor open-source. Academic licenses (for research and students), however, are quite affordable (i.e. ~50$/year for the basic version). This brings an interesting discussion that edges on the philosophical: why is it “widely accepted” in Academia that hardware must be expensive, but software must be free? At the end of the day, a modelling workstation is a very expensive machine. Graphics cards that run modern machine-learning tools are also expensive. Personally, I don’t see the problem in using a non-free software, if it provides a powerful tool for the development and deployment of computer algorithms, more so [if it was designed by an academic for academic purposes](https://mathworks.com/company/newsletters/articles/the-origins-of-matlab.html).

But is this all? Are those the two reasons why we choose MATLAB? To be fair, these were not our reasons to choose a specific programming language, but were rather considered as potential drawbacks.  
The main reasons for our choice follow purely from the analysis of our intended audience: practitioners in applied sciences and engineering, the keywords being **applied** and **engineering**. Our goal is to make UQ available to a wide audience of people who are not necessarily experts in programming, nor in UQ. In this sense, a common ground that can be found between most of our users is a scientific/technical education. No matter the field, equations (_formulas_ if you are an engineer 😉 ) are the universal shared language of scientists.

As a consequence, Bruno and I focused on languages that offer a [_functional programming_](https://en.wikipedia.org/wiki/Functional_programming) paradigm, as opposed to [_object oriented programming_](https://en.wikipedia.org/wiki/Object-oriented_programming), as it is by far the most natural approach to scientific computing. The overhead necessary to handle the abstractions in object-oriented programming forces users to waste precious time in “getting their code to run”, rather than “getting their algorithms to function”.

In 2013, the number of _functional programming languages_ that wouldn’t be horribly slow when dealing with linear algebra and that were _well known in most applied science education programs as well as outside academia_ were very few, and MATLAB was by far the most successful and well-known option.  
Even more, UQ is most often performed at the _prototyping_ stage, rather than during _production_. **These** were the main reasons for our choice. However, for the skeptics, here’s a rundown of a number of other reasons that need to be considered when designing a software for a specific audience and/or task:

- the availability of a powerful [integrated development environment (IDE)](https://en.wikipedia.org/wiki/Integrated_development_environment), with powerful debugging tools. Today a few options exist in the main languages (e.g. [spyder](https://www.spyder-ide.org/) for Python, or [Julia’s own IDE Juno](https://junolab.org/)), but the choice back then was quite poor
- the extremely fast learning curve of MATLAB
- the possibility of hiding parts of the code (for licensing purposes)
- native object-oriented code support: even though the UQLab libraries are written in a functional programming paradigm to be accessible to applied scientsits/engineers, it’s core is actually fully object-oriented (OOP). This is because it doesn’t deal with science, but just with IT-related businesses, for which [encapsulation](https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)) is instead extremely important.

And I’m pretty sure in the months we spent identifying what to use to write UQLab other good arguments were made, but these are the ones that come to my mind first.

But then, would you still use MATLAB if you were to start from scratch in 2019? Unfortunately, I ran out of font-ink with this [lengthy post](https://i.kym-cdn.com/entries/icons/original/000/011/269/potato.jpg), therefore [I won’t be able to provide an answer here](https://en.wikipedia.org/wiki/Fermat%27s_Last_Theorem)…

'til the next one  
Stefano

* * *

1. [More recent versions of MATLAB](https://mathworks.com/products/matlab/matlab-execution-engine.html) have dramatically increased the performance of `for` loops through improvements of the built-in [just-in-time compiler](https://en.wikipedia.org/wiki/Just-in-time_compilation) 

2. See also: [LAPACK in MATLAB - MATLAB & Simulink](https://mathworks.com/help/matlab/math/lapack-in-matlab.html)

---

<div class="post-metadata">

**Author:** ![gramian](https://uqworld.org/letter_avatar_proxy/v4/letter/g/90db22/32.png) [@gramian](https://uqworld.org/u/gramian)\
**Post date:** [January 15, 2020, 10:31am UTC](https://uqworld.org/t/matlab-but-but-python-r-c-cobol/147/2 "2020-01-15T10:31:25Z")

</div>

Well, and then there is [GNU Octave](https://www.gnu.org/software/octave/), an open-source alternative to MATLAB.

---

<div class="post-metadata">

**Author:** ![timueh](https://uqworld.org/user_avatar/uqworld.org/timueh/32/386_2.png) [@timueh](https://uqworld.org/u/timueh)\
**Post date:** [January 17, 2020, 3:15pm UTC](https://uqworld.org/t/matlab-but-but-python-r-c-cobol/147/3 "2020-01-17T15:15:41Z")

</div>

I like Matlab. It’s the language I was taught at university (whether that’s good or bad is not up to discussion). When I started doing my PhD, however, I wanted to learn a _real_ programming language, and I chose [Julia](https://julialang.org/), because it seems to be a _very_ promising language to bet on.

Why Julia? As pointed out in the post, there is always the question of object-oriented vs. functional. And Julia happens to be in the middle. Using the ideas of [multiple-dispatch](https://en.wikipedia.org/wiki/Multiple_dispatch), in my opinion, it provides the right tradeoff.

But then again… it seems that the choice of one’s go-to programming language seems to be similar to one’s choice of (non-)religion…

---

<div class="post-metadata">

**Author:** ![ste](https://uqworld.org/user_avatar/uqworld.org/ste/32/122_2.png) [@ste](https://uqworld.org/u/ste)\
**Post date:** [January 17, 2020, 3:58pm UTC](https://uqworld.org/t/matlab-but-but-python-r-c-cobol/147/4 "2020-01-17T15:58:40Z")

</div>

hi @timueh, good choice with Julia. It’s one of my top 3 favorite languages, and it’s primarily functional, while admitting also OO and fancier stuff. Not last, programming today is not the same as in the '90s, hence the machine-learning- and HPC- friendliness of Julia will sure come in handy in the future.

That’s the language I’d probably choose if I were to design UQLab next year 😉

As far as languages as religions go, I sincerely hope it’s not the dominant mindset (albeit admitting it’s the case for some communities…). Each of the available languages serves a purpose and has a specific philosophy, user-base, features, etc. Once the goal is clear, the language choice (assuming know-how is available) becomes rather “constrained”. I feel focusing on a language due to prior belief is a dangerous choice, especially in a project that is expected to run long-term and to have a number of different developers over time that will have to maintain and support it. But then again, this is just my perspective, as an OS- and programming language- agnostic type of guy.

@gramian Thanks for your comment. Yes, GNU Octave also existed and was considered early on during the design process of UQLab. But Octave 3 was painfully slow in 2012 (although I think it already officially supported BLAS and LAPACK), with poor portability across OSes, a relatively small user base and a rather limited object-oriented stack that didn’t allow us to implement what we planned. Hence the choice of Matlab instead.

[edit: typos]

---

<div class="post-metadata">

**Author:** ![timueh](https://uqworld.org/user_avatar/uqworld.org/timueh/32/386_2.png) [@timueh](https://uqworld.org/u/timueh)\
**Post date:** [January 19, 2020, 2:28pm UTC](https://uqworld.org/t/matlab-but-but-python-r-c-cobol/147/5 "2020-01-19T14:28:26Z")

</div>

So, let’s assemble a task force, and let’s go @ste: `UQLab4Julia`!?.. 😉

Just one tiny clarification: Julia is _not_ OO. It’s also not purely functional. The idea of multiple dispatch is to combine the best of the two world. I recommend [this talk by Stefan Karpinski](https://www.youtube.com/watch?v=kc9HwsxE1OY).

---

<div class="post-metadata">

**Author:** ![damarginal](https://uqworld.org/user_avatar/uqworld.org/damarginal/32/73_2.png) [@damarginal](https://uqworld.org/u/damarginal)\
**Post date:** [January 20, 2020, 9:00am UTC](https://uqworld.org/t/matlab-but-but-python-r-c-cobol/147/6 "2020-01-20T09:00:22Z")

</div>

> [@ste](#):
>
> Once the goal is clear, the language choice (assuming know-how is available) becomes rather “constrained”

Sometimes I forget that this is a rather important point 🙂 before getting involved in whatever raging [holy wars](http://catb.org/jargon/html/H/holy-wars.html) out there.

This reminds me of a blog post I read recently on [MATLAB, Julia, and Python](https://tobydriscoll.net/blog/matlab-vs.-julia-vs.-python/). The author is a veteran MATLAB user/programmer (has even written some textbooks on it) who is aware of the changing landscape. I think his post is not vitriolic and pretty nuanced, coming from a perspective of numerical computation. I like his comparison between these three languages to cars 🙂. I didn’t come from a strict numerical computation background and have a bias toward Python as it has served me well hacking my ways before; from text processing to gluing all the apps and codes I was dealing with. Most probably from the perspective of numerical computation, despite the recent wave, there are indeed better alternatives; old and new.
