by skizm · 13y ago · 0 comments
Sure it has warts like all other languages -- memory hog, weird design patterns, bulky code -- but a lot of those can be easily avoided or worked with.
Sorry for the rant. I've just never had someone give me a straight answer as to why Java is so disliked. It usually has something to do with design patterns (FactorySingltonParentFactory.helper.blahblahblah) but that's just preference and is hardly the common case with Java code.
Also, "hard to shoot yourself in the foot" can sometimes mean "hard to do mystical stuff when you really, really want to". 99% of the time, regardless of language, you should be writing clear, idiomatic code. 1% of the time, though, you want some voodoo (that you can encapsulate so that no one else really has to understand it), and when that time comes you want the language to get out of the way.
For example, almost no one needs to write metaclasses in Python. It's just not something most people will ever have a nonzero desire or need to do. But, suppose you're writing an ORM or a templating system or something else were it might be darn handy to create a lot of methods at instantiation time. In those cases, it's incredibly convenient to be able to do the magical stuff at all. You only have to get it right once, then all the downstream users can benefit from a much simplified and cleaner experience.
I don't want to shoot my foot. Sometimes, though, I might want to shoot a snake crawling across it. I prefer to use languages that keep things safe in general but allow shoot-footing when you really, really need it.
As for your import example you can totally do that:
> import java.util.Collections; Collections.sort(someList);
You just have to make use of static methods. I do understand though that a lot of the standard library is not designed like this so your point is taken.
I'm sure there must be several great tools out there that replace those that I don't like, but I haven't had the time to explore.
That sums it up for me, basically. I could add that this is a manifestation of the tendency to make things more complex than they need to be which is pervasive in the whole Java ecosystem. IMO, even Scala couldn't escape the curse and suffers from it (although it's a lot more pleasant to use than Java).
My first real job was programming Java and I have a bit of nostalgia for it, but having to do anonymous inner classes for a simple callback is kind of annoying.