My post from last week generated some interesting discussions and reactions, but one in particularly grabbed my attention.
Both Stephen Haberman and Tom Davies made the following observation:
As far as Fantom is concerned, I doubt the successor of Java will lack user defined generics. That’s like going back to Java 1.4.
This got me to think. If I were to pick a different language than Java, would I be willing to give up user defined generics? Here is my answer:
That’s a fair point.
And user defined generics are on Fantom’s road map, but I wouldn’t expect them for at least one or two years.
Switching to a new language always comes with compromises, no matter how superior you think that new language is. Even if it beats your current language on every point, you should expect to lose some productivity because of lacks in other areas, such as tools, support, documentation, community, compiler bugs, etc…
Fantom is no exception, and actually, due to the very design goals and Andy and Brian set for themselves when they created it, Fantom made some tough compromises in order to keep the language manageable. And user defined generics are one of the casualties.
Note that Fantom supports implicit casting, which contributes to cutting down the verbosity of the code when you are dealing with raw user types, but obviously, this doesn’t buy you any safety compared to user defined generics.
By the way, as the name implies, “user defined generics” means that Fantom does support some limited form of genericity: only List, Map and Func are generic. Therefore, your collections remain typed but you no longer have the option to create your own class Node<T>.
Is it a big deal?
I would miss them, because I do use them. A quick look at the TestNG code base shows about twenty generic classes out of nine hundred. That’s less than 2%, and TestNG is a framework that exposes a substantial API. But there is no question that these classes increase the robustness of the API and of the client code that uses it.
However, I feel that I would use the other features that I would gain from Fantom a lot more, especially properties and closures. I wouldn’t be surprised to find out that I could use at least one of these features in all the nine hundred classes. That’s a lot of benefit right there.
How about you? If you had to drop one feature from the following list:
- User defined generics
- Type inference
- .net support
Which one would you do without?