Love and Hate

I did a BSc in Psy­chol­o­gy 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 psy­chol­o­gy stu­dents hate:

  1. Sta­tis­tics
  2. Com­put­er programming

There were fifteen years between when I started my under­grad­u­ate degree and when I returned to teach psy­chol­o­gy as a lec­tur­er. The aver­sion to maths and com­put­er science was still present. Most psy­chol­o­gy stu­dents elected to study psy­chol­o­gy because they wanted to learn about things like anxiety and Schiz­o­phre­nia, moods and per­son­al­i­ty, or just to under­stand them­selves a bit better.

Rarely do stu­dents sign up to a psy­chol­o­gy degree because they’re pas­sion­ate about normal dis­tri­b­u­tions and con­di­tion­al state­ments. Pro­gram­ming knowl­edge can help, but it can also detract you from focus­ing on the impor­tant parts of your research.

Let’s take a stroll…

When I was a lec­tur­er, I always hoped that by the end of the three years of under­grad­u­ate study most stu­dents had gained an appre­ci­a­tion for sta­tis­tics and pro­gram­ming and why it’s so impor­tant. But I always remem­ber at the end of my PhD, a close friend saying they would never have started the PhD process if they had known how much pro­gram­ming it involved. She was inter­est­ed in how the brain worked, not coding in MATLAB. I don’t think she’s done any pro­gram­ming since.

Per­son­al­ly, I grew up with com­put­ers. My Dad was an elec­tri­cal engi­neer whose hobby was build­ing com­put­ers on the weekend, so I’ve always felt com­fort­able in this world. I truly believe that learn­ing to code is a great skill, one that we should be intro­duc­ing into schools at the ear­li­est age pos­si­ble so hope­ful­ly — like me — people get past the dislike and see what a pow­er­ful and helpful tool it can be.

That said, I’m a psy­chol­o­gist and a neu­ro­sci­en­tist, not a com­put­er sci­en­tist. I program as a means to an end, under­stand­ing 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 pos­i­tive note and talk about where a little bit of pro­gram­ming knowl­edge can go a long way.

The Good

The Drake Meme: He's not fond of learning to program for future work, but very fond of understanding programming jokesFirst of all, pro­gram­mers are some of the fun­ni­est people I know. I’ve already lost hours on Reddit forums going through memes for this piece! Learn­ing a bit about pro­gram­ming can open up a new world of comedy. All (well some) jokes aside, pro­gram­ming is a great skill to develop for a number of dif­fer­ent reasons.

Auto­mate simple tedious tasks

Pro­gram­ming is great if you need to solve monot­o­nous and tedious tasks quickly and easily. Take the example of moving and organ­is­ing files into dif­fer­ent folders. This is some­thing that can come up in almost any job. Once you know the spe­cif­ic steps of the process it’s easy to write a couple of lines of code that will move every­thing for you. For example, your boss wants you organ­ise photos for the company website.

You need to move all the pic­tures with “David” in the file­name into a folder called David and all the pic­tures with “Kara” in the file­name into a folder called Kara. On a mac, you just need to open Ter­mi­nal, go to the folder with all the pic­tures, and type some­thing like ‘cp *Kara*.jpg Kara/’. One line of simple code can save hours of drag­ging and dropping.

Avoid mis­takes (kind of…)

Using the same analogy as above, if you wanted to move 1000 pic­tures into 5 dif­fer­ent folders then not only is it boring and time-con­sum­ing but you’re likely to make mis­takes. 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 work­ings in maths exams.

Keeping good records has become even more impor­tant given the repro­ducibil­i­ty crisis in science. The poet Alexan­der Pope said “to err is human” and with the best will in the world, mis­takes happen. Keeping logs of your data col­lec­tion and analy­sis steps will help researchers repro­duce your find­ings so that we remove erro­neous results from the lit­er­a­ture and help make psy­cho­log­i­cal phe­nom­e­na more reproducible.

Learn to speak clearly (in com­put­er 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 sand­wich, I can’t just tell a com­put­er to make me a sand­wich. You need to break the process down into clear and precise processes.

  1. Walk to kitchen
  2. Check fridge for exist­ing sandwich 
    1. If exists, eat that sandwich
    2. Else, start making a new sandwich 
      1. Ingre­di­ents = Bread, cheese, tomato, butter
      2. Get ingre­di­ents out of fridge
      3. Tools = knife, board
      4. Get tools from the drawer, etc.

Writing down the step-by-step process­es involved in the sim­plest tasks makes you realise how many process­es we have running through our heads at any one time. Not to mention how sur­pris­ing­ly com­pli­cat­ed the sim­plest tasks actu­al­ly are. Learn­ing to code means you learn to think about the indi­vid­ual ele­ments involved in cre­at­ing a larger behav­iour. Under­stand­ing behav­iours in this way will help you com­mu­ni­cate them more clearly, either in an essay/lab report or just describ­ing it to people.

The Bad

You might have guessed from the first section that I like pro­gram­ming, and that’s true. But our rela­tion­ship is pretty hot and cold. On a good day, it’s great, on a not-so-good day …

Debug­ging and those cursed red lines!

Liam Neeson is TAKEN aback by an odd programming bug,

Truth­ful­ly, I’ve lost count of how many hours I’ve spent scream­ing at com­put­er screens with red error mes­sages only to find out that:

  • I’d got a low­er­case L con­fused with a capital i — can you see the dif­fer­ence between l or I ?
  • I’d used { instead of [ or (.
  • I’d actu­al­ly fixed the problem but because I didn’t refresh the work­space my code used an old version of the vari­able that didn’t have a column 6 whilst I stared at the code which clearly defined 6 columns!!

You can argue that pro­gram­ming teaches you per­sis­tence and problem-solving skills, but surely there are better ways to do this! The hours I spent debug­ging typos is time that could have been used reading more around the topic or just relax­ing. Was pro­gram­ming worth it? Come to think of it, those grey hairs began to appear when I started learn­ing to code …

What do you mean that’s not the right pro­gram­ming language?

You’ll pick up on lots of generic skills whilst learn­ing to code. These are common across most pro­gram­ming lan­guages. However, there are also lots of dif­fer­ences. For example, count­ing in MATLAB starts with 1, i.e. the first column would be referred to as column 1. However, count­ing in most other lan­guages starts with 0, so this same column would be referred to as column 0.

Each lan­guage has its own sets of func­tions and gram­mat­i­cal rules, and whilst some of this is trans­fer­able across lan­guages there are a lot of things that are lan­guage-spe­cif­ic. Most pro­grams will let you cal­cu­late the stan­dard devi­a­tion, but I can never remem­ber if the func­tion is “sd”, “std”, or “stdev”. This also leads to more errors when chang­ing between lan­guages, and more scream­ing at computers.

The Office likes it's proramming jokes.

The worst thing is that lan­guages change, and some­times they even die out. I have exper­i­ments that can only work in MATLAB v2014b or earlier. Even if you’ve managed to build a per­fect­ly working experiment, the rules of the game can change with an update and you’re back to square one.

As for longevi­ty across lan­guages, I’ve inter­viewed tech­ni­cians that studied in the 80s, so they learned fortran and pascal which are pretty much dead lan­guages now. I spent 15 years learn­ing to use MATLAB, but this is dying out in favour of R and Python. As research moves out of the lab and onto the inter­net, the web lan­guages like HTML and Javascript will become even more impor­tant to psy­chol­o­gists. It can be so frus­trat­ing to learn some­thing that could quickly become obso­lete. To para­phrase Carrie Brad­shaw, “I couldn’t help but wonder … was learn­ing to code worth it?”

Is it really worth the time?

Although pro­gram­ming is a useful skill to have under your belt, given the limited amount of time we have at our dis­pos­al, how much do we really gain by learn­ing to code? The truth is, you have to make quite a large invest­ment into pro­gram­ming before you really start to see any gains. If you’re study­ing a behav­iour­al science subject, the over­ar­ch­ing goal is to under­stand the brain and behav­iour. So any time spent learn­ing a new skill like coding is time you’re taking away from devel­op­ing other skills.

How do you decide what skills are most impor­tant? Look at senior sci­en­tists and Pro­fes­sors, what are their key skills? I would argue that 9/10 times it’s science com­mu­ni­ca­tion (both writing and pre­sent­ing) and exper­i­men­tal design/statistics. But I’ll let you in on a secret… most Pro­fes­sors don’t know how to program in modern lan­guages or use modern soft­ware tools!

As you get pro­mot­ed and move up the ladder (either in acad­e­mia or indus­try) you’ll spend more time as a thought leader pos­tu­lat­ing and com­mu­ni­cat­ing 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?

Learn­ing a pro­gram­ming lan­guage is only the first step in getting your research par­a­digms and ques­tion­naires online. You also need some­where to store the experiment so par­tic­i­pants can inter­act with it plus you need to save their respons­es. For this, you need to know about servers and you need to become even more of a com­put­er scientist.

Also, how secure is your server? You’ll need an infor­ma­tion secu­ri­ty expert to check for that.

Data Protection, do you speak it?

By the way, are you com­ply­ing with laws sur­round­ing data privacy? Yes, along with learn­ing pro­gram­ming and com­put­er science, you now need to learn law.

Can't you just take the eagles?

Who has the time?! All I wanted was to show par­tic­i­pants some pic­tures and record their responses!!

The right tool shall set you free

Whilst I would rec­om­mend learn­ing to code, I also under­stand that it’s not always a good use of time. For most behav­iour­al sci­en­tists, under­stand­ing the lit­er­a­ture and coming up with excit­ing ques­tions is more impor­tant than learn­ing to code. As a behav­iour­al sci­en­tist, pro­gram­ming should be a means to an end, a way of cre­at­ing that great experiment that’s going to change the world! So how can we build exper­i­ments easily without invest­ing too much time learn­ing to code?

In the 1980s, Graph­i­cal User Inter­faces (GUIs) changed the way people used com­put­ers. People didn’t need to learn pro­gram­ming lan­guages and long lists of com­mands anymore. People could work com­put­ers intu­itive­ly using a mouse to click and drag icons on a screen. This rev­e­la­tion made com­put­ers acces­si­ble to every­one, and helped Microsoft and Apple put com­put­ers in every home and every pocket.

In exper­i­men­tal psy­chol­o­gy, there are some task builder tools that allow researchers to bring their pro­to­cols to life without coding such as Gorilla, Psychopy with Pavlovia, Testable or Lab­vanced. These are a great solu­tion for most people and you can create lots of exper­i­ments without a single line of code.  If you want to explore some of the other ben­e­fits of Task Builders, check out our article “10 Reasons Why Task Builders Are Better Than Writing Code”.

One of the most excit­ing things about science is expand­ing human knowl­edge with cutting-edge par­a­digms and ideas.  However, stand­ing at the fron­tier of your field can often require novel func­tion­al­i­ty. This is where Task Builders can fall down as they lack the flex­i­bil­i­ty of pure code.

That’s why at Gorilla, we’ve made four impor­tant design and service deci­sions to make sure we can take you over that horizon.

  • Our tools are modular. Similar to Lego bricks, they can be com­bined in an infi­nite number of ways to bring your pro­to­col to life. In my short time at Gorilla I’ve already seen zones and widgets com­bined in ways I’d never imag­ined were pos­si­ble, thanks to the cre­ativ­i­ty of our clients.
  • The Gorilla’s Task Builder has a script tab so that you can augment the func­tion­al­i­ty that we’ve pro­vid­ed with your own code.  In fact, we’ve got some really cool exam­ples of code here that you can copy and paste into your exper­i­ments to do things like change colours or send par­tic­i­pants on dif­fer­ent jour­neys based on their responses.
  • Gorilla includes a vanilla JavaScript code editor for writing bespoke code from scratch and running it within our server infra­struc­ture. This means that you can benefit from someone else’s hard work and import an exist­ing par­a­digm into Gorilla as long as it’s written in JavaScript (i.e., jsPsych, Lab.js). For those of you that are invest­ed in learn­ing to code, you can write your own task, game, website, or sim­u­la­tion from scratch!
  • Some­times it’s best to hire in the support you need. At Gorilla, we offer a con­sul­tan­cy desk that gives you access to high-quality research soft­ware engi­neers and behav­iour­al sci­en­tists who can add com­po­nents to Gorilla or build your whole pro­to­col for you.

What­ev­er you choose, remem­ber that pro­gram­ming is a means to an end, and so look for a solu­tion that lets you focus on what’s most impor­tant for you. For most people, that means finding a tool that’s pow­er­ful and flex­i­ble enough to accom­mo­date their research.

With or Without code — Happy Experimenting!

Joshua Bal­sters

Dr Joshua Bal­sters is a Psy­chol­o­gist and Neu­ro­sci­en­tist with a BSc in Psy­chol­o­gy and PhD in Cog­ni­tive Neu­ro­science from Royal Hol­loway Uni­ver­si­ty of London. He worked as client liaison at Gorilla from 2020 — 2021, helping researchers get started with online research and sup­port­ing their projects. 

Jo Ever­shed

Jo is the CEO and co-founder of Caul­dron and Gorilla. Her mission is to provide behav­iour­al sci­en­tists with the tools needed to improve the scale and impact of the evi­dence-based inter­ven­tions that benefit society.