Archive for December, 2007

Scala 2.6.2 getting support for Java generics

Saturday, December 29th, 2007

Scala is a far superior language to Java. In fact, of all the languages that I have investigated, it is the most powerful language that also targets the JVM and Java libraries easily (sorry CAL). I have long held the position that there are no (with one corner case) rational justifications for using the Java programming language for anything but educating our children on how not to design a programming language even when targetting legacy code. This has of course, been met with ‘what about this?’ and ‘what about that?’[1] all of which I have been able to refute, except for one niggling corner case.

Client code of existing Java-compiled code would not receive the benefits of generics, since they were erased. For example, if you were to call a Java-compiled method that returned a List<Integer> from Scala, you’d have a reference to java.util.List without the type argument. If you were to call this method from Java, then many methods on the returned List would return Integer in place of the type argument, however, for Scala, you’d have a type AnyRef (an alias for java.lang.Object) just like Java did in the pre-1.5 days. This gave Java one (and only one) case where its use was an improvement over the use of Scala.

This has been the only remaining use case where Scala does not match or exceed Java in ability, however, Martin Odersky (creator of Scala) has revealed that the next version of Scala is to do away with this limitation! Furthermore, we can use the feature today! That is, we can start moving over any Scala <= 2.6.1 code to 2.6.2 right now and have the full advantages of a powerful language and do away with Java forever, unless of course, you're still out there appeasing the irrationalities of the suits (you poor buggers, no really, I mean it).

From Martin on the Scala mailing list:

Just to confirm:

The nightly build of Scala contains now support for Java generics. The
first official release supporting this will be 2.6.2. For instance
java.util.List is considered a generic type in Scala in this release.
I announce now so that you can experiment with the new feature. Maybe
you also already want to start to migrate your codebase to the new
scheme.

More precisely, the following things have changed:
continues

[1]
Here are some that I have met and convincingly (and often quite easily) debunked in conversation. Perhaps I could write about them some time.

  • From the CTO of X Corporation, “I don’t have any programmers capable of using Scala”. This myth is both easily falsified, but also extremely detrimental to the interests of the organisation — far more than is initially realised. That is to say, after debunking this myth, my opponent in the argument often has an enlightening experience and then an “Oh no! Given this (new understanding), look at what (detrimental decisions) I have been doing to the organisation!”. Of all fallacies, this is the one I’d like to put in the box of past events from which to learn.
  • But Java is enterprise-ready
  • But Java is a robust language with many libraries

What’s it like to use those languages?

Thursday, December 20th, 2007

I have had colleagues and others ask me, “what is it like to use those non-mainstream languages?”. I have never given an answer that I think is satisfactory. It doesn’t seem possible to answer this question satisfactorily, without educating on all the fundamental programming and mathematical concepts that are on hand. I want to convey what it would be like to someone who is familiar with the typical mainstream languages such as Java and C#, without having to dive into a lecture about category theory or type-classes or what-have-you. It is also hard to answer this question when there is so much pseudo-science around; I have to contend with absurdities such as ‘design patterns’ and ‘X driven development’ and sometimes even the hijacking of terminology such as ‘automated testing’ and ‘type-safe’ and … (I could go on and on).

Instead, I propose a hypothetical scenario that the inquirer is likely to be able to imagine. Then point out what it is like from their position in light of this hypothetical position. Hopefully then, I can simply say “it’s like that” and have the question answered satisfactorily. On with the story…

Imagine there was a programming language called Java Prime (Java’). It was just like Java, except it had no such thing as java.lang.Object or a common supertype. Instead, to represent universal type arguments, we used generics, even for such functions as equality i.e. {<T> boolean eq(T t1, T t2);}. We maintain the usual Java rules of invariance in type arguments i.e. C<T> is a C<U> iff T = U as opposed to say, covariance, C<T> is a C<U> iff T is a U. For example, in Java, a List<String> is not assignable to a List<CharSequence> even though String is a CharSequence.

Now imagine a new programming language called Java Prime Prime (Java”). This language is not as powerful as Java’ because it doesn’t have generics! Now imagine that Java” had mass adoption because learning generics is too hard, ‘not for the real world’ and ‘only relevant in academia’. We could hypothesise about how the result would look. Here is one scenario; you cannot write a function to compute the length of a List; instead, you have to write a function for each and every type that may be applied to a List. Then, some bright guy would register listlength.com and start the ListLength project. He would ship a JAR file containing the length function over many different types. He would attract fellow contributors and even write some kind of plugin facade that would allow you to compute the length of Lists of types in third-party APIs. listlength.jar would be a 100MB jar file that you could download.

