6 ms·
Why teach with Ruby?
- steveklabnik 16y agoThis post was a lot of work, and I'd love to hear your thoughts, HN. Please tear me apart. :)
- michaelchisari 16y agoIt seems a lot of the "magic" with Ruby comes from Rails, and I would say that teaching a new language using a framework is probably going to be pretty overwhelming to any beginner. One thing I would worry about with Ruby as a teaching language is that the syntax is somewhat unique. I don't think this is a terrible thing, the basic structure is similar once you get past the syntax, but I think it can trip people up if it's their first language, and then they move on to Java/C++/Perl/Python/PHP which seem to follow more of a continuity. I think, from my experience, I actually think learning a couple different languages at once can be really advantageous. I pretty much learned Pascal, C and Assembly at the same time, working in the demoscene, and linking them all together. The important part of programming isn't the syntax, it's the structure and the concepts. You can always look in the manual for syntax, but structure and concepts are the hardest parts to grok. So maybe my suggestion is to have side-notes for the examples that say, "here's how you do this in PHP, here's how you do it in Java, here's a breakdown of the differences and similarities." On the other hand, I may be completely wrong, because I'm biased based on how I learned programming, and not everyone learns that way. With all that said, this is a pretty great piece.
- SlyShy 16y agoAs a TA for an intro to programming class taught using Java, I wish, wish, wish we were using Ruby instead. I spend 70% of my time teaching people Java's obtuse syntax, rather than teaching the underlying concepts. Once a programmer has developed the concepts, she can code in nearly any language, but she really has to learn the concepts. Ruby's syntax is straightforward enough that little kids get it down in days, so students can actually learn computer science rather than Java science.
- michaelchisari 16y agoI think the hallmark of any good teaching language is the ability to get up-and-running quickly, and Ruby (and PHP and Perl and Python and scripted languages in general) have that over Java, C++, and others. But I think it's important to compare and contrast languages for just that reason, so that when moving to a language which requires a lot of preparation before you can even echo "Hello, World", the student doesn't get frustrated.
- mike-cardwell 16y agoIt depends what you're learning. If all you're learning is to memorise blocks of code, then Ruby is probably easier to learn because there's less of it. If you're trying to learn what a programming language is actually doing, I don't think Java is any more difficult than Ruby. If anything, most Java code is a lot more clear about exactly what is going on. FWIW, I learnt and tutored Java at University and have recently been learning Ruby and Ruby on Rails for fun.
- michaelchisari 16y agoWe also can't underestimate how much of an effect being familiar with a certain style and syntax has an effect on our judgment of languages which break from that style. Since I started with Pascal and C++, and then branched to Perl and PHP, the first time I looked at Ruby code, it looked like gibberish. But Java and Google Go immediately looked very familiar to me. I've since learned Ruby better, and it's kind of come into focus, but I think that's definitely something to keep in mind when we're teaching programming to others.
- SlyShy 16y agoLearning what a programming language is actually doing is good, but arguably that is a different course than an intro to CS course. One big advantage Ruby has over Java is that irb is simply a snap to use.
- sigzero 16y agoI agree...it should the language and language only if you are teaching a beginners class.
- kenjackson 16y agoGood post, although I disagree with it :-) One thing that bugs me is the Hello World example. While I completely agree that the Ruby is example is far cleaner, the Java/C/C++/C# example doesn't add much confusion in my experience teaching intro programming. The concept of classes is often confusing, but setting aside the code isn't much of a mental challenge for any student I've met. It just feels like its the wrong place to have the discussion of magic. The places I see students get tripped up is with iterators, recursion, classes, byref, and metaprogramming. I think the standard ceremony vs convention concern that people in the blogosphere love to talk about is generally a non-issue for almost everyone except those people who like to blog about it. Show how those other issues are made simple, yet don't miss important facts, with Ruby (or whichever language you think is most effective) and you've made a powerful case (note, I think this is largely the argument as to why SICP is so well regarded as it did a decent job on most of those).
- steveklabnik 16y ago> The concept of classes is often confusing, but setting aside the code isn't much of a mental challenge for any student I've met. While I have little formal teaching experience, I hung around in the undergraduate lounge in school, which is where students came for help. I ended up helping a lot of non-majors with their first CS class, which was popular because it filled a general requirement for an Arts and Sciences degree. These two classes were in Java and in VB6, and they struggled with anything that wasn't near-rote application. They had trouble with the scoping of variables, they didn't know when to use functions appropriately... if you say 'what does x = 5 do?' they can answer, but they can't apply that to writing new programs. My friends who are TAing courses now have several students who end up turning in homework that doesn't even compile. Maybe students at your school are just smarter than mine, but a lot of people struggle here. > It just feels like its the wrong place to have the discussion of magic. It's true, I am conflating 'magic' slightly. I don't mean 'they can't properly metaprogram,' I mean it in the "any sufficiently advanced technology is indistinguishable from magic" sense. They struggle to apply what they see as magic incantations to new problems, because they don't have a solid foundation to work with.
- 16y ago
- happy4crazy 16y agoI've been teaching myself programming over the past six months or so, and I'm very glad that I started with Ruby. The syntax is clean, and I think it's awesome that Ruby's object model is so elegant. I agree that the magic parts are frustrating at first, but it's pretty neat that you can spend a couple weeks reading, e.g. Paolo Perrota's Metaprogramming Ruby, and then actually know how it works! In terms of conceptual and syntactic elegance, I personally prefer Ruby to, say, Python. I watched most of the videos for MIT's intro CS class (available on academicearth.org), which uses Python, and just never particularly enjoyed it. It just struck me as messier than Ruby. That said, I'm sure I should give Python another chance. But at the end of the day, I think the main advantage of Ruby over something like Java, at least as a teaching language, is that you get a REPL. My memory of complete-noob-hood is still fresh enough to say that being able to do interesting things in a REPL is HUUUGE. And even now that I've got a bit more programmatic maturity, I wouldn't have gotten nearly as far with Haskell as I have without GHCi. So... I wonder what it would be like to teach a class using Javascript? Marijn Haverbeke's book, Eloquent Javascript, is pretty awesome, and I bet you could teach a pretty sweet class using it in conjunction with something like Node (for its REPL, in addition to all its other webby goodness). Hmm...
- jablan 16y agoThanks for the post, and I completely agree. However, there is one thing about Ruby that could have been better, considering Ruby as a didactic language: TMTOWTDI (more than one way to do stuff) concept which Ruby borrowed from Perl: although it arguably helps with "the principle of the least surprise", I find it confusing when it comes to learning: multiple names for the same methods, {/} and begin/end block syntax, completely superfluous for keyword first come to mind, and even optional parantheses for method calls could be confusing, especially when they collide with operator priority. Slightly unusual syntax, comparing to the mainstream languages, shouldn't worry anyone, since 1) it's really not that different (we're a bit spoiled there, as languages are lately crafted to mimick each other as much as possible - to facilitate "brain drain" from rivaling camps) 2) the aim is not to "learn to make money by programming", but to learn to code 3) opinions here are highly biased, because we already learnt programming our way.
- binarysoul 16y agoI can't really ready your post because of the background. I'd recommend changing it
- jablan 16y agoI think that's a foreground, actually. :)
- stevelosh 16y agoSafari Reader (or the Chrome/FF extensions like it, or the readability bookmarklet) fix it nicely (and many other sites like it).
- steveklabnik 16y agoI will check into that. It's just a stock Tumblr theme, and my screen is usually dirty, so I didn't even notice! EDIT: just plain white now. Thanks! For anyone who is curious what he's talking about, the theme I'm using had this set as a fixed background: http://static.tumblr.com/nfoxfxu/r5fl3h6w1/bg.jpg http://static.tumblr.com/nfoxfxu/r5fl3h6w1/bg.jpg
- deleted 16y ago[deleted]
- jeremymcanally 16y agoThat's any language that has scoping. I think what you're searching for is something like using lambda {} that captures the outer scope. I used lambda actually to introduce some middle schoolers to capturing behavior in Ruby. It worked well.
- z0r 16y agoThe arguments are all very good, but I think I prefer Scheme as a first programming language just because the syntax is easy to teach and you can get to the good stuff much more quickly. Doesn't meet your 'real world' requirement though - although, I think a few months spent learning the basics in Scheme would make it easier to pick up subsequent languages rather than vice versa.
- steveklabnik 16y agoI think Scheme is a fine language, especially when paired with SICP. But I see it as being something that's more of the leap from intermediate to master than total-beginner to literate. I could certainly be wrong about this, however!
- horofox 16y agoRuby is awesome. Please don't compare it with java, that makes me so sad. Java is so bad, deal with it. The good thing about java is the JVM to use with another language like scala, clojure and so on. Being a programmer is actually funny, you can stay all your life using 10 frameworks to do something for web in java with a lot of lines of code and bugs and think you are so good(like I did), but you're actually so bad. I'm still trying to learn lisp and start doing some clojure too, can't wait!
- steveklabnik 16y ago> Please don't compare it with java, that makes me so sad. I only do because Java has been the go-to year one language for colleges for the past few years. I wouldn't even mention it otherwise. > I'm still trying to learn lisp and start doing some clojure too, can't wait! Enjoy! I don't have a ton of Clojure experience, but from what I've seen, it's pretty awesome.
- tel 16y agoUnrelated, but I often wonder why people insist on a program that prints a string to the screen as the universal best first program. It's very practical, but it's also so tangential to what programming is. Just delay compilation until the third week and you'll be able to start the dialogue at objects, "is a", "has a", actions, properties. This is the language we use to deal with the world already and though it's got funny syntax attached, it's not a foreign concept to anyone. Talk about the runtime system and it's expectations later. (Edit: I think this is also why a lot of people hate the IO monad in Haskell so much. Side effects are actually an advanced topic in pure FP so much of the literature on IO is based around flaky metaphors and "don't worry about how this works" just to get people printing things ASAP. If you just use the REPL and don't worry about implementing it then you can build up to understanding the interaction between IO and the RTS in a sensible way.)
- endtime 16y ago>Unrelated, but I often wonder why people insist on a program that prints a string to the screen as the universal best first program. It's very practical, but it's also so tangential to what programming is. The point is that the first step is getting your environment set up so that you can write[, compile,] and execute code. Printing a string is just a conveniently trivial program.
- tel 16y agoIt's true that that's the first step to programming as a craft, but it's hardly the first step to programming as a way of thinking, managing complexity, and building abstraction. That's like saying the first step to flying an airplane is turning the ignition. Yes, that's true, but without a firm idea of what's going to be happening after that point you're only going to hurt yourself by turning that key. It's something that comes to head when learning to fly a plane/program.
- Avshalom 16y agoIt's true that that's the first step to programming as a craft, but it's hardly the first step to programming as a way of thinking, managing complexity, and building abstraction. But programming is a craft, so how is the first step tangential.
- dusklight 16y agoI think Ruby is a beautiful language but you really got to consider it in the context that it was invented in. Matz originally created it kind of as a spiritual successor to Perl, and it's original incarnation was as an easy to write, easy to read, fun to use scripting language. Rails came along later, I don't think anyone was really expecting it before it showed up, and it changed the Ruby conversation entirely. Ruby is excellent in many ways but I feel like Matz never took into account what is needed for a group of programmers to work on the same code base. I don't want to say he completely dropped the ball or anything like that but stuff like monkey patching and other shenanigans that make life easier if you are the sole programmer working on a code base become problematic if you are working in a largish team where not everyone might know everything that is going on. What I am trying to say is, IMHO Ruby "feels" like it is a good language to teach in, but you can end up using it for a really long time without acquiring programming discipline and fundamentals. If you start in C, for example, and you have to mess with malloc and pointers and stuff like that, you are forced to get that discipline, because otherwise stuff goes south really fast. Someone who starts in Ruby might never really understand the performance cost of initializing an object, or what the stack and heap is, or why it matters. I think it would be better for a new programmer to start out in C or even assembly for a little while, just to understand how a computer really works, then it becomes so much easier to understand why languages like Ruby and Python (and my personal favorite, Clojure) were created and how to use the abstractions that these more modern languages provide.
- macrael 16y agoPeople don't need to start in C. If we required that, there would be many fewer programmers. In University, our CS department got people started in Java (not the best starter language, but certainly cleaner than C) but our required OS course was in C. So, after being introduced to programming in a somewhat simpler form, you were required to spend a semester writing big projects in C, and you learned about pointers and memory allocation really fast. So, I agree that programmers should learn more about how these machines really work if they want to write good code, but I'm not convinced people should have to start at that level. Doing so would unnecessarily discourage people from learning to program. Imagine suggesting that everyone should learn to start programming in assembly. I think that's an analogous claim and is pretty silly. People starting to learn to program shouldn't be worrying about low level details or unnecessary syntax, they should be discovering the joy of creating programs.
- neovive 16y agoI'd like to highlight your mention of Scratch. I agree that Ruby is an excellent language for introducing older students to programming, but Scratch is truly exceptional for younger students. Scratch excels at introducing fundamental programming concepts,while hiding syntax and language subtleties for beginners. The puzzle/block metaphor of Scratch really works for "building" a fully-functional program. For those that have never worked with Scratch, the underlying Squeak(Smalltalk) implementation is completely hidden. I guess the choice of language really comes down to the audience and age group. It's unlikely that colleges will ever utilize Scratch in their introduction to programming courses, thus Ruby is an excellent choice. But elementary and middle school students would benefit greatly from learning programming concepts such as logic, control structures, iteration, etc. from a tool like Scratch.
- jrheard 16y agoBackground/disclaimer: I learned Ruby first (largely thanks to _why's guide), but have been using Python at my job and in my personal projects for about a year and a half now, and have grown to prefer Python. The main gripe that I have with using Ruby as a teaching language is that the whole magic thing. You address this really well, and I really like your passage on abstractions, but I don't agree that the magic is just limited to advanced usage of the language. Here's my gripe in its most pure form: in Python, in order to figure out all of my capabilities right now (short of what things I can import), I can use dir(object_i_want_to_know_about) and see everything that object can do. I've got a friend who's learning Ruby, and we wanted to find a built-in String method to see if a string starts with a prefix. We found it after Googling, but I wanted to find out about it in the context of the REPL. I figured that Ruby must have similar functionality to Python's dir(), but as far as I can tell, the only way to achieve that is to hack the REPL in a very minor way (you can add a few lines to your .irbc that will achieve this). There doesn't seem to be anything like dir() built into the language, and so it's a lot harder to figure out what you can do at any given point in time without Googling. I think that this difference speaks volumes about the difference in philosophies between the two languages, and is in large part why when I introduce friends to programming these days, I tend to do it via Python, in particular via Zed's book. I haven't used Ruby much in the past year or two, though, so if I'm completely mistaken about my assertions here, I'd love to find out about ways in which I can reason about the options available to me when I'm hacking around in irb. PS: I really liked the code example near the end of the article.
- gmac 16y agoI figured that Ruby must have similar functionality to Python's dir() Sounds like you wanted 'x'.methods => [:<=>, :==, :===, :eql?, :hash, :casecmp, ... ] or the more focused 'x'.methods - Object.methods => [:casecmp, :+, :*, :%, :[], ... ] ?
- jrheard 16y agoYup - that's exactly what I was looking for. Awesome.
- poink 16y agoI make a living with Ruby and Rails, but I'd stick with JavaScript if I were learning today. Server-side JS is a LOT of fun.