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.
/me wonders if you can prototype in Perl and then convert to Java.
Re:Universal translator?
Ovid on 2009-09-10T16:10:48
Absolutely not possible except in all of the simplest of cases
:) However, I did once write a vim filter to translate Java to Perl
:P
You might also like his Java Puzzlers, which is entertaining if less essential reading.
And why not look into Scala 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.