Why Do Java Developers Like to Make Things So Hard?
"Imagine if the Perl cafe and Javahut were across the street from each other. You walk into Javahut, and ask to sit down. "I'm sorry," says the person at the door. I'm not actually the hostess, I'm a Factory class that can give you a hostess if you tell me what type of seat you want." You say you want a non-smoking seat, and the person calls over a NonSmokingSeatHostess. The hostess takes you to your seat, and asks if you'll want breakfast, lunch, or dinner. You say lunch, and she beckons a LunchWaitress. The LunchWaitress takes your order, brings over your food, but there's no plates to put it on because you forgot to get a CutleryFactory and invoke getPlates, so the Waitress throws a null pointer exception and you get thrown out of the place."
This is so true it hurts.
Still, could be worse. Working with RPGIV, there are no restaurants. Nor are there any supermarkets; you have to grow your own food. And make your own cutlery.
Via Ian Bicking.
Posted to Java by Simon Brunning at March 30, 2004 01:06 PMJava is old hat, so is Python, you need to be doing Lua (pronounced Loo-ah) for seriously evil people.
Posted by: SilverBack on March 30, 2004 04:51 PMI *know* what Lua is, Ian. (That is you isn't it?) Lua looks cool, but it's got nothing on Python.
Posted by: Simon Brunning on March 30, 2004 04:57 PMLua: Tcl for the new millenium!
Posted by: Ian Bicking on March 30, 2004 05:10 PMIan, that really isn't a compliment you know :-)
I understand trhe article, but its not really a Java issue - you can create saomething just as 'evil' with python. You might see it more with Java due to the number of frameworks obsessed with the Service locator pattern (which is really what James Turner is talking about). This is of course why IoC rules :-)
Posted by: Sam Newman on March 30, 2004 09:20 PMSam,
You *can* make something just as evil with Python - but for whatever reason, people tend not to. Python is dynamic by nature, and flexible systems don't require any special contortions.
Java, OTOH, is static by nature. To build something dynamic, you have to code everything to interfaces (which is a pretty good practice in any case), and you need to instantiate everything using a factory or IoC. (‘new’ is a code smell.)
You’ve demonstrated the IoC approach on your blog, as it certainly looks simpler and more powerful than the factory approach – but I’ll take Python’s simplicity any day.
Posted by: Simon Brunning on March 31, 2004 09:32 AMOk, I'll bite, why is 'new' a bad thing?
Posted by: Andy Todd on March 31, 2004 09:15 PMBecause you can't intercept a new SomeClass(), you are stuck with a SomeClass instance. You can intercept, inject, register, mock or whatever if you use any other technique, but as soon as you new it, you've got it and only it.
Posted by: Jed Wesley-Smith on April 1, 2004 02:52 AMOkay, I'll bite... What's IoC?
Posted by: Michael Chermside on April 5, 2004 03:29 PMFinally, I found http://today.java.net/pub/a/today/2004/02/10/ioc.html
Apparently IoC stands for Inversion of Control. The basic idea appears to be that if your code needs to use a Widgit object or service, instead of constructing one itself, or calling a WidgitFactory function, your code implements some interface, or has a setWidget() method or something, and something OTHER than your code creates the Widgit. The handy part is you don't have to hard-code the Widgit details. The annoying part is that you need SOME way of telling the rest-of-the-world to give you a Widgit (and what kind)... perhaps a config file or something.
Well... how'd I do?
Posted by: Michael Chermside on April 5, 2004 03:40 PMGood, I think. But Sam's the expert around here...
Posted by: Simon Brunning on April 6, 2004 09:07 AMHave any of you guys actually written any business applications. I'm looking for a success story for a major business application written in J2EE.
Posted by: salvation on April 28, 2004 03:25 PM