Confessions of a Neuro MATLAB Apologist

Many neuroscientists, especially those of the computational persuasion, say MATLAB should be dumped for Python. But, they’re wrong.

Example at random from TwiX calling to rid the field of the MATLAB scourge.

Here’s my take on the best arguments to use Python in neuroscience, and why I think they come up short.

1. Python is free, just like science.

I get the rationale. Python is more compatible with the ethos of academic science than MATLAB. Python is free to use and free of restrictions to access, just like the marketplace of ideas into which academics pour their work to advance science. But, just how free is science, really? Surely, no one who publishes paywalled articles in Nature would criticize pay-to-use programing languages (rolls eyes). There seems to me precious little difference between paying for laboratory equipment and paying for the software (or a programming environment) to analyze the data you record with that expensive equipment. The entire neuroscience community tacitly accepts this, which is why we all spend so much of our time writing grant proposals. Science costs money, and we should pay for the tools we need to get the job done.

2. Python is opens source, so we can check everyone’s work.

Open source means permission to go into the code to verify its veracity and perhaps to improve its algorithms. It bestows upon the masses equality, that any eager mind can find a bug in the code of any esteemed expert, and this transparency will make us all better through vetted programs. I don’t denigrate the beauty of that world, which was the original idealist vision for the entire web-based software ecosystem. But when the rubber meets the road, no one really does this for all the niche bespoke code that runs your specific random experiment. The exquisitely maintained libraries with massive userbases for things like math or deep learning, that essentially have companies backing them, are the exception rather than the rule. And if you want to dive into community code, MATLAB provides that through Git or the FileExchange. What really ends up happening is that graduate students in neuroscience that aren’t equipped to vet code end up using whatever is out there without checking it at all. The huge advantage of MATLAB is that all the stock functions and branded toolboxes are vetted by teams of engineers before they ship, so the code vetting that PhD students aren’t doing anyway doesn’t need to happen in the first place. Even if neuroscientists wanted to vet the code they wouldn’t be as good as the Mathworks engineers anyway because, well, they’re neuroscientists.

3. Python is where programming is headed, everyone should use it.

Undoubtedly, Python is king by popularity right now, which is taken to mean it is time to switch to it from MATLAB. But popularity is a specious reason for adoption. We should use the best tool for the job, not the current top dog. CompSci majors had damn well better know how to code in Python (among other languages) before they get released into the wild because the language is their substance, but neuroscientists only need to use Python if that’s what’s helpful for their experiments. Its a tool, not their media. Neuroscientists need to become conversational in programming, it isn’t the centerpiece of their education, and MATLAB is quick to pick up since so much of the overhead is done for you.

MATLAB is easy to debug quickly, both by students themselves and their PIs trying to make sure the codebase is properly implemented/validated. This cannot be understated as an asset because neuroscientists learning to code make copious mistakes at all levels, and debugging speed is key.

MATLAB runs, every time. When there is a language update (which Mathworks releases regularly), everything runs. If functions are going to be phased out, you have at least a year notice sent to you by command line warning and release notes. MATLAB has a standardized IDE that doesn’t interfere with its underlying libraries. You don’t have to worry about compatibility, or finding the right IDE, or even learning what an IDE is (we’re concerned with where the neurons are, not where the workspace GUIs are). There won’t be a public library update which breaks multiple dependencies in your codebase because MATLAB can vet for back-compatibility since they control the full software environment, not just one module. Plenty of companies that prioritize long-term stability of their tech-stacks are still running MATLAB. Usually neuroscience labs just need the code to work rather than absorb the latest programming tricks. We are not shipping at enterprise scale, we need the code Ned wrote four years to keep doing the spike sorting right.

MATLAB looks like math and graphs. Writing a line of math in MATLAB looks a lot like writing it on paper, whereas Python generally looks like code. That makes it easier to understand and write, and anything that lowers the coding bar for scientists is good news. Plotting data is also simple and full of options, which is great, since data visualization is what we spend all day doing.

4. People don’t switch to Python just because they’re lazy and don’t want to port legacy code.

Who cares? No one in academia should switch to Python just to stay current. There needs to be a compelling reason or urgent benefit to warrant the investment that codebase migration requires. If there’s something you need that MATLAB lacks and Python provides, and need it so much it overcomes all the benefits MATLAB offers to budding and confused neuroscience programmers, that’s when you bite the bullet and port your code.

5. Python does deep learning though, which is hot.

The wheels driving the explosion and astonishing capability of deep learning were greased thoroughly by Python. There is no serious deep learning research team pushing the boundaries of natural language models or foundation models for massive electrophysiology datasets or innovative mixed architectures using anything but Python. No argument here. If that’s what you’re doing, MATLAB has precious little to offer, since their toolbox for creating truly innovative network architectures is pretty clunky. I appreciate this limitation because I’m involved in work like this. But lets be honest, you’re not actually doing that kind of work. There are very few academic neuroscientists pushing the boundaries of deep learning architectures.
If you want to run any normal architecture that’s been around for a couple of years MATLAB has an off-the-shelf version of that for you ready to go that you can spin up basically instantly and that (because it’s in MATLAB) plays well with the rest of your software stack. Whenever we do standard deep learning projects we keep everything in MATLAB because it’s easy to integrate with our setups and MATLAB is still better than Python for our real-time hardware control work. It’s another case of using the best tool for the job. Very few neuroscientists will need the power to create deeply customized architectures; almost everything we need to do uses standard models for which where MATLAB is sufficiently capable.

Why do you hate Python, you hater?

I don’t hate Python. I’m rejecting the normative claim that neuroscientists switch to Python. If you are more computer scientist than neuroscientist or your computational neuroscience requires considerable deviation from standard ANN architectures, then Python will be the better tool for you, and you should use it. Python has a lot of advantages in userbase size and deep learning flexibility. I’m arguing that most neuroscientists don’t need any of that, and therefore, it isn’t worth giving up MATLAB and all its features that are so helpful for neuro R&D.

Leave a Reply

Your email address will not be published. Required fields are marked *