Justin starts a blog RSS

Hacks, gripes and insights from someone behind the curtain.

Stuff I've made
cobosoda - Evolve virtual robots
termlauncher - pwn leopard's terminal

Archive

May
24th
Sat
permalink

Java got no soul

Hackin’ on cobosoda today. Writing a class named SexualReproduction right now, which is kind of fun. I wish java would let me do things like combine non-booleans with logical operators. Where I could write in perl:

sub get_number_of_parents {
    my $self = shift;

    return ($self->{mom} && $self->{dad} && 2) ||
        (($self->{mom} || $self->{data}) && 1) ||
        0;
}
In Java I must write:
public int getNumberOfParents() {
    if (mom != null && dad != null)
        return 2;
    else if (mom != null || dad != null) 
        return 1;
    else
        return 0; 
}
It probably makes more sense to third parties that way, but personally I dig a good short circuit.
Comments (View)
blog comments powered by Disqus