Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Thursday September 10, 2009
09:50 AM

Java Tutorial Fail

[ #39610 ]

So I came back from two weeks in the US to find that I'm now a Java programmer. Not having seriously programmed in Java since 1.4 (pre Tiger, or pre 5.0, depending on how you count), I decided to brush up my basics. Working through Sun's Java tutorial, I came across this delightful code:

public class Rectangle {
    private int x, y;
    private int width, height;

    public Rectangle() {
        this(0, 0, 0, 0);
    }
    public Rectangle(int width, int height) {
        this(0, 0, width, height);
    }
    public Rectangle(int x, int y, int width, int height) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
    }
    ...
}

OK, I can understand multiple constructors. I'm OK with method overloading (wish we had it in Perl), but switching the order of arguments?

Rectangle rec1 = new Rectangle(4,5,0,0);
Rectangle rec2 = new Rectangle(4,5);

It would have been trivial to make those equivalent, but since the tutorial doesn't show extending the arguments, they're not equivalent. Nice job showing new programmers bad code, Sun!

Side note: I'm going to be in Java-land for a while because we're creating a new service which requires the domain knowledge that I and another programmer have, but due to internal requirements, must be written in Java. Thus, we have two Java devs on loan who will build the system and I'll be pairing with them and our team will take over maintenance after they leave. Should be interesting to see how this works out.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • /me wonders if you can prototype in Perl and then convert to Java. :-)

  • I think you'll find that this is suitably frowned upon in Josh Bloch's Effective Java [infoq.com]. If you don't have a copy around, I'd really recommend picking up a copy if you're going to be coding Java at all.

    You might also like his Java Puzzlers [javapuzzlers.com], which is entertaining if less essential reading.

    And why not look into Scala [scala-lang.org] whilst you're on the JVM? I find it very Perlish in many ways. :)

  • Anyone who is a competent Perl OO programmer can knock out Java classes with a little help from IDEA and/or Eclipse.

  • Personally I would prefer to use Perl6 parameters for this with a little bit of type checking thrown in:

    Rectangle(Int $x = 0, Int $y = 0, Int $width = 0, Int $height = 0)

    You can always use Perl6::Subs;