Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Ruby and perl are quite alike, so I'll pick out a couple of differences that I find interesting.

One of the most important design decisions in ruby is that everything is an object and practically everything you can do with those objects is implemented as a method call, in fact, a lot of the functionality that in perl is implemented as operators and functions are just method calls in ruby:

container.each { |element| # do something with element }

Is more or less equivalent with

foreach my $element (@container) { # o something with $element }

Except that every container can decide how to implement its each method, which means you can keep the ruby code exactly the same if you decide to switch from a standard array to another implementation (like requesting records from a database, or reading lines from a filehandle etc etc) *)

Compared to perl, ruby makes extensive use of polymorphism, and less auto-conversion of objects. For instance, a "+" operator will concatenate strings and add numbers in ruby **) while in perl "+" will convert strings to numbers and add them - this is one of the reasons perl has so many operators: since they force conversions on their operands, you need "+" and ".", "*" and "x" etc. This difference will be even more apparant in perl 6.

One of the advantages of doing it the way perl does, is that it takes less typing; you almost never have to explicitly convert from strings to numbers or back. One of the advantages of doing it the way ruby does, is that it keeps the basic language simpler (less operators) and if the API is good it can make it easier to inject your own object types into existing code/library calls. Also IMHO ruby's way scales better. See the container.each example above.

Also, ruby has stable, light-weight multithreading compared to perl. This is, at the moment, my biggest reason for using ruby instead of perl for some programs - you can quite easily run a program with 200+ threads in ruby, while in perl, using 200 threads or forking 200 sub-processes tends to slow things down too much.

If you want to know more, I suggest you get a good book on ruby; I like the pickaxe book. I have the second edition in paper, but the first edition is also freely available online.

*) Yes, you can tie an object to an array in perl, but that's not quite the same thing.
**) Note that in ruby, 1 + "a" is an error.


In reply to Re: Perl/Ruby comparison by Joost
in thread Perl/Ruby comparison by srdst13

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-26 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found