[ Content | View menu ]

Your First Programming Language Needs A REPL

Mark Mzyk | January 22, 2008

REPL: noun

Read-Eval-Print-Loop: an interactive top level or shell; a simple, interactive computer programming environment.

That definition was shamelessly adapted from the wikpedia article.

Floating around the web lately, there has been a lot of debate about whether Java should or should not be the first programming language taught to someone. It was started by this article: Computer Science Education: Where are the Software Engineers of Tomorrow? The responses have been numerous and varied. I haven’t been bookmarking them, so I’ll leave it to you and the power of Google to find them if you want to read them. Needless to say, there isn’t a consensus on the issue. It wouldn’t be fun to follow if there was.

Recently, in my own education, I’ve been working on learning Erlang. Erlang is not my first language. In fact, it’s not even my second. I first learned Java. Then I learned some assembly, then C. From there I moved on to C++. I then left school and learned PHP for my work. I’ve even dabbled in some Flex. Yet Erlang has something none of the previous languages I’ve worked with have (or if they do, I didn’t learn with it): a REPL.

A REPL, as defined above, is nothing but an environment where you can input some code and the REPL then spits the output right back at you. No need to compile, no need to wait. This, to me, is simply amazing.

Perhaps I sound like a small child in awe. It’s because I am. Programming Erlang, even only the very simple operations, is incredibly fun. I find myself extending what I’ve been reading because it’s easy for me to just type it in the REPL and see what is output. I play, I experiment. I’m a kid again.

I didn’t have this experience with Java. There was so much underlying boilerplate I had to understand. Then I had to compile and wait. This made it more of a chore instead of something like an experiment. It contributed to my frustration at learning the language. At the time, I thought it had to be this way. You had to slog through the tedium to get to the joy at the end. Only by putting in the work did you get the reward. Wow, was I wrong.

You can argue all day if Java is a good first language or not, if GUI tools are necessary or not, etc. In my opinion though, whatever first language someone is taught, it should have a REPL of some kind. It isn’t about making it easy. It isn’t about avoiding the underlying math or hidden concepts. It’s about fostering an environment that encourage exploration and experimentation.

If you want to be a biologist you can start by studying the plants that grow outside your door. Interested instead in chemistry? Cook something, observe how it changes. Psychology? Play mind games with your brother, see how he reacts. Why can’t computer science be this accessible? Why haven’t we made it this accessible? Actually, we have, but for some reason we haven’t done a good job disseminating the knowledge of just how accessible it can be. It starts with the REPL.

I don’t care what language you prefer. If you’re going to teach someone comptuer science, start with a languaget that has a REPL of some kind. I don’t even really care what kind of REPL it is, so long as it promotes exploration, experimentation, and enjoyment. It can exist for Java so a nine year old can understand it. It can involve a turtle. Too simplistic? I’ve already mentioned Erlang. There’s also Lisp. Even Python.

Sometimes it takes being a kid again to understand how things should be. In learning, don’t discount the power of playfulness and wonder that comes from instant feedback.