Sunday, August 12, 2012

Wednesday, August 01, 2012

Typing more to type less

My code is littered with bits like this:

import com.google.common.collect.UnmodifiableIterator;

public final class TimesIterable
        implements Iterable<Integer> {
    private final int n;

    public static Iterable<Integer> upTo(final int n) {
        return new TimesIterable(n);
    }

    public TimesIterable(final int n) {
        this.n = n;
    }

    @Override
    public Iterator<Integer> iterator() {
        return new UnmodifiableIterator<Integer>() {
            private int i = 0;

            @Override
            public boolean hasNext() {
                return i < n;
            }

            @Override
            public Integer next() {
                return ++i;
            }
        };
    }
}

All so I can write:

import static TimesIterable.upto;
import static java.lang.System.out;

public static void main(final String... args) {
    for (int n : upTo(4))
        out.println(n);
}

To my surprise Google is not quite there yet. (I'd prefer to be wrong).

Zing zings

Azul's Zing remains amazing technology:

Where a typical JVM may spend time battling with garbage collection, McCandless says an in-memory test with the full Wikipedia English-language site loaded worked with no garbage collection pauses under Zing JVM, even with a 140GB heap.

Now free for open source.