First off, the facts:
Similarity
Differences
- RubyLanguage is a pure ObjectOrientedProgrammingLanguage, Perl5 is less OO (but Perl 6 is coming with very good OO support).
- Both languages slightly resemble CeeLanguage, while Ruby borrows a little from SmalltalkLanguage too.
- Ruby is the newer of the two, having been released in 1994, while PerlLanguage was initially released in 1987.
- There are many more Perl users than Ruby users.
- Perl has more third-party libraries than Ruby.
- Perl uses sigils such as @, $ and % to denote variable type, and Ruby uses sigils such as @, @@, and $ to denote scope. By default, all variables in Perl require a sigil, and variables in Ruby in the most local scope don't.
- Perl has multiple variable types (scalar (a "single thing", capable of holding a string, a number, or a reference), array, hash). Ruby has one variable type: reference to object (the object can act like an array, hash, or whatever). Dereferencing references in Perl requires a specific syntax; in Ruby the dereferencing is automatic and transparent.
- Perl automatically converts strings to numbers and numbers to strings, depending on context. Perl can do this because it has different operators for numbers and strings; for example, "." for string concatenation and "+" for numeric addition. Ruby, on the other hand, doesn't auto-convert types, leaving it to the programmer to convert types explicitly (".to_i", ".to_f", and ".to_s"). This allows Ruby to overload operators cleanly; for example, using "+" for both string concatenation and numeric addition. Some methods also implicitly convert types (e.g., to_i, to_f, to_s as necessary).
- That's not necessarily a good thing. + is plus, and . is concat. 34 . 56 == 3456.
- Of course 34.to_s + 56.to_s == 3456 also, so this is merely a matter of coding style, not an advantage or a disadvantage.
- Perl5's syntax for defining objects is unnatural and difficult (to be kind about it). Ruby's syntax is natural and simple. Main reason for that is that Perl was originally not designed to be Object Oriented - OO was added on top of Perl4 - adding radically new concepts to a language is BAD!
- Unless somebody does not believe in heavy OOP and likes the way the language is for non-OOP stuff.
- Ruby has first class continuations (ContinuationExplanation). Perl doesn't.
- Perl 6 and Parrot will have continuations, while Ruby 2.0 will not.
- Perl has GoTo and MagicGoto (useful for faking TailCallOptimization). Ruby doesn't.
RubyLanguage has some superficial similarities to
PerlLanguage, but they have less in common than most casual observers would think. Parts of the regular expression handling is the same, but that's about it.
Ruby is not similar to PascalLanguage other than the use of the "end" keyword. It is more similar to SmallTalk. (-- AustinZiegler?)
Apart from the curly brackets, is Perl anything like
CeeLanguage?
Of course it is! For example: constructs like "for", "while" and "if", attribution ("="), +=, ternary operator (?:), printf, sprintf
Ruby uses a full PCRE library for regexes, so that part is virtually the same. I think Ruby
is similar to Perl, but only in a broad philosophical sense. There's more than one way to do it; easy things should be easy, complex things should be possible, all that jazz. Ruby was written to meet pragmatic constraints, as was Perl. (
YukihiroMatsumoto focused on weeding out ugly little inconsistencies and misfeatures as well;
LarryWall was not so concerned with this.)
Among many differences are: a much better object system and much better functionals (being stuck with $_ is damned ugly IMO)...I write a lot of Perl code and practically think in it, but Ruby is still way easier for me to read. --
TheerasakPhotha
I would say that Ruby and Perl share a philosophy more than they do features:
ThereIsMoreThanOneWayToDoIt. For instance, to print things, you have print, p, puts, $stdout <<, etc. That these all have subtle distinctions only emphasizes the link to Perl. Ruby and
PythonLanguage, on the other hand, have many similar features, but Python is much more focused on providing one mainstream way to do things.
After a bit of a look I got the feeling the
RubyLanguage is the result of crossing
PerlLanguage with
SmalltalkLanguage. --
DavidPlumpton
This has been my opinion since day one. Ruby = Smalltalk + Hentai Tentacles (a.k.a. Perl)
My description of Ruby has always been: Smalltalk with enough syntactic sugar that you can make it look like Perl. --
RobertFisher
After prolonged use, I got the feeling that Ruby has little to do with
PerlLanguage, save the superficial "scripting language" comparisons listed up top. --
JamesBritt
See
http://www.rubygarden.org/faq/entry/show/14 for a list of what
RubyLanguage lifted from Perl. (It's halfway down the page)
I also got that feeling (after a few months with Ruby). Now that I have looked at SmalltalkLanguage, Ruby feels more like a re-implementation of Smalltalk with Algol-like syntax, file/edit/command-line environment instead of the IDE, and a bunch of Perl functionality thrown in as libraries (RegularExpressions, etc).
That's what I think really 'killed' Smalltalk... the VM/VI model offers a number of interesting advantages, but in a practical sense, it can be very prohibitive. Similar logic explains why the
VonNeumann architecture won out over technically sophisticated devices like the
LispMachine. (Disclaimer: this is not a knock on either Lisp or Smalltalk; in all honesty, I strongly admire those two and use SBCL under SLIME.) --
TheerasakPhotha
With rubyisms.pm (available from
TheCpan), ruby-style blocks are available in perl. By no means does this equate to feature parity, but the style is available at least.
See also
ScriptingLanguage
CategoryProgrammingLanguageComparisons CategoryComparisons