Java 5 ; object persistence

May 07, 2007 17:03

I'm pleased about the Tetrad code being in Java 5, which really is a slightly different language. Java 5 has two nice features:

* nicer 'for' loops (++), such as:

for (int sampleSize : new int[]{1000, 10000}){ ... }

* Parametric types, which avoids all that unnecessary casting that Java is notorious for (+):

List nodes = dag.getNodes();
Node node0 = nodes.get(0);

Combined, we can now do:

for (Node node : dag.getNodes()) { ... }
instead of

for (int i=0; i < dag.getnodes().size(); i++) {
Node node = dag.getnodes().get(i);
...
}

(although this translation would probably break if you remove an element from the list inside this loop without decrementing i)

-----------------

Sometimes, after your program has finished execution, you notice that some object (e.g. a graph) had a really interesting property... or, if the program is non-deterministic, and you notice a bug, you may want to run the same example again for debugging purposes (or the entire state of the program, if that were possible).

Unfortunately, the object is now gone, and all you have is its footprints. By the time you think of putting Object.serialize() in the code, it's too late: you have to pray that you'll run into that situation again.

What do you do?

programming

Previous post Next post
Up