The little difference that goes a long way...

Once every year I try to recreate blocks in Java using anonymous inner classes, and then quickly remember, how discouraging Java can be:

assertNoException(new Block() {
   public void call() throws Exception {
     sqlInterface.getActiveAppointments(USER_ID, SUPER_START, SUPER_END, COLS); 
   } 
}); 

 

What I'm looking for would obviously be: in Smalltalk

assert noException: [ 
   sqlInterface getActiveAppointmentsForUser: userId betweenStart: start andEnd: end loadColumns: cols
]

Or in Ruby:

assertNoException do
 sqlInterface.getActiveAppointments(USERID, SUPER_START, SUPER_END)
end

Or even frigging Javascript:

assertNoException(function() {
   sqlInterface.getActiveAppointments(USERID, SUPER_START, SUPER_END);
});

Now, just to be masochistic, let's try another Smalltalk favourite. Inject, in Java 5 with Generics:

 

public class OXCollections {

	public static <L,C> L inject(L list, final Iterable<C> iterable, final Injector<L,C> injector){
		for(final C component : iterable) {
			list = injector.inject(list,component);
		}
		
		return list;
	}
	
	public static <C> List<C> inject(final Iterable<C> iterable, final Injector<List<C>,C> injector) {
		return inject(new ArrayList<C>(), iterable, injector);
	}
}



public interface Injector<L,T> {
	
	public L inject(L list, T element);
}

// Reverse all Strings in a List:

List<String> reversed = OXCollections.inject(originalList, new Injector<List<String>>, String>() {
public List<String> inject(List<String> list, String element) {
list.add(new StringBuilder(element).reverse().toString());
return list;
}
});

Yes, Generics really did improve everything for everyone. The pain is almost unbearable.

*sighs* Enough ranting, back to the Java IDE. Life sucks, and then you die, as they say.