However, some other guys aren’t into the length library. After all, it only works on List; what about Set and all the other types? Furthermore, the function should be called ’size’ not ‘length’. So now we have a debate about the correct name of the function and size.jar is 150MB and has Eclipse integration (somehow?). The debate is quite circular and often attracts personal attacks and so on. You watch this debate from the sideline; sometimes laughing at its silliness, sometimes feeling quite empathetic toward its proponents.

The hypothetical size of listlength.jar and size.jar is infinity. It could indeed go on forever and it keeps many people employed. To threaten the monopoly on list length would attract the harshest of criticism, despite any irrationality of that criticism. Imagine walking passed a ‘length guy’ and a ’size guy’ having a discussion and whispering into each of their ears, ‘generics’. You would attract many kinds of irrational responses and you could even catalog each one perhaps assigning some to the blatant logical fallacy group, the anti-intellectualism category and intersections of categories and so on, anticipating and sometimes even making predictions which response is about to be used based on body language. You could chart them and determine which response is likely to follow from which and so on. In fact, you could get a darn good idea of the way the system works; much better than the length or size guys ever will while their bubbles haven’t popped.

The fact of the matter is that you just wrote infinity lines of code by saying a single word. This might sound knee-jerky and quite out-of-nowhere, but it is absolutely true. The fact that the statement appears both extreme and is absolutely true should start ringing some alarm bells for the length and size guys, but they have already prepared their defence against these kind of attacks. You might even say things like, “the length and size libraries are the most useless things I have ever seen” even though it is so popular that it appears on some people’s CV! You don’t write a web application without first downloading listlength.jar or size.jar (depending on which establishment you subscribe to).

So you plod on, using generics in Java’ as it were, having already written the list length function (and the set length function and… oh wait, I’m not going there :)) once and for all and you have no choice but to ignore the length and size guys, despite their curiosity about what it is you are doing. If you ever present your length function to them, be prepared for charges such as ‘how confusing’ or ‘look, it’s longer than my length function! (while pointing at the <T> declaration)’, but if you’re like me, just sigh and keep on working.

Imagine, however, that you were placed under duress to use and even contribute to the length library. Suppose you worked for Java Joe and Joe, the Senior Architect, demanded that you use the length library, because of the usual irrationalities (too hard, not for the real world and so on). You question him, but the authoritarianism is clear and so there you sit, about to write a line of code for the length library. Suppose now you type 20 characters of code. Have you made progress? Do you feel like typing another 20? You sit there totally aware that the very act of typing 20 characters is no different with respect to progress as it is to doing nothing at all. You wonder if you should even just sit there; why not just go to the beach? After all, you’ll be making the same amount of progress as Java Jim; your colleague madly bashing away at his keyboard. It’s quite an anxious feeling to sit there in a state of logical inconsistency as a result of suppression of reason and thought. How would you deal with it?

That’s what it’s like.

  • Attempting to make undeluded progress against the wishes of a well-controlled establishment
  • As a devout humanist, I watch people labour over a completely futile task under what appears to be nothing more than a spell
  • Dealing with the irrational criticism and charges of blasphemy that are attracted by making statements that challenge the establishment (despite their truth value)
  • Dealing with suppression of reason, stupidity and (often inadvertent) authoritarianism

I hope that gives you a taste :)

Scalaz

Tuesday, December 18th, 2007


Scalaz is a library written using the Scala Programming Language and tested using ScalaCheck (maintained by myself and Rickard Nilsson) automated specification-based testing. It is released under a BSD open source licence.

Features include:

  • The Either Algebraic Data Type and general functions over that type
  • Enhanced Option type
  • Control package (Functor, Monad, MonadPlus, Foldable, etc.)
  • Transparent memoisation, loosley inspired by a paper written by Simon Peyton-Jones, Simon Marlow, and Conal Elliott (IFL ‘99) titled, “Stretching the storage manager: weak pointers and stable names in Haskell”
  • Validation package for web form field validation (using Either and monadic functions across it)

Links:

No no, I said ‘critical examination’

Thursday, December 6th, 2007

The expected tripe has rolled in after my previous post was publicised on reddit (thanks gst whoever you are ;)).

Here are some of the wonderful accusations:

      What a controlling, elitist piece of shit. Worthless article.

      Elitist? I’ll accept that and so what? There is nothing wrong with elitism; in fact, I encourage it. Of course, bragging about it publicly is a little distasteful, but that was never the intention. Controlling? I seem to have controlled you, but nobody else. What else can I say? The response is full of gems of insight!

      What else did you expect? It is Tony Morris, after all.

      Ever heard the term, Ad Hominem fallacy? Such… a critical examination, um, yeah.

      …here we have a Haskell zealot…

      WTF? I use many languages, one of which is Haskell, but certainly nothing that could be described as ‘zealous’. This seems to be an outright statement of ‘I have tricked myself into describing something other than reality’, since I find absolutely no evidence to support it.

      …banned Java from his 6 year-old son’s computer, lest it pollutes his mind. And then he criticises people for being closed-minded!

      I concede on this one and should have made my point clear. I have no intention of hiding Java from my son indefinitely. I’m not going to show him a horror film until he a sound moral basis to conduct himself with his peers for the same reason that I will not show him Java until he has a sound basis with which to apply reason and understands the foundations of what it is he is doing (programming).

      Well I think we’ve all seen this kind of attitude to some extent, but it all seems to proliferate quite extensively from the ivory towers of academia, i.e. the functional programming community.

      They look down on other people who dirty their hands doing “real work” instead of spending time worrying about how pure their language is.

      This one is a classic! First, I’d like to dissolve the apparent rift between ‘the functional programmers’ and ‘the imperative programmers’. There simply is no clear distinction and it’s a pointless exercise anyway. Second, I am a member of both communities.

      Finally, I’d like you to describe for me what “real work” is. Is it repeating yourself indefinitely because your programming language demands it? No really, I’m asking for a formal definition that we can have a discussion about. You do realise that almost all of Java’s language features started off in “the academic world” (i.e. someone though of a clever idea) and were subsequently perverted before finalising in a JSR (i.e. they were dumbed down to appeal to the masses), right? The results of these JSR teams are merely acts of intellectual fraud. I wish they gave public tours of these circuses so you could see for yourself.

      So Tony hangs around mediocre programmers. Big deal.

      Perhaps I do, but there is no evidence supporting this position. I have only described quite a small subset of all programmers that I could potentially know of. I think that most people only know one language, but I could be mistaken (from the samples I have anyway). i.e. Java, C#, VB, C, etc. are all the same language under this description. How many people do you know who look to advanced languages for insight?

      He only hit the grey mass of average programmers. These used to program in C++ and Visual Basic, and before that in FORTRAN. This grey mass of programmers never have in depth knowledge of the programming language or tools they are using, and are too intelectually lazy to actually learn it. I don’t think java create this kind of guys, but it seems to have the qualities that attracts them.

      On a positive note, this response is one that I have not considered enough to my own satisfaction and I thank that respondent for it! ;) Specifically, the response that Java may not create self-delusion, but attracts those who seek it. I’ll have to think about it some more, thanks again.

Thanks for some of the other positive responses that attempt to refute my argument (read: outburst of frustration) with a rational response, it is most appreciated.
THINK

Does Java cause self-delusion?

Wednesday, December 5th, 2007

Finally, the mainstream media is starting to consider the possibility that Java is not only the crappiest language available on this planet (or at least up there with others such as C#), but also has the capacity for adversely affecting one’s learning capacity.

My 6 year old son is learning computer programming by first understanding the mathematical foundations, then applying what he has learned using Haskell, because it is short and natural (he doesn’t even know what Haskell is). I know many people claim to struggle with this language, but I have always held the position that this is because they are tainted will ill-conceived ideas that are internalised to the point of failing critical examination. My son uses a Linux machine for his work (read: fun), but importantly, Java is and has always been banned on his computer. As his trusted carer, I have a moral obligation to protect him from what could cause possible harm and from my observations, potential self-delusion.

Yes, that’s right. Java appears to me to cause an extreme state of delusion. Too often, I find myself in a conversation with someone who only knows one language (or a few others that are superficially different i.e. strict, imperative, poor type system), but most importantly, they don’t know it that well. I have the unfortunate and shameful scar of knowing Java quite well having worked on the implementation, but it always fascinates me to watch someone argue against what I am telling them even though they are not introducing any new information into the discussion. The conversation often quickly denigrates into chest-beating nonsense by making outlandish claims such as “my having never worked on a large Java application” (so what? and, I’ve worked on the largest Java application on the planet, but again, so what?) and various other forms of logical fallacy. I think we’ve all seen this behaviour to some extent, but it seems to proliferate quite extensively from the bottom of the intellectual pool i.e. the Java community.

It is a logical notion that the most well-versed person on the origins of Christianity is an Atheist (and observations support this), likewise, the most well-versed Java programmer wouldn’t touch such a useless (albeit popular) tool unless under extreme duress. This naturally leads to a conclusion where one attempts to explain the observed irrational behaviour from the Java Junkies who don’t understand the ins and outs of Java that well anyway (seriously, this boggles my mind). I certainly don’t think these people are committing acts of intellectual fraud by trying to deceive me. I am convinced that they have deceived themselves (again, Monotheistic belief systems — such a sound analogy), but to this extent?

The psychology of the human brain continues to fascinate me. The ability for self-delusion is extraordinary. I throw out the hypothesis that Java potentially causes brain damage for examination by anyone who cares. Certainly, I find no other explanation for such irrational behaviour.

Discipline in Thought

Wednesday, December 5th, 2007

Professor Edsger Dijkstra

…who once said the following wise words,

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.

Replace BASIC with Java/C# these days.