Getting with the program

If you are realistic with what you can achieve, you need not be fearful of programming says Matthew Partridge as he delivers his ode to code. . .

If you are realistic with what you can achieve, you need not be fearful of programming says Drย Partridge as he delivers his ode to code...

Like it or not, coding is now a major part of science. Some might debate that point but this is my column and these articles go a lot better if you all just agree with me. Also, by coding, I mean programming or writing scripts that make computers go. I feel I have to be clear because I recently got in to an argument online about โ€˜codingโ€™ being outdated and โ€œimplies difficulty and confusionโ€. Again, letโ€™s just assume Iโ€™m right.

Anyway, tangents about my rightness aside, coding is very important to almost all branches of science - from small calculations, to larger development of controlling equipment, or setting up an early warning system based on the force applied by your boss as he opens the door linked to a gauge of how angry he is. I came to coding quite late in life (aged 29). The very first week of my PhD I was plonked in front of a piece of equipment I had never seen or heard of before and shown a computer program that included a check box with no label that you needed to scroll to and tick. I asked why and was told โ€œoh, that makes it work somehow - the last student put it thereโ€. Which led me to think a) that the last student was possibly an idiot, and b) if the student was an idiot and if he can code that in surely I can code it back out again.

Although confusing at first, coding will be an invaluable aid and speed up your research.

Although confusing at first, coding will be an invaluable aid and speed up your research.

This then led to me spending about 2 months trying to understand what all the wiggly lines meant, what breaks if I delete stuff and why it randomly says โ€œcritical errorโ€ when it starts but then carries on just fine. But eventually I learned enough to replace the tick box with some better code AND add in some nifty features which saved me about 2 hours per experiment.ย Back then I was learning Labview by editing other peopleโ€™s code. Iโ€™ve since moved on from that and now write quite a lot of my own. But over the last few years Iโ€™ve been learning Python which has reminded me of some key advice for anyone starting out that I think is worth sharing.

Back then I was learning Labview by editing other peopleโ€™s code. Iโ€™ve since moved on from that and now write quite a lot of my own.

Firstly, if you want to use code start small. There is no point thinking โ€œhmm, I need a program that has a billion features and literally does everythingโ€. The first Python code I wrote was a script that simply did a little bit of maths I needed. Within a few weeks I was pretty much just using my Python window as a really efficient calculator.

From there, I grew my calculators into little scripts to process my data sets. Normally Iโ€™d been doing my data set processing in Excel, which is fine but limited, and can be a bit annoying if you donโ€™t already know the cryptic excel formulae (despite using it several times I still barely understand how hlookup works). Python is much better for just crunching a thousand values, converting them to other units and then producing a nice little summary file. If youโ€™re doing anything more complicated than averaging and unit conversion (like resampling, rolling averages or searching) your entire python code will probably end up shorter than the required excel formula!

Getting into coding is like learning anything. Be reasonable about what you are going to do from the start. There are some amazing how-to guides for very clever projects like sword wielding robots or games of thermonuclear warfare. This is a bit like planning a trip to France before youโ€™ve even start learning French. Donโ€™t start it thinking โ€œIโ€™ll be re-designing operating systems by the end of the weekโ€. Start it thinking โ€œI wish I could process my data slightly faster than I do alreadyโ€ because that is the actually useful power of code in science.

Related Content

Pin It on Pinterest

Share This