Language Comparisons

Comparisons of programming languages, usually Ruby and something else.
  • 13


    Erlang Message Passing

    Like many Pragmatic Programmer fans, I've been having a look at Erlang recently by working my way through Programming Erlang. In the book, the author includes a challenge: build a message ring of processes of size M and send a message around the ring N times, timing how long this takes. The author also suggests doing this in other languages and comparing the results. Having now done this, I can tell you that it is an interesting exercise.

    First, the Erlang results. Here's a sample run that creates 30,000 processes and sends a message around that ring 1,000 times:

    $ erl -noshell -s solution start 30000 1000
    Creating 30000 processes (32768 allowed)...
    Timer started.
    Sending a message around the ring 1000 times...
    Done:  success
    Time in seconds:  29

    So we see about 30,000,000 message passes there in roughly 30 seconds. I should also note that Erlang creates those processes very, very fast. It's possible to raise the process limit shown there, but I'm more interested in comparing what these languages can do out of the box.

    Read more…

  • 29


    YARV Looking Promising, James's C is Not

    I participated in the ICFP programming contest last weekend with a group of friends. We had a great time with the event and learned a ton. I thought I should share two interesting insights with others that might appreciate them.

    First, YARV looks very promising for some general speed increases in Ruby. If you are not familiar with YARV, that's the virtual machine that will run Ruby 1.9. During the contest, we ran into some performance issues with our Ruby solution and after we had optimized all we could think of, we decided to try running our entry on the experimental YARV VM to see if it was faster there. Good news: it was a lot faster.

    Please do not take these numbers as anything more than very non-scientific observations, but we did notice a huge speed increase on YARV. We were reliably waiting around 15 minutes for one section of our program to run on Ruby 1.8.4, but when we introduced YARV the same section generally ran in just under seven minutes. You heard me right there, it was over twice as fast. I think that's very promising news for the future of Ruby.

    Read more…

  • 21


    The Why and How of Iterators

    A friend of mine has been asking some general questions about iterators in private emails we have traded. I wanted to put some of my answers here, in case they appeal to a wider audience.

    Why do we have iterators?

    First, let's invent a little data to play with:

    >> Name =, :last)
    => Name
    >> names = ["James", "Gray"),
    ?> "Dana", "Gray"),
    ?> "Caleb", "Nordloh"),
    ?> "Tina", "Nordloh") ]
    => [#<struct Name first="James", last="Gray">,
        #<struct Name first="Dana", last="Gray">,
        #<struct Name first="Caleb", last="Nordloh">,
        #<struct Name first="Tina", last="Nordloh">]

    Now let's assume we want to print some names. We can use the each() iterator for that, no index:

    >> names.each { |name| puts "#{name.last}, #{name.first}" }
    Gray, James
    Gray, Dana
    Nordloh, Caleb
    Nordloh, Tina
    => [#<struct Name first="James", last="Gray">,
        #<struct Name first="Dana", last="Gray">,
        #<struct Name first="Caleb", last="Nordloh">,
        #<struct Name first="Tina", last="Nordloh">]

    Read more…

  • 10


    Java a Bit on the Wordy Side

    I was helping a friend of mine with a Java problem yesterday and couldn't help but notice this totally normal (for Java) file in his project:

    public class Contact implements Serializable
       private String firstName;
       private String lastName;
       private String email;
       private String phone;
       public Contact()
           this("", "", "", ""); // call four-argument constructor
       } // end no-argument Contact constructor
       // initialize a record
       public Contact(String first, String last, String eml, String phn)
       } // end four-argument Contact constructor
       // set first name
       public void setFirstName(String first)
          firstName = first;
       } // end method setFirstName
       // get first name
       public String getFirstName()
          return firstName;
       } // end method getFirstName
       // set last name
       public void setLastName(String last)
          lastName = last;
       } // end method setLastName
       // get last name
       public String getLastName()
          return lastName;
       } // end method getLastName
       // set email address
       public void setEmail(String eml)
          email = eml;
       } // end method setEmail
       // get email address
       public String getEmail()
          return email;
       } // end method getEmail
       // set phone number
       public void setPhone(String phn)
          phone = phn;
       } // end method setPhone
       // get phone
       public String getPhone()
          return phone;
       } // end method getPhone
    } // end class Contacts

    Read more…