jueves, agosto 20, 2009

The water is wet.

I've heard is a bad idea to start any post with "I'm sorry for not writing more often..." So I won't.

Were I live we usually say something like "he just discovered that the water is wet" when somebody makes a statement about something obvious. I'm just going to do exactly that.

I'm part of that unfortunate CS population that instead of receiving a wonderful introduction to programming with SICP had to deal with Java. Is really common to use Java for most of the courses that include projects. This semester I took this CG course so made the only choice I could. I chose to use Scala(1)

The good

I just translated the first simple Java3D example into Scala. And I mean, just plain translation of the code avoiding extra type annotations. Just not having to write all those types saves a lot of space! And I mean, this is what I'm talking about:

    val config = SimpleUniverse.getPreferredConfiguration();
val canvas3D = new Canvas3D(config);
this.add("Center", canvas3D);
val scene = createSceneGraph();
val simpleU = new SimpleUniverse(canvas3D);

    GraphicsConfiguration config = 
Canvas3D canvas3D = new Canvas3D(config);
this.add("Center", canvas3D);
BranchGroup scene = createSceneGraph();
SimpleUniverse simpleU = new SimpleUniverse(canvas3D);

I mean... this really counts if you think about not wasting columns as I do.

The bad

If you write something like:
    def createSceneGraph() = {
val objRoot = new BranchGroup();
objRoot.addChild(new ColorCube(.4));

But let's say you didn't write the "=", or made explicit the return type, or wrote the "return" keyword, or wrote it without curly braces. Or just make combinations of those.

In the best case you get a compiling error.
Sometimes it makes exactly what you want.
Sometimes it compiles... But with different semantics!

I would really prefer a concise way to write it and no alternatives. An F# kind-of light-syntax would be really nice.

(1): I could've used Groovy, Clojure or [write your jvm-based language here] too, but I prefer static typing.

No hay comentarios.: