LEARNING TO CODE

iStock-185104278.jpg
 
 

Computer programming (i.e., coding) is an essential skill that all students within psychology and neuroscience should develop. Being comfortable with computer programming—especially Python and R—will enable you to develop your own task scripts and wrangle data much more effectively.

Yet, learning computer programming is a challenging task and the learning curve can be rather steep. In most situations, you will not learn how to code from psychology/neuroscience classes at Duke. Instead, you will learn from online training materials, software manuals/tutorials, other students/trainees, and your own experiences. Having a specific problem or goal in mind (e.g., program a new task or analyze a new dataset) helps considerably.

 

While you’re learning to code, keep the following points in mind:

·    Be patient and persistent. No one “gets it” immediately, and you will sometimes have to work through dozens of errors before arriving at a solution.

·    Be careful and obsessive. Most coding mishaps occur because of a tiny typo. If you’re thorough, you will catch these mistakes and save yourself time and frustration.

·    Understand input and output for all scripts you use.

·    Have a basic sense of how each line of code relates to other lines of code in your script. Everything is connected.

·    Paths errors are common. Avoid them by shoring up your understanding directory structures. Every input and output file lives in a specific location that you control.

·    Avoid staring at the same error for more than 30 minutes. If you haven’t solved it in 30 minutes, switch to some other work or take a walk outside.

·    Don’t be shy about asking for help. Other students/trainees and Internet forums (e.g., NeuroStars, Cookbook for R) are great places to find help.

 

·    Utilize as many resources as you can find. Duke has a great hub of information on specific languages, such as R and Python, that can be accessed either online or through the range of workshops they do throughout the year (https://library.duke.edu/data/data-visualization).

 

Although learning to code can be a daunting and frustrating task, it is well worth the investment. Coding is a skill that will generalize well beyond the laboratory