Last week, a tweet by Roberto Trotta drew my attention to a recent paper by Simon Portegies Zwart that studied the amount of carbon dioxide emitted by running N-body simulations in different programming languages.
The figure that caught my attention was Figure 3, copied below from the version of the paper published in Nature Astronomy. It shows that, for this type of application, Python is horrendously bad for the environment in comparison to Fortran and C++. The author exhorts educators to reconsider teaching Python to students, instead favouring a return to compiled languages.

The first programming language I learnt (besides Scilab, a free version of MATLAB) was Fortran. And no, I didn’t study computer science in the 1950s. I was taught Fortran as an astrophysics undergraduate in 2015. Fortran has the unfortunate — and in my opinion, somewhat undeserved — reputation of being a very elderly and redundant language, far surpassed in ease of use and flexibility by modern, interpreted languages like Python.
There’s some truth in this statement. My friends and I certainly agreed with it when we started learning it. But my opinion has since changed. The relatively low level syntax of Fortran meant I learnt to think more like a computer, and consider the structure and efficiency of my programs in greater detail than is necessary with equivalently simple Python scripts. Once you have some familiarity with Fortran, it’s usually easy to understand what a program written in it is doing. This is not something I can say about Python, ironically due in part to the flexibility of writing styles that the language is popular for.
So, I retweeted Roberto’s tweet, as it tickled me to find that my pro-Fortran bias could actually have a scientific justification beyond my own personal preference. Then I began to read other people’s comments about the paper, and in particular the figure I showed above.
Many people reacted very defensively to the perceived criticism of those who use Python — which, let’s be honest, is everyone in the astronomy and cosmology community, barring the very few pure pen and paper theorists that still survive (and even they use Mathematica occasionally).
Some noted that the paper makes an unfair comparison here: no one in their right minds would really use Python to run an N-body simulation. But they missed the wider point of the paper, as the author also considered the effect that parallelising code can have. This means running parts of the code in parallel to each other, thus generally speeding up the computation and reducing run time for the program.
The main finding is that running a program on a single core workstation produces more carbon dioxide than running a parallelised version on a cluster (up to a certain point). This is partly because supercomputing clusters are generally better maintained than personal workstations, and are built with more efficient and faster components.
This is a point that does not work in Python’s favour. It is not an easy language to parallelise. Pure Python will not be sped up by multi-threading, as it has what’s called a global interpreter lock, which prevents threads from executing concurrently. If you want to parallelise Python effectively, you have to rely on external libraries — and these will probably be written in C or Fortran.
This is where the discussion ends for me. I will continue to use Fortran for my computationally intensive tasks and Python for simple things like making plots. But the strong reactions that many people had to this paper and its conclusions made me wonder about the creep of tribalism in science.
Tribalism can be seen in most walks of life, most obviously (in the before times, anyway) on Saturday afternoons at football grounds all across the country. It’s also been very clearly evident in the politics of the United States and the United Kingdom over the past five years or so.
One other comparison that came to my mind was the reaction I often get when I tell people I’m vegetarian. Vegetarianism and veganism have grown hugely in popularity since I was growing up, and it’s happily now easy for me to find something good on the menu when I go out to eat. And yet I still try to avoid talking about my dietary choice with people (friends and strangers alike). Some ask natural questions, but many get very defensive and feel they have to justify to me why they consume animal products.
I am certain that this increase in polarisation of opinions and beliefs has been exacerbated by social media. The ability to isolate yourself in a circle of people who all share your opinion (the echo chamber concept) and receive instant validation of posts you share via likes, retweets and replies drives this cementing of convictions.
Doubtless we’ve all been spending more time online since the beginning of the pandemic too, and the addictive nature of social media — and the fact that it is deliberately designed to be that way — has been widely studied. Dopamine, a hormone released during pleasurable activities, increases in production when a notification comes in. The dopamine spike can manifest as a physical sensation: that familiar thrill in the gut, the hairs on the back of your neck standing up in reaction to the validation that a notification brings. This reinforces the cycle of posting, reacting to posts and anticipating the next notification.
At the end of all this, we see overblown, emotional reactions to every single post or tweet that even mildly contradicts our personal beliefs. It’s too easy to rattle off two hundred and eighty characters of rebuttal, and be sucked into an angry “debate” about a topic which appears innocent to an disinterested observer.
I don’t think this is healthy for science.
Yes, we must have opinions. Yes, we must share those opinions. No, we should not isolate ourselves in a circle of sycophants and blurt out responses to everything that annoys us. Quite apart from the effect on a person’s blood pressure, we must consider that future students are certainly reading these sprays of thought. Aggressively dismissing a paper in a quick tweet sends the impression that we could react in the same way when the student comes to us for opinions on their own written work.
And, lest I sound too righteous, I’m fully aware that I react quickly and angrily myself, though I’m trying to cut down by regarding it as a somewhat guilty pleasure that I treat myself to maybe once a week.
What can we do in the long run? I advocate for three things:
- Write long form content so you can fully and dispassionately develop your opinions. For example, this very blog is part of my effort to reduce my reactive social media posting.
- Talk to people in real life. For example, take this paper to your local journal club (and if you don’t have one, start one) and listen to what other people think about it.
- Log off. Every now and then, treat yourself to typing out a tweet, backspacing it, closing your laptop and going outside. This has the added bonus of reducing your carbon emissions too.
Leave a Reply