I am often asked – “what is the best computer programming language to learn?” And for years the reflex response was Ruby. Ruby is elegant, Ruby is easy to understand, it’s creative, it’s expressive, it’s powerful, flexible, and robust. Ruby is enjoyable to work with, and is applicable both as a first programming language to learn, and scales well for enterprise level development. Ruby should be taught in schools.
But why? If I had to summarize this into a single point, it would be: IRB – Interactive Ruby Shell. Run through a shell (a command prompt for those using Windows), IRB interprets the syntax as it is typed in, one line at a time, and displays output as soon as there is any.
This creates a Ruby playground of sorts, and I can’t think of a better way to prompt learning than letting students play around with their objects, methods, and code blocks. All too often I’ve seen students get really frustrated trying to get their entire program to compile and work as a whole, right away. Lacking experience to debug through a screen full of code, it is often discouraging to explore the language, fearing more bugs and unknowns. As Ruby’s interpreter will execute one block at a time, and often as little as a single line of code – mistakes become apparent. Suddenly the problems are narrowed down from “my program doesn’t work” to “the line I’ve just entered doesn’t work”.
What I like the best in terms of learning with this programming language, is that everything is an object, and when asked – it will describe itself. What it is, what methods it has. Best of all one doesn’t need to set up and compile a whole program just to confirm that 42 is indeed an instance of a Fixnum class – instant interactivity is the key.
Though that’s over 100 methods that can be performed on a static number, other classes have even more options. I’d think that a MethodFinder will be a selling point to a lot of students. Knowing what you start off with, and what you want to end up with as a result, this cleaver call will suggest all the available methods that will get you there!
gem install what_methods
Knowing that “hello” is 5 letters long, the methods list is crunched down to just “size” and “length” – both produce the desired result. This is simply amazing for students starting out, as they could now concentrate on understanding the concepts of operations, and be reminded of the proper syntax when needed.
Ruby is helpful and interactive. It encourages students to try things out, and explore the programming language on their own. One of the themes that came up in Keeping students interested in Computer Science was a requirement for engaging examples. Loading various classes into this Ruby playground would quite literally put students into a role of a Matrix master, having complete control over every object in their virtual domain. Programming is art, and it is best learned through practice of logical expression of creative thoughts.
I think that Ruby makes an excellent choice for a first programming language to be taught. How does it compare to what you’ve learned first?