Skip to content

Instantly share code, notes, and snippets.

@pyrmont
Created June 10, 2014 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pyrmont/2c7ec066c75113b7a295 to your computer and use it in GitHub Desktop.
Save pyrmont/2c7ec066c75113b7a295 to your computer and use it in GitHub Desktop.
Ruby as a First Programming Language

My friend Rob tweets:

The more experience I get with Ruby, the more irresponsible I feel when teaching it to new devs.

OK, so I think Ruby is a good language to use to start teaching programming for a number of reasons.

First, I believe it's best to start beginners with an object-oriented language. The OO paradigm provides, in my opinion, the best balance between power and comprehensibility. I'm happy to concede that OO languages do not immediately make sense to a lot of people in a way that procedural languages do. After all, if you can read a recipe, you can basically read procedural code. The problem is that it's pretty difficult to do anything interesting in procedural languages and doing interesting things is what will motivate a person to get past their early, and inevitable, frustration. You might accept this but argue that functional languages have a high degree of power and should be the starting point. Unfortunately, while functional languages are able to do truly spectacular things, they do this to some degree by sacrificing comprehension. Since reading code is so important to writing code, having the former be a challenge risks discouraging a person from ever getting competent at the latter.

Even if you don't accept that the first language should necessarily be object-oriented, you might nevertheless agree that a first language should utilise a paradigm comprehensively. There's probably a correct word for this but what I mean when I say 'comprehensive' is that the paradigm used is used comprehensively throughout the language. If you're going to be an OO language, don't have primitive types. Ruby is comprehensive in this sense; it's objects all the way down. Why put such a premium on comprehensiveness? Because it helps beginners with the most difficult thing: constructing their own mental model of what's happening. If the language employs a paradigm comprehensively, it means less complexity required in said model to deal with special cases where the paradigm doesn't apply.

Ruby has the additional virtue of teaching beginners two things that, while peripheral to the actual act of programming, are nevertheless essential to being any good: namely, the command line and code reuse. Ruby's gems, and the command line tools used by various high-profile Ruby frameworks (Rails, Sinatra, Compass, etc), are so simple and useful that not only is using them empowering but it can even be fun. From almost the very beginning, Ruby has you in the terminal, leveraging other people's code. It's difficult to describe how much of an absolute bad ass it can feel for a command line newbie to type bundle install and see all this code magically download and become part of their app. It's the kind of feeling that builds confidence and makes you want to learn how to do more elaborate things.

Finally, Ruby has a strong and opinionated community. Surely one of the worst thing's about PHP (other than everything else) is that for so long it has been pervaded by a 'whatever works' mentality that almost celebrates mediocrity. The standards of Ruby programmers will be pulled down to some extent if it truly takes the place of PHP as the language of choice for people who are learning how to program on the web, but I don't believe that drop need be substantive or cause for much concern. Cultural expectations are important in regulating behaviour in any group and the expectations I've always seen in the Ruby community are for elegance above almost all things. That's a good place to start someone programming.

For context, my programming experience is: HTML (1995 to present), JavaScript (1998 to 1999, 2012 to present), PHP (2000 to 2006), Java (2001 - 2003), C (2002), Ruby (2006 to present).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment