So I’ve been learning Ruby and Rails for about a week, after avoiding it for years solely because of the ridiculous hype. Well, now I’ve learned my lesson.1 After a week, I’ve built three fairly function web applications, and one of them is basically a Ruby version of something that I’ve been working on for months.
No kidding.
Lately, I’ve been toying with the idea of teaching programming again, and I actually think I may teach Ruby.
Yeah. Doesn’t that sound like the nonsensical ravings of a lunatic mind?!
Back in Charleston in a former life, I taught Introduction to Programming courses through community education. Recently, I’ve noticed that there are not any practical programming classes offered through Hood River County, so I decided to ping the powers that be and ask if they’d be interested.
Now, the non-programmers (and some of the programmers) might ask “Why would you teach in Ruby if you don’t know it?”
In a word: Fundamentals.
The greatest tool that any programmer has is a strong grasp of the fundamental principles, and there is no better way to learn those fundamental principles than teach them.
Sound counter-intuitive? It’s not. I started teaching at the 8th grade level, and let me tell you, if you can distill a complex topic down to an 8th grade understanding, then you actually understand that topic.
Programming Fundamentals
One type is programming fundamentals. You will not get too far if you don’t know the basic fundamentals of programming. These are things that programmers don’t even think about anymore, like how to count. We all think we know how to count, but a programmer counts starting at 0. 1 is the second number. Fundamental, but it’s something that takes getting used to.
When I taught programming, the majority of the introductory course were not at all about “how to program.” Those courses were most certainly about “how to think like a programmer.” The language is almost ancillary, because half the time you’re not even using it anyway.
Language Fundamentals
Another type is language fundamentals. These are the fundamental tools and syntax guidelines that a language has, and the differences between languages are somewhere between subtle and drastic. Consider:
# in Python:
a, b = 0, 1
if (a): print("A")
if (b): print("B")
Any person who has programmed in Python for more than 34 seconds knows what the result of this code would be. The script sets the variable “a” equal to zero and the variable “b” equal to one. Then it asks whether “a” and “b” are True and prints if so. It will not print “A” because the number zero evaluates to false. It will print “B,” however, because the number 1 (or any other positive integer) evaluates to false.
This is a linguistic fundamental in Python. Zero equals false, one equals true.
Contrast that with:
# in Ruby: a, b = 0, 1 puts "A" if a puts "B" if b
One thing that was interesting to me when looking at Ruby for the first time is that this script prints both “A” and “B!” So, in Ruby, zero is true. This is a very subtle (can I say “drastically subtle?”), but important difference, between these languages.
Each language has its idiosyncrasies, and learning the fundamental features of any language is the bread and butter of a programmer.
Teaching such early introductory programming is more a matter of teaching these fundamentals than teaching what one knows from long-term exposure to a language.
Teaching Fundamentals
When I was teaching, I knew a lot of people who were good at finding libraries to do really complex things, but who didn’t really understand the difference between, say, class and instance variables. This is dangerous. It’s easy to say “let’s build something complex right away” and then get blindsided by things that you never took the time to learn– like a bug introduced because you didn’t realize that zero equals true.
Fundamentals are everything, and the most important thing to teach, especially at the early stages, are the power of these fundamentals. The most important thing to teach is not how to program, but how to think like a programmer.
Learning Fundamentals
Teach a person how to type a tutorial, and they learn how to type a tutorial. Teach a person how to write a tutorial and… well, maybe the analogy doesn’t work that well, but you get the picture.
I think I learned more about Python teaching it than my students did. In fact, I’m sure of it. Why?
Here’s an example
str = "This is a string" print(str[0]) # prints "T" print(str[0:3]) # prints "Thi" print(str[-1]) # prints "g"
Simple slicing was a class I had. Every string is, basically, an array, and every array can be sliced. In the first example, it prints the zeroth (first in your inexpressive human tongue) element, which is “T.” In the second, it prints the zeroth to (i.e. not including) the third element. The last example prints the last element. Negative one symbolizes starting at the end and working backward.
When I taught this, a student (an 8th grader, by the way) asked “Why isn’t it negative zero?”
Uh… shit.
I had no idea!
I didn’t know, because I never really thought about it. I just read the Python tutorial and had been using that syntax ever since. Luckily, I was honest enough to say “I never thought about that” and we worked through why (hint: it makes an elegant sense). That is language understanding. That is fundamental knowledge that gives you power later on that is far beyond merely copying other code, using libraries, and reading books.
That student thought like a programmer.
At the same time, I learned something more about how to think like a Python programmer.
Coda
So, we’ll see how things go– we’ll see whether the community ed department wants an intro programming class.2 If they do, I’m seriously considering teaching it in Ruby instead of Python. It’s just a really great language: clean, simple, and fun.
It’s also one in which I would love to learn more fundamentals.
I’d be using a fairly small amount of Ruby to teach a class how to think like a programmer.
Meanwhile, I’d be learning a heck of a lot about how to think like a Ruby programmer.


