Rhett Allain on “Sloppy Code” and Messy Learning

Dr. Rhett Allain is an educator, author, and blogger who’s fascinated by physics.  In his books and on his blog for Wired he explores the wacky calculations behind cool things, real and imaginary.  From the physics of Stephen Curry’s Jump Shot to the Center of Mass of Thor’s Hammer, Allain consistently amuses an interests himself and his readers with great insights into the physics around us and in our culture, and he often uses code to make the calculations.  

In this interview, Allain talks about how he learned to code and how he’s using it to enrich himself, his readers, and his students.

You can find other interviews we’ve done with educational innovators here.

Rhett Allain and one of his research subjects
Rhett Allain with one of his research subjects

Elliott: How do you use code in a Physics classroom?

Rhett: For my introductory physics courses and labs, I now have the students make at least one numerical calculation (it doesn’t have to be in Python). The calculation should find the motion of an object with non-constant forces. Here’s a post I wrote with more details (including student complaints): http://www.wired.com/2014/02/isnt-physics-computer-science/

I love the way python lets you tackle interesting problems right away.

Elliott: Could you tell me a little about your background with code? How did you get started?

Rhett: Of course I had some programming courses as high school student and also couple in college. Remember back then they made you take a typing (on a typewriter) course before you could enroll in programming. That turned out to be a great thing – I can type quite fast now.

However, studying Basic, Pascal, and C didn’t do too much for me. It wasn’t until I started using code to solve problems – physics problems – that I really started to learn. In this case, I learned Python (with the visual module) after being inspired by the Matter and Interactions introductory physics textbook by Bruce Sherwood and Ruth Chabay (great book!).

It was probably around the year 2000 that I started doing stuff in Python. Once you get started, you kind of get addicted. I love the way python lets you tackle interesting problems right away.

I want to emphasize two things. First, there is no real code without a problem. You need the problem to come before the code (for me at least). Second, I am a big fan of sloppy code. The best code is the code that you understand even if it’s sloppy. All too often students get the idea that they should have this neat and organized code. That isn’t a bad thing, but students shouldn’t be intimidated from writing their own code.

The best code is the code that you understand even if it’s sloppy.

Elliott: That’s a very interesting point. It’s almost like writing- the acts of creating and of editing are very different and the creating is the hard, important part. Do you see parallels with your approach to code and teaching other skills or subjects?

Rhett: Yes, I think for learning any subject matter or skill it is very common for people to think “I’m not good enough”. Just take singing as an example. How many people do you know that won’t sing because they can’t sing? I think it’s better to just “sing, sing a song. Make it simple to last your whole life long. Don’t worry that it’s not good enough for anyone else to hear. Just sing, sing a song.” – I didn’t make that up, it’s from the Carpenters.

Elliott: In a recent post, you talk about using Python to help your daughter better understand the concept of radioactive decay for homework. Has that changed how you or she thinks about her learning?

Rhett: I’ll be honest – I think she’s moved on. Don’t get me wrong, she’s a smart kid – but she’s also very busy with other school things and other activities. I think the most important thing for her was that she could get the data for the experiment fast [instead of getting 200 pennies to shake up in a shoebox]. Sometimes we create things (like code) to help others but sometimes we just create it because we can. Again, I’m not saying it wasn’t useful or couldn’t be useful – just that she didn’t do anything else with it.

I try to expose my kids to programming as often as I can. They have all done stuff on code.org (like the hour of code) and I think they have made progress. With kids, I think the biggest mistake anyone could make would be to not expose them to coding as soon as possible. I suspect that most parent/teachers are just a little intimidated to do so – but they shouldn’t be. The coding tools available right now are pretty darn awesome.

Elliott: So you approach code from the point of view of what it let’s you do rather than being interested in it intrinsically? I hear a lot of talk about learning to code but not as much about authentic motivation and interest in using it.

Rhett: Is there anything more boring that just learning code? Oh sure, you need to get to the basics before you can use it to solve problems. That might be true – but still, if you have a problem before you have code you also have motivation. This is the best type of learning. It’s exciting learning when you are trying to solve a problem.

Without confusion, there is no learning.

Elliott: From what you’ve said above I gather that you have a very permissive and supportive attitude towards coding and a very high bar for making your classes hands-on. What of your teaching style is personal to you and what would you think is something you do that all teachers should do to be successful?

Rhett: In physics, there is one idea everyone should understand about learning. You can not learn physics without doing physics. Although I say this a million times in class, there are still students that think if they just pay enough attention in class they can grab those special words that will make them understand physics. Of course this is wrong. Physics understanding only comes through the sweat and tears of struggling through the material. Without confusion, there is no learning. There is no easy path to real learning.

What does this mean for class? Well, I try to provide as many opportunities for students to struggle in class. Of course we also go over some material and I answer questions. The most important thing is that the students continue to work on physics outside of class. I suspect the same would be true for other subjects.

Elliott: Your Wired blog is very popular. What inspired you to start blogging?

Rhett: I was teaching a physics course and some students asked to do some type of extra project. After letting them, I found the projects to be pretty awful and thought maybe they just need an example of a good project. So I decided to analyze that old Ford commercial that shows a truck stopping a plane on the runway.

Well, that was the end for me. I didn’t care about giving examples for students anymore, I only wanted to write more blog posts. Am I addicted? Maybe.

Editor’s Note: Read Rhett’s post on the F-150 stopping a plane here.

Elliott: I know for me that hearing from readers is a major motivation to my writing and interviews like this on. What kind of personal value to you get out of writing your posts?

Rhett: Everyone enjoys hearing that people find your stuff useful and/or entertaining. However, that’s not what motivates me. What motivates me is the question. Why does R2D2 fly the way he does? I want to know the answer. How much power would it take to fly a human powered helicopter? I want to know. The fact that other people read (and like) my stuff is just a bonus.

Elliott: Are there other sites or bloggers out there that you suggest readers should check out?

Rhett: I used to have and RSS feed of my favorite blogs – but I don’t do that so much anymore. Instead, I rely on finding new stuff from twitter. There are tons of great blogs, but by looking at what people share on twitter (or google plus) you can find stuff that you would otherwise miss.

Elliott: How can readers stay in touch and get updates from you and/or subscribe to your blog?

Here’s the list:

Also, I have a recent book that covers many of my favorite topics from Dot Physics: Geek Physics – Surprising Answers to the Planet’s Most Interesting Questions (http://amzn.com/111836015X)