Hacker News new | past | comments | ask | show | jobs | submit login

Where was the substance to the post? The post she linked to was far more interesting:

https://netguru.co/blog/posts/brace-no-more-going-from-java-...




That article raised a frown with me. It presents some Java code, then shows the Ruby version, which ends up being much more concise. But the Java code is needlessly verbose. Here's how i'd arrange it:

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Gallery)) return false;
        Gallery other = (Gallery) object;
        return (this.gid != null || other.gid == null) && (this.gid == null || this.gid.equals(other.gid));
    }
Apart from the cast, which you need because Java has static types and Ruby doesn't, it's the same length. It's basically the same code, token for token.

Actually, the logical structure of the final line is a bit obscure to me; i'd write it:

        return this.gid != null ? this.gid.equals(other.gid) : other.gid == null;
Or, in Java 7 or later:

        return Objects.equals(this.gid, other.gid);




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: