rc3.org

Strong opinions, weakly held

The Ruby way versus the Java way

James Roberston has a good post summaring a debate between competing philosophies of language design. The subject is Java’s java.util.List versus Ruby’s Array class. Refactoring guru Martin Fowler argues that Ruby’s version is better because it includes bunches of convenience methods, and Elliotte Rusty Harold argues the converse, that fewer methods is better.

My contribution to this debate is to say that I was hacking on some Java code last night and found myself wishing that Java’s List class had methods for grabbing the first and last elements in the list. To me, the convenience methods make your code much more readable. In the Java world in particular, everybody uses editors that auto-complete method names anyway, so it’s not as though we need to memorize all of the public methods of every class we use in the first place.

2 Comments

  1. what’s wrong with:

    Object first = myList.get(0);
    if (myList.size() > 0)
    Object last = myList.get(myList.size() - 1);
    

    I’d say that any comparison based on “methods in the classlibrary” is purely artificial. PHP’s totally botched “identity”-concept that makes for 3(!!!) incompatible versions of PHP plus its unbelievably sad unicode support is a REAL reason to throw that toy-language out the window if you don’t have a particularly big investment in it.

    After that it’s about finding the right tool for the job at hand, not finding the right hammer to pound on screws.

  2. I agree with Harold. Java classes are tougher to learn because they are packed with so many convenience methods. I use his XOM library all the time to parse XML, and it’s so much easier to know the classes well because the number of methods is so small. Knowing the classes well results in better programming.

Leave a Reply

Your email address will not be published.

*

© 2024 rc3.org

Theme by Anders NorenUp ↑