Showing posts with label rants. Show all posts
Showing posts with label rants. Show all posts

Wednesday, 8 October 2008

Thou Shalt not Forget Those Who Are Afraid of Upgrades

I don't know how often I will have to curse about type erasure in the Java HotSpot VM. It is a pain in the… EVERYTHING. And the only reason for it is, of course, our sacred backward compatibility.
Some core library functionalities are utterly broken. How can a parameterized ArrayList's .toArray() return Object[]?
WHY??*
All because of type erasure. class Foo {{T[] = new T[42]; }} is illegal, because the runtime would have no clue as to what constructor to call for the array (it doesn't know its type). It boils down to: you cannot instantiate Generics. OK, you say, it wouldn't make too much of a sense anyway, but you see, it has side effects. Ever bothered to read the code of ArrayList and other parameterized standard collection types that use an array as a back end? Don't, if you want to retain your sanity. The heart of it is a lot of dirty casting, made necessary because of the way Generics are implemented (oh, the irony.)
One of the proposed features for Java 7 are Reified Generics, but somehow I doubt they'll make it into the language anytime soon. There's just still too many people around using a 1.4 VM (YES, Apple, we're looking at YOU) and introducing another substantial change to the way Generics work would make them even more complex than they already are (Yes, that PDF has more than 500 pages. Yes, it's mostly about Generics.) So, probably we'll have to just keep up with that crap. Microsoft did it right in .NET. Pity it's a closed platform.

</rant> [1] You have to first create an Array of your Type T (a literal type, not a Generic one) and then pass it to the overloaded .toArray(T[]).

Saturday, 26 July 2008

The Power of ASP.NET

To all you web admins and coders of web servers: please make sure to fail gracefully. What does that mean? Well, you shouldn't present your potential readers with such hilarious demonstrations of your own incompetence:
HTTP/1.1 404 Connection: close Date: Sat, 26 Jul 2008 13:35:29 GMT 
    Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET 
What's that? A decent 404 message? No! A decent 404 message should include at least an excuse, a clear description of the problem, (not everyone knows how to make sense of something like HTTP/1.1 404 Connection: closed.) and probably a sitemap or search resource to find the content the user came to your web page for in the first place!

Friday, 6 June 2008

Shit happens.

... only to you and when you'd need to get stuff done as quickly as possible
Here used to be a screenshot showing one of IBM's documentation resources about UIMA down, but omploader.org think it's funny to molest people into not using their service, rather than just telling them...
Ah well, I'll need to remember that docs myself now. That'll teach me to sync documentation offline. BTW. Another great example why creating a dark-net to store something as harmless as documentation and/or howtos is braindead. If they hadn't forced me to sign up for their service, I could've used The Internet Archive or the Google cache.

Saturday, 26 April 2008

Where Sun Don't Shine

Sun are a big company. Really big. They created some of the most reliable server workstations, some of the fastest processors, some of the most stable OSs in the world. And they created the as of now most-used programming language, Java. Java is sort of nice. It's dumbed-down C++ with some enhancements, it's not feature rich, but nobody in their right minds wants a programming language to be feature rich. I'm a big advocate of "the right tool for the right job" and feature rich languages seem to contradict to that credo. Java is the right tool for many jobs: GUI creation in Swing is easy and straight forward, networking closs platform is painless and portability is one of Java's main selling points - because it's really easy. The only thing you have to keep track of is the JVM and source version and there you go.

I guess if we lived in milk-and-honey-land, that would make Java a perfect programming language. But it isn't, and milk-and-honey-land is far off. Java was supposed to bring interactive web pages to the clients more than ten years ago (note that JavaScript has nothing to do with Java). It failed. And miserably so, I must say. There's nothing that turns me off more than a page using a Java applet. They are ugly, they are slow to load, memory hogs, and they are buggy.

But I don't care about applets. Servlets are a much better technology anyways, and I found Java to be really useful for Web programming. But this rant is really about Java on the Desktop and about Java for the programmer. Over the years, I've come about some rather annoying misfeatures, bugs and Sun's stubborn way of not wanting to address bugs that have been known - literally - for years.

  • Swing sucks, after all. It's ugly. It's slow. It's bloated. It lacks a set of really useful and easy-to-customize stuff in the library. Heck I remember hacking Delphi used to be more fun than Swing. At least you didn't have to call.thatMethod().somewhere().InAnInnerClass(WayDown.theCamelCase.objectHierarchy()); But see below
  • Swing sucks even more. Ever tried to run a Swing app on X using a window manager that is not one of {Compiz,Metacity,Kwin}? Well, good luck. <3 grey boxes. This has been a bug for a long time, Sun claim it's fixed. It ain't. It's fixed for Compiz, everything else still has problems. This is because some mind-bogglingly stupid intern at Sun had to hardcode the goddamn fucking names of Window Managers into .equals() checks of the kluges used for circumventing the original bug. The result? My favorite window manager, XMonad, displays Protege like this.
  • Many people seem to argue against 8-space indentation on the basis of Java code exhausting horizontal screen space even on 1900xX resolutions. That shouldn't be the case. typedefs, operator overloading, sane object names (SomethingBadHappenedButIReallyDontKnowWhatExactlySoHeresAnException, anyone?) and more modern stuff like partial hiding/importing/exporting (like in Haskell) could greatly improve on the situation.
  • Inexplicable syntactic difference between dynamic and static arrays. Yeah, I know, it's just syntactic sugar. Go write your stuff in ASM, then, if you don't like that.
  • No way to generalize a static array. If T is a generic type, T[] stuff = new T[x]; is illegal. But a function header like void some_function(T[] stuff) isn't. This means that you actually can have static arrays of generalized types, but you have to work your way around like T[] stuff = (T[])Object[x](); This is ugly, and, moreover, it's dangerous. It's also a restriction that hits the language quite hard. Don't believe me? Read on...
  • Not only that, but you are not allowed to create arrays of inner classes of parameterized classes. That's right. No, I know it's stupid, but it's the way it is.
    public class General<T extends Something> { InnerClass[] ic = new InnerClass[10]; private class InnerClass { int data; } }
    This will not compile. It fails with the oh-so-descriptive-and-helpful error message "generic array creation". There you go, the inner class doesn't even use that freaking parameter type. It's enough for it to be a subclass of a paramaeterized type. This is especially annoying when you have to create, say a tree class that is to store all sorts of interesting different types. That would be what them Generics are good for in the first place, right? Well, if you want the tree to have, say, 4 children per node, you'd love to do that using a static array, right? And inner classes are usually the best approach for making a specialized Node class... But in Java, you have to suffer compiler warnings and unsafe typecasts to do that.
  • You can't pass functions as arguments. That's because there are no function pointers. Meh. That makes NLP systems and natural language processing (especially computational semantics) unreasonably complex, because you'll have wrap it all up into classes. But this may fall under the right tool for the right job clause. I've long since wanted to switch to Prolog, C++ and, lately, Haskell for natural language processing. They're way batter at that than Java.
  • This isn't even as much as I expected it to be, but there's more that I've missed for now. Jamie Zawinskie has a lot more on this, but I do not share all his views. Maybe it's that I'm just no C programmer and therefore I have a whole different set of expectations. Maybe I just don't understand all of his points, but I couldn't agree more with most of the stuff he describes. When you google for "why java sucks", you will find a whole bunch of pages. About 3000, for the phrase query. That's a lot for a phrase query.

    I don't say Java sucks in general; it's an OK language for quite a number of tasks. And it's probably even the language I know best. But it has deficiencies, and quite some and then some more. I'll be moving on to greener pastures from now. Prolog sounds nice, it's well suited for what I'm currently doing. Haskell sounds even nicer, and I spend every free minute I can find with monads and similar stuff. I'll probably blog about it, too, when I'm good enough at it. ;-)