Pet peeves in Java
These are my peeves, and the peeves that belong to me. If you think I'm ranting over nothing, stick your comments below my items please.
- Declaring a class final is the height of arrogance. Who are you, a library writer, to tell me how to use your library? And doing so in the name of "security" is nonsense.
String as a final class.
- Thanks to this bit of brilliance I can't add a LevenshteinDistance method to String, so instead of the succint, clear string.levenshteinDistanceFrom(anotherString); I have to create a LevenshteinDistanceCalculator class with a single public method, create an instance, and call its method. Ugly!
- Oh, wait. That's right. I wouldn't be able to add a LevenshteinDistance method to String anyway because of the file-oriented style of Java code. I'd have to subclass String. so I still wouldn't be able to write what I would in Smalltalk: "string" levenshteinDistanceFrom: "sting".!
- And saying you shouldn't override String's behaviour because the VM knows about String's internals just tells you that you've cocked up the VM - the VM is just another piece of code so why should it have special privileges and knowledge of internal behaviour of String?
- The new operator. What is wrong with something like Foo f = Foo.new();? Using new just because C++ did is just stupid. We always used flint & steel to light our fires, so why should we use matches? Get with the program, people.
- Why is an array a language construct, and not simply a class? And if it's not an Object (which it's not) then WHY do you make a new one using new?
- Constructors - these are just methods, for goodness' sake, returning a new instance. There shouldn't be anything special about them. You'd have to have them being static because it wouldn't make sense requesting a null object to return a new instance (a la "String a = a.new()"). The special syntax of constructors (i.e., they don't specify a return type) is just a hack to get around the issue of (contra|co)variance (I can't recall which, offhand) brought in by Java's manifest typing. Have I already mentioned that I can't stand manifest typing?
- Static initialisers. Yet another concept that could have been implemented simply as a method of the metaclass.
- Using { and } for both delimiting blocks and specifying literal arrays. Ugly!
- Primitive types. If you're going to make an object-oriented language, why would you want something other than objects in it, pray tell? This ugliness in the name of efficiency is short-sighted, and just plain ugly. But then, Java would probably have declared them as final objects anyway. Oh, that's right, it's not really that much effort to wrap these primitives up in objects when I want to use collections, is it? Bollocks.
CategoryRant