An Introduction to Programming for Psychology
R programming and Python programming are likely the most applicable languages in psychology. There are exceptions in sub-areas with specific analyses so ask your supervisor, but you can't go wrong starting with R and Python.
The best want to learn would be to take an "intro to computer science" course!
Why? There is a big difference between "learning R" and "learning to program".
Language-specific workshops are okay for "learning R" or another specific language, but that is a very limited approach.
Actual computer science courses are best for "learning to program".
Learning to program is like learning to drive
Once you learn how to drive, you can drive any car.
You learn the rules of the road, the signs you're likely to see, how to accelerate and turn a vehicle, how to park, how to navigate a roundabout, and so on. After you learn, you can drive any truck, van, sedan, coupe, hatchback, station-wagon, or roadster. I concede that a normal license wouldn't prepare you to drive a big bus or an 18-wheeler, but generic driving knowledge teaches you to drive any common commuter vehicle.
Once you learn how to program, you can learn to use any programming language.
I had never used R before grad school, but I had learned to program during my undergrad in Software Engineering. Within a few days, I was competent in R. By the end of my first semester, I was competent enough that I could teach others. This is because I already knew how to program. Knowing how to program means not being limited to R or Python or any individual language. If a new programming language would be useful for something I'm working on, I will be able to learn how the syntax differs and can pick it up quickly. This is just like figuring out where the shifter is in a new car or how much pressure to put on the pedal. This ability to learn new languages is the power of learning to program rather than learning a single programming language.
An introductory computer science course teaches core programming concepts.
This includes variables, data structures, if-statements, loops, functions, recursion, debugging, commenting, documentation, and maybe a little more, but not much more. There are only a few basics you really need to wrap your head around programming, but programming is infinitely more difficult when you don't know the basics! You would learn how basic programming concepts work in general while applying what you learn to a specific language in the course. You could then apply your knowledge to any new language you are likely to learn, such as R or Python.
You won't have to concern yourself with more advanced concepts and algorithms, nor will you be using complex specialist languages in psychology (i.e. the "18-wheelers" of programming languages). Instead, you could focus on gaining enough general knowledge of programming to learn whatever you need, including R (which is a very easy language that is quite specific to analysis and visualization) and Python (which is a pain in the ass to get installed, but is a very versatile and conventional programming language for analysis and for developing experimental tasks, e.g. behavioural measures).
By learning to program, you learn to see patterns
You'll be asking, "How does this language do X?"
- How does this language assign variables?
- How does this language end a line?
- How does this language handle spaces and indentation?
- How does this language use brackets?
- How does this language call functions and return results?
- How does this language index arrays? Do they start at 0 or 1?
For example, you learn to ask, "How does this language write a "for" loop?"
Generally speaking, all programming languages you'll run into have some version of a "for" loop. Once you know how they work, you know how they work everywhere. What changes is the specific way you write down the "for" loop. How do you specify the variables? What punctuation do you use? How do you break out of the loop? All that sort of stuff.
In contrast, if you only know how a "for" loop works in one specific language, you don't really understand how "for" loops work. If it seems like magic, you don't understand. If something goes wrong in your "for" loop, you will have a hard time fixing the issue because you don't really understand what is happening. You also won't be able to implement a "for" loop in a new language if you have to do something outside your comfort zone.
When you know how to program, all of this is easy to solve.
Index
Return to Software
Continue to Glossary and Acronyms