Keywords: clean code, data science education, refactor, test
Have you ever looked over code that you wrote months or years ago, only to be baffled by the codes purpose? To paraphrase Donald Knuth, the job of a data scientist isn’t writing code that tells the computer what to do; but instead writing code that tells other data scientists what we want the computer to do. Software engineers have accumulated decades worth of advice on writing clean code, as well as refined techniques for cleaning up old code. We will distill this advice by first summarizing the first principles of writing clean code. Then, the audience will be introduced to examples drawn from the literature and the author’s data science courses. Each example will used to illustrate problematic code, and then testing and refactoring will be applied to clean the code.