Intersting post on Perl 6 type subsets and multiple dispatch

I recently read a blog post by Alex Miller about Clojure multi-methods.

It described and answered a question his friend had asked him, as well as discussing some related problems. I'm going to showcase the different options Perl 6 provides for solving these same problems. Here's the initial question:

Is it possible to write a multimethod that has defmethods which handle ranges of values? For example, say that a person has an age. Can I write a multimethod that accepts a person as a parameter and returns "child" if age < 16, "adult" if 16 <= age < 66 and "senior" if age >= 66?

As in Clojure, the answer is "Sure." In keeping with TIMTOWDI, Perl 6 provides several ways to do this.

This post does a rather good job of covering some of the new features in Perl 6 in a very readable way.

Interesting blog post on the Oracle Google thing by Charles Nutter

As you've probably heard by now, Oracle has decided to file suit against Google, claiming multiple counts of infringement against Java or JVM patents and copyrights they acquired when they assimilated Sun Microsystems this past year. Since I'm unlikely to keep my mouth shut about even trivial matters, something this big obviously requires at least a couple thousand words.

It's long, but he has some interesting thoughts and a decent amount of background that I wasn't necessarily aware of. It's nice that he lists all of the patents, too.

Anyone have recommendations for a good book on HTML/JS/CSS?

I've been deep in the bowels of the backend of web applications for years, but I haven't done anything on the frontend side in years. Since I acquired a webOS based phone, I'm finding that my biggest problem is not having a deep enough understanding of modern web development and how to get the layout I want. I also have ideas that I think might be fun to implement as web applications, but my lack of knowledge about the frontend technology is a problem. Does anyone know of a good book on the topic? Not a nutshell reference, but more in the vein of things like "The C Programming Language" or "Programming Perl".

Tail Call Optimization Decorator in Python

This function decorates a function with tail call optimization. It does this by throwing an exception if it is it's own grandparent, and catching such exceptions to fake the tail call optimization.

Sometimes I wonder why a whole bunch of Scheme loving folks use Python. Then, I see rather clever things like this, and it starts to make more sense. I do wonder how much of a performance penalty something like this incurs, though.

Fun with constants in Java

The following code does not compile:

public class A {    public static void main(String[] args) {        int i = Integer.parseInt(args[0]);        switch (i) {            case X: System.out.println("ONE!"); break;            case Y: System.out.println("TWO!"); break;            default: System.out.println("ZERO!"); break;        }    }    public static final int X = B.getNumber("X");    public static final int Y = B.getNumber("Y");}class B {    public static int getNumber(String s) {        if (s.equals("X")) {            return 1;        }        else if (s.equals("Y")) {            return 2;        }        else {            return 0;        }    }}

The compile error is: constant expression required            case X: System.out.println("ONE!"); break;                 ^ constant expression required            case Y: System.out.println("TWO!"); break;                 ^2 errors

I think I'll leave explaining why as an exercise for the reader. (Or for a future post. ;-)

Rawr: JRuby application packaging tool

Rawr, a packaging and deployment tool, is all you'll ever need for your JRuby projects. With Rawr, a simple, pre-generated configuration file turns your code into an executable jar, a .exe for Windows, and a .app for OS X.

It's kinda like Shoes in that it gives you an exe for Windows, an app for OS X, and a jar that you can use everywhere else. Cool stuff.

JRuby lead developer expounds on useful JVM flags

I probably start up a JVM a thousand times a day. Test runs, benchmark runs, bug confirmation, API exploration, or running actual apps. And in many of these runs, I use various JVM switches to tweak performance or investigate runtime metrics. Here's a short list of my favorite JVM switches (note these are Hotspot/OpenJDK/SunJDK switches, and may or may not work on yours. Apple JVM is basically the same, so these work).

If you write any serious Java at all, I highly recommend that you click the link above and read his post. It is full of many amazing gems that I can see being really useful for optimizing and debugging Java applications.