Powered by: newtelligence dasBlog 1.9.7067.0
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2008 , Ted Neward
E-mail
The Pragmatic Programmer says, "Learn a new language every year". This is great advice, not just because it puts new tools into your mental toolbox that you can pull out on various occasions to get a job done, but also because it opens your mind to new ideas and new concepts that will filter their way into your code even without explicit language support. For example, suppose you've looked at (J/Iron)Ruby or Groovy, and come to like the "internal iterator" approach as a way of simplifying moving across a collection of objects in a uniform way; for political and cultural reasons, though, you can't write code in anything but Java. You're frustrated, because local anonymous functions (also commonly--and, I think, mistakenly--called closures) are not a first-class concept in Java. Then, you later look at Haskell/ML/Scala/F#, which makes heavy use of what Java programmers would call "static methods" to carry out operations, and realize that this could, in fact, be adapted to Java to give you the "internal iteration" concept over the Java Collections:
1: package com.tedneward.util;
2:
3: import java.util.*;
4:
5: public interface Acceptor
6: {
7: public void each(Object obj);
8: }
9:
10: public class Collection
11: {
12: public static void each(List list, Acceptor acc)
13: {
14: for (Object o : list)
15: acc.each(o);
16: }
17: }
Where using it would look like this:
1: import com.tedneward.util.*;
3: List personList = ...;
4: Collection.each(new Accpetor() {
5: public void each(Object person) {
6: System.out.println("Found person " + person + ", isn't that nice?");
7: }
8: });
Is it quite as nice or as clean as using it from a language that has first-class support for anonymous local functions? No, but slowly migrating over to this style has a couple of definitive effects, most notably that you will start grooming the rest of your team (who may be reluctant to pick up these new languages) towards the new ideas that will be present in Groovy, and when they finally do see them (as they will, eventually, unless they hide under rocks on a daily basis), they will realize what's going on here that much more quickly, and start adding their voices to the call to start using (J/Iron)Ruby/Groovy for certain things in the codebase you support.
(By the way, this is so much easier to do in C# 2.0, thanks to generics, static classes and anonymous delegates...
1: namespace TedNeward.Util
2: {
3: public delegate void EachProc<T>(T obj);
4: public static class Collection
5: {
6: public static void each(ArrayList list, EachProc proc)
7: {
8: foreach (Object o in list)
9: proc(o);
10: }
11: }
12: }
13:
14: // ...
15:
16: ArrayList personList = ...;
17: Collection.each(list, delegate(Object person) {
18: System.Console.WriteLine("Found " + person + ", isn't that nice?");
19: });
... though the collection classes in the .NET FCL are nowhere near as nicely designed as those in the Java Collections library, IMHO. C# programmers take note: spend at least a week studying the Java Collections API.)
This, then, opens the much harder question of, "Which language?" Without trying to infer any sort of order or importance, here's a list of languages to consider, with URLs where applicable; I invite your own suggestions, by the way, as I'm sure there's a lot of languages I don't know about, and quite frankly, would love to. The "current hotness" is to learn the languages marked in bold, so if you want to be daring and different, try one of those that isn't. (I've provided some links, but honestly it's kind of tiring to put all of them in; just remember that Google is your friend, and you should be OK. )
There's more, of course, but hopefully there's something in this list to keep you busy for a while. Remember to send me your favorite new-language links, and I'll add them to the list as seems appropriate.
Happy hacking!
local anonymous functions (also commonly--and, I think, mistakenly--called closures)