Out of the coding comfort zone

Between R, Python, Matlab and Julia and many others, which language should you use for scientific computing? Most grad students i met have learnt only one. Electrical engineer show up with Matlab. Psychologists are keen on R and sometimes Python. Neuroscientists are a little bit more variable. Only computer scientists had in my experience a solid and basic understanding.

The Blub-Paradox

Besides the scientific culture surrounding a language, there are good reasons to pick up a new language. A new language often puts its focus on a different concept, which broadens your horizon and might eventually turn you into a well-rounded programmer. As Paul Graham wrote about Blub programmers: the only programmers in a position to see all the differences in power between the various languages are those who understand the most powerful one. [...] You can't trust the opinions of the others, because of the Blub paradox: they're satisfied with whatever language they happen to use, because it dictates the way they think about programs. There are dozens of blogposts out there, which want to convince you of one language or warn you of another. Matlab is closed-source, tied to its IDE, and for that, got some hate by Olivia Guest. Java did receive a rant by Joel Spolsky. R has a weird syntax which made Tal Yarkoni suffer. Heck, just google more of that yourself.

But i do not want to list reasons for switching. For me the point is, dear reader, you are probably smart enough to know that you can profit from learning a new language. What i want to do is telling you my personal story of how i picked up new programming languages. And i hope that, in doing so, you will lose any fear that switching is not possible, because you are currently in the clutch of your personal Blub paradox. But be warned. My first language was BASIC. And as Dijkstra infamously noted: It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration Therefore, take all the following with a grain of salt.

I learned BASIC on a Mister X, which was a childrens toy, and offered only a single line as screen and no memory. I must have been maybe 10 years old at that time. And obviously, like everyone my age, i grew up in a time were you had to use a terminal to interact with your PC, or C64 or Amiga. In highschool, i took then some computer science classes, and they taught Pascal. In my pasttime, i mostly played computer games, and my interest in adventure games gave rise to me playing a little bit with Adventure Game Studio, which used a C++ dialect. Although i majored in phyics and chemistry, i decided to study education. This started a long hiatus in programming. In fact, education studies were so theory-driven and qualitative, that they did not even teach us SPSS.

Comfort Zone

So, when i started my first Phd, i was out of the programming game. I did my analysis in SPSS and WinMiRa, pressing buttons instead of writing code. My 220-page thesis was written in Word. Formatting was hell. But my training was to read books and write text, not to run experiments and write code. Only when i started to work in neuroscience, did i pick up programming again. And in 2010, this meant Matlab. Picking up Matlab felt easy. Once the license is verified, it runs out of the box. No need to install additional dependencies, compile modules, choose an IDE. Additionally, who does not prefer writing code to clicking through GUIs when you arae doing analysis on large datasets? Additionally, the semi-open toolboxes like Fieldtrip are pretty good. And you had a lot of statistical functions, too. So, coding in Matlab is just covenient and very comfortable. For many years, i did not meet anybody who would do their EEG/MEG analysis not with Matlab. Matlab was good enough. So what made me move out of my Matlab-Blub-Bubble?

First, Matlab was closed source, and it always felt weird to code in an closed-source environment. Second, i started using Twitter. This got me exposed to people, who wrote their code in R or Python. Third, and probably the first decisive experience. I was re-running an old analysis script - maybe 2 months old - but used an updated version of a toolbox. The results were different. This made me wonder whether my reliance on toolboxes might not be a good idea. Additionally, i was supervising several studies, and having to juggle many analysis projects made me want to look for ways to increase my productivity. What better way to cut productivity than reducing errors? All of this made me wonder about reproducibility, and how i could improve my coding habits and style. I read a couple of general books, for example Code Complete, but also less general books on agile and rapid development as well as software testing.

But when i tried to implement this best practices in Matlab, it felt like pushing against a very strong barrier. I started using git for version control and this was quite well,although git can be very weird and leaks abstraction. Yet regardlessof git, code organization sucks in Matlab. Namespace control is only rudimentarily implemented, and you can only put one public function in a file. I tried it over the course of a study, but it did not feel sufficient. My second Phd was almost finished. This gave me some freedom. Additionally, it made me wonder about my suitability for jobs in the industry. So i decided to spent some time to pick up new languages, to see whether they'd fare better.

New tricks

I played first with Julia, and wrote a module to load BrainVisionRecorder .eeg files. I chose Julia because the syntax was very similar to Matlab. I really enjoyed coding in Julia, and i got exposed to modules, namespace, closures, pre-compilers, notebooks, and many cool concepts more. What i missed in Julia were the good toolboxes. Furthermore, when i timed it, virtually the same code running in Julia took longer than in Matlab. Additionally, Juno was running in Atom. As visually stunning as it might be, Atom was not very stable. I did also go through the effort to use Atom as a Latex editor, though, and wrote a whole ethics proposal and some drafts for manuscripts with it. What made me finally try Python was that we needed to call some compiled C++ in a time-sensitive manner. Calling from Matlab did cause some overhead in the range of up to 20ms. This was a no-go for us. So we opted for Python. And Python was a relevation. All the things i liked in Julia, but in a robust environment, a slicker syntax and so much more support and well-documented packages. We have been using mostly BCI2000 for our experiments, and i spend the summer to rewrite almost all of our experiments in Python. Developing in Python is fun. Even GUI development is fun. A year ago, when people wrote on twitter how good python would be, i did not believe them. What i am currently exploring is R, and the syntax really is weird. But hey, R was the first to warn me when i was using Spearmans on data with non-unique ranks. Kudos for that. And RStudio is maybe one of the best IDEs i tried out so far, with great markdown support.

Conclusion

Currently, i see no good reason to turn back to Matlab. I still have it installed on my machine, mainly to re-run old scripts for not yet published studies. But Python and R is certainly the stronger combination. So, to conclude, what made me explore new languages? Some freedom, some practical necessity, some desire to become a better programmer. I guess that's all that's necessary, because almost all languages are open and free.