I did a BSc in Psychology quite a long time ago and although a lot of things have changed — such as the grey bits in my hair — I’ve noticed that at least one thing hasn’t. Most psychology students hate:
- Statistics
- Computer programming
There were fifteen years between when I started my undergraduate degree and when I returned to teach psychology as a lecturer. The aversion to maths and computer science was still present. Most psychology students elected to study psychology because they wanted to learn about things like anxiety and Schizophrenia, moods and personality, or just to understand themselves a bit better.
Rarely do students sign up to a psychology degree because they’re passionate about normal distributions and conditional statements. Programming knowledge can help, but it can also detract you from focusing on the important parts of your research.
Let’s take a stroll…
When I was a lecturer, I always hoped that by the end of the three years of undergraduate study most students had gained an appreciation for statistics and programming and why it’s so important. But I always remember at the end of my PhD, a close friend saying they would never have started the PhD process if they had known how much programming it involved. She was interested in how the brain worked, not coding in MATLAB. I don’t think she’s done any programming since.
Personally, I grew up with computers. My Dad was an electrical engineer whose hobby was building computers on the weekend, so I’ve always felt comfortable in this world. I truly believe that learning to code is a great skill, one that we should be introducing into schools at the earliest age possible so hopefully — like me — people get past the dislike and see what a powerful and helpful tool it can be.
That said, I’m a psychologist and a neuroscientist, not a computer scientist. I program as a means to an end, understanding how the brain works and why we behave the way we do. At some point, you have to know when to pass a job off to the experts.
Let’s start on a positive note and talk about where a little bit of programming knowledge can go a long way.
The Good
First of all, programmers are some of the funniest people I know. I’ve already lost hours on Reddit forums going through memes for this piece! Learning a bit about programming can open up a new world of comedy. All (well some) jokes aside, programming is a great skill to develop for a number of different reasons.
Automate simple tedious tasks
Programming is great if you need to solve monotonous and tedious tasks quickly and easily. Take the example of moving and organising files into different folders. This is something that can come up in almost any job. Once you know the specific steps of the process it’s easy to write a couple of lines of code that will move everything for you. For example, your boss wants you organise photos for the company website.
You need to move all the pictures with “David” in the filename into a folder called David and all the pictures with “Kara” in the filename into a folder called Kara. On a mac, you just need to open Terminal, go to the folder with all the pictures, and type something like ‘cp *Kara*.jpg Kara/’. One line of simple code can save hours of dragging and dropping.
Avoid mistakes (kind of…)
Using the same analogy as above, if you wanted to move 1000 pictures into 5 different folders then not only is it boring and time-consuming but you’re likely to make mistakes. Writing down the process helps you retrace your steps and see where there could have been a mistake. There’s no log keeping when you drag and drop so you don’t know what you did. There’s a reason that we always had to write down our workings in maths exams.
Keeping good records has become even more important given the reproducibility crisis in science. The poet Alexander Pope said “to err is human” and with the best will in the world, mistakes happen. Keeping logs of your data collection and analysis steps will help researchers reproduce your findings so that we remove erroneous results from the literature and help make psychological phenomena more reproducible.
Learn to speak clearly (in computer code)
In order to write code, you need to break your problem down into clear and simple steps. If the end goal is to make a sandwich, I can’t just tell a computer to make me a sandwich. You need to break the process down into clear and precise processes.
- Walk to kitchen
- Check fridge for existing sandwich
- If exists, eat that sandwich
- Else, start making a new sandwich
- Ingredients = Bread, cheese, tomato, butter
- Get ingredients out of fridge
- Tools = knife, board
- Get tools from the drawer, etc.
Writing down the step-by-step processes involved in the simplest tasks makes you realise how many processes we have running through our heads at any one time. Not to mention how surprisingly complicated the simplest tasks actually are. Learning to code means you learn to think about the individual elements involved in creating a larger behaviour. Understanding behaviours in this way will help you communicate them more clearly, either in an essay/lab report or just describing it to people.
The Bad
You might have guessed from the first section that I like programming, and that’s true. But our relationship is pretty hot and cold. On a good day, it’s great, on a not-so-good day …
Debugging and those cursed red lines!
Truthfully, I’ve lost count of how many hours I’ve spent screaming at computer screens with red error messages only to find out that:
- I’d got a lowercase L confused with a capital i — can you see the difference between l or I ?
- I’d used { instead of [ or (.
- I’d actually fixed the problem but because I didn’t refresh the workspace my code used an old version of the variable that didn’t have a column 6 whilst I stared at the code which clearly defined 6 columns!!
You can argue that programming teaches you persistence and problem-solving skills, but surely there are better ways to do this! The hours I spent debugging typos is time that could have been used reading more around the topic or just relaxing. Was programming worth it? Come to think of it, those grey hairs began to appear when I started learning to code …
What do you mean that’s not the right programming language?
You’ll pick up on lots of generic skills whilst learning to code. These are common across most programming languages. However, there are also lots of differences. For example, counting in MATLAB starts with 1, i.e. the first column would be referred to as column 1. However, counting in most other languages starts with 0, so this same column would be referred to as column 0.
Each language has its own sets of functions and grammatical rules, and whilst some of this is transferable across languages there are a lot of things that are language-specific. Most programs will let you calculate the standard deviation, but I can never remember if the function is “sd”, “std”, or “stdev”. This also leads to more errors when changing between languages, and more screaming at computers.
The worst thing is that languages change, and sometimes they even die out. I have experiments that can only work in MATLAB v2014b or earlier. Even if you’ve managed to build a perfectly working experiment, the rules of the game can change with an update and you’re back to square one.
As for longevity across languages, I’ve interviewed technicians that studied in the 80s, so they learned fortran and pascal which are pretty much dead languages now. I spent 15 years learning to use MATLAB, but this is dying out in favour of R and Python. As research moves out of the lab and onto the internet, the web languages like HTML and Javascript will become even more important to psychologists. It can be so frustrating to learn something that could quickly become obsolete. To paraphrase Carrie Bradshaw, “I couldn’t help but wonder … was learning to code worth it?”
Is it really worth the time?
Although programming is a useful skill to have under your belt, given the limited amount of time we have at our disposal, how much do we really gain by learning to code? The truth is, you have to make quite a large investment into programming before you really start to see any gains. If you’re studying a behavioural science subject, the overarching goal is to understand the brain and behaviour. So any time spent learning a new skill like coding is time you’re taking away from developing other skills.
How do you decide what skills are most important? Look at senior scientists and Professors, what are their key skills? I would argue that 9/10 times it’s science communication (both writing and presenting) and experimental design/statistics. But I’ll let you in on a secret… most Professors don’t know how to program in modern languages or use modern software tools!
As you get promoted and move up the ladder (either in academia or industry) you’ll spend more time as a thought leader postulating and communicating the big ideas. You don’t need to program anymore, you’ll hire someone to bring your vision to life.
The Ugly
So you have a good handle on JavaScript or Python? That’s great! So what do you know about server architecture?
Learning a programming language is only the first step in getting your research paradigms and questionnaires online. You also need somewhere to store the experiment so participants can interact with it plus you need to save their responses. For this, you need to know about servers and you need to become even more of a computer scientist.
Also, how secure is your server? You’ll need an information security expert to check for that.
By the way, are you complying with laws surrounding data privacy? Yes, along with learning programming and computer science, you now need to learn law.
Who has the time?! All I wanted was to show participants some pictures and record their responses!!
The right tool shall set you free
Whilst I would recommend learning to code, I also understand that it’s not always a good use of time. For most behavioural scientists, understanding the literature and coming up with exciting questions is more important than learning to code. As a behavioural scientist, programming should be a means to an end, a way of creating that great experiment that’s going to change the world! So how can we build experiments easily without investing too much time learning to code?
In the 1980s, Graphical User Interfaces (GUIs) changed the way people used computers. People didn’t need to learn programming languages and long lists of commands anymore. People could work computers intuitively using a mouse to click and drag icons on a screen. This revelation made computers accessible to everyone, and helped Microsoft and Apple put computers in every home and every pocket.
In experimental psychology, there are some task builder tools that allow researchers to bring their protocols to life without coding such as Gorilla, Psychopy with Pavlovia, Testable or Labvanced. These are a great solution for most people and you can create lots of experiments without a single line of code. If you want to explore some of the other benefits of Task Builders, check out our article “10 Reasons Why Task Builders Are Better Than Writing Code”.
One of the most exciting things about science is expanding human knowledge with cutting-edge paradigms and ideas. However, standing at the frontier of your field can often require novel functionality. This is where Task Builders can fall down as they lack the flexibility of pure code.
That’s why at Gorilla, we’ve made four important design and service decisions to make sure we can take you over that horizon.
- Our tools are modular. Similar to Lego bricks, they can be combined in an infinite number of ways to bring your protocol to life. In my short time at Gorilla I’ve already seen zones and widgets combined in ways I’d never imagined were possible, thanks to the creativity of our clients.
- The Gorilla’s Task Builder has a script tab so that you can augment the functionality that we’ve provided with your own code. In fact, we’ve got some really cool examples of code here that you can copy and paste into your experiments to do things like change colours or send participants on different journeys based on their responses.
- Gorilla includes a vanilla JavaScript code editor for writing bespoke code from scratch and running it within our server infrastructure. This means that you can benefit from someone else’s hard work and import an existing paradigm into Gorilla as long as it’s written in JavaScript (i.e., jsPsych, Lab.js). For those of you that are invested in learning to code, you can write your own task, game, website, or simulation from scratch!
- Sometimes it’s best to hire in the support you need. At Gorilla, we offer a consultancy desk that gives you access to high-quality research software engineers and behavioural scientists who can add components to Gorilla or build your whole protocol for you.
Whatever you choose, remember that programming is a means to an end, and so look for a solution that lets you focus on what’s most important for you. For most people, that means finding a tool that’s powerful and flexible enough to accommodate their research.
With or Without code — Happy Experimenting!