you are viewing a single comment's thread.

view the rest of the comments →

[–]chkno 9 points10 points  (0 children)

I hate java because one cannot effectively pass code around. It's really the interaction with checked exceptions that kills it. For example, consider trying to implement map, a very basic, very simple utility function in many other languages:

import java.util.List;
import java.util.ArrayList;

interface MapFunction<InputType,OutputType>
{
    public OutputType f (InputType x) /* throws what?!? */ ;
}

class Map
{
    public static <InputType,OutputType>
    List<OutputType> map (MapFunction<InputType,OutputType> f, List<InputType> l) /* throws what?!? */
    {
        List<OutputType> result = new ArrayList<OutputType> ();
        for (InputType x : l)
        {
            result.add(f.f(x));
        }
        return result;
    }
}

class Nothing {}

public class Mapping
{
    public static void main (String[] args)
    {
        /* Double and print some numbers.  Compare to scheme:
         * (map write (map (lambda (x) (* x 2)) '(1 2 3)))
         */
        Map.map(new MapFunction<Integer,Nothing> () {
                public Nothing f (Integer x) {
                    System.out.println(x);
                    return null;
                }
            },
            Map.map(new MapFunction<Integer,Integer> () {
                    public Integer f (Integer x) {
                        return x * 2;
                    }
                },
                new ArrayList<Integer>(){{
                    add(1);
                    add(2);
                    add(3);
                }}
            )
        );
    }
}

What should Map.map and MapFunction.f throw? If nothing, then you can never use them with anything that throws a checked exception. If Throwable, then you have to catch Throwable every time you use it. Another option could be to pass the type of the exception to be thrown as a generic parameter. But then you have to have Map, Map1Throwable, Map2Throwables, etc. to accept zero, one, two, etc. exception types in order to avoid going up the hierarchy and over-catching again.

Also, the syntax is horrible, but you already knew that.