Ruby is from objects, Perl is from procedures
Perl has had objects for quite a while now, decades even, but you can’t get away from the fact that OO is really just a bag-on-the-side of Perl 5. This can be a Good Thing sometimes, actually, because it means that well-written code can be used objectively or functionally.
Still, though, Perl 5 is fundamentally not OO at it’s core and all the magic exists in bless(). Ruby (and many others, too many to mention) are object oriented from the ground up. But what does that really mean?
This is the first part of what I hope will be a pretty useful set of tutorials for those moving from the world of Perl in to Ruby. For the overview of topic I hope to cover in this series you can go back and look at the “Overview” page. In this first part I want first to talk about how Perl and Ruby are similar and then go over some of the most visible differences.
I originally gave a presentation with this same title at the February 2012 ut.rb meeting. Although it was focused at the Perl programmers that were present at that meeting it was so well received I’ve decided to spend more time on it an develop it in to a series of blog posts.
Of course this is meant to give Perl programmers a foothold in a new language but it is also useful for anyone coming in to the language from somewhere else.
My Perl credentials
I started developing in Perl in 2000 and was a full-time Perlista from 2000-’07 using versions 5.005 to 5.6, but I’ve never used the Perl 6 series. My first gig was doing financial code for a credit-card processing company, then I moved on to start a web site (Quizilla.com) that eventually went to many tens-of-millions of daily page views on Perl code I wrote.
Overview of what’s on tap
In this series I plan on covering:
- Part 1: basic similarities and shared conventions. Differences between use of semicolons, and parenthesis.
- Part 2: Bagging on Perl’s OO system. Objects and methods under Ruby. Symbols.
- Part 3: Perl sigils counterparts in Ruby. New meaning of $, @ and @@. Constants in Ruby.
- Part 4: String interpolation, deliberate/implicit returns on methods.
- Part 5: Bang (!) and Boolean (?) methods.
- Part 6: blocks (very basically).
- Part 7: bonus Rails-specific content: method_missing() and “magic methods”.