A Newbie's First Impression of Ruby
I just realized that this post title rhymes. Sorry about that.
I am reading Beginning Ruby: From Novice to Professional by Peter Cooper to introduce me to the language. It definitely lives up to its title! So far, I’m coming out of each chapter with an actual understanding of what I just read… even if I have to read it more than once.
The best part is seeing the vast amount of code that is absent in the language. When I was learning Java and Actionscript 3, the syntax for classes, methods, and instances was so daunting. You need to write so much just to set up one instance of a class. In Ruby, this Actionscript:
[as3]public class Person {
public var firstname:String = new String();
public var lastname:String = new String();
}
var aliso:Person = new Person();[/as3]
becomes this:
[ruby]def Person
attr_accessor :firstname, :lastname
end
aliso = Person.new[/ruby]
It’s much less code. It makes so much more sense to write it this way! A core principle in Ruby is DRY, or Don’t Repeat Yourself. It’s wonderful. It makes me think, “Is Actionscript 3 so stupid that it needs to know aliso is a variable and a Person before I instantiate it as a new Person variable?”
I was able to build an application (worked through in the book, of course) that took the text from any specified text file and analyzed it—counting words, sentences, paragraphs, the amount of “useful” sentences, and even writing a summary using that information. I built it in one Ruby file, with just a couple dozen lines of code. It was fantastic!
That’s it for now. My first impression of Ruby is most definitely a great one.
