Aug 18

Playing with varargs

Tech 1 Comment »

Tom McQueeney has been playing with varargs.

It will definitely be interesting to see how often people use varargs in their designs… especially code APIs. As with everything, hopefully they won’t be overused.

When you see examples such as:

public Person(String... params) {
lastName = firstName = middleName = nickName = "";

if (params.length > 0) lastName = params[0];
if (params.length > 1) firstName = params[1];
if (params.length > 2) middleName = params[2];
if (params.length > 3) nickName = params[3];

if (params.length > 4) {
throw new IllegalArgumentException(
"Constructor called with too many arguments"

it gets a little scary. How often will someone pass in “Almaer”, “Dion” instead of “Dion”, “Almaer”. Tom points out this issue himself

Named parameters please :) :)

Aug 18

Tomcat, Jetty, Resin, Orion, Choices…

Tech 3 Comments »

Jason Hunter has just migrated from Tomcat to Jetty:

As part of the move I’ve upgraded from Tomcat 3.2.1 to Jetty 4.2.21. Even though I helped develop the earliest version of Tomcat and have an affinity toward it, I decided to hop off the Tomcat 4.x and 5.x upgrade path. In these later versions Tomcat is no longer the lean alley cat it once was. It’s gotten a bit “thick in the middle”.

Here’s the Tomcat 5.x dependencies as pulled from gump: ant xml-xerces jaf javamail jmx jsse xml-xalan2 jakarta-tomcat-coyote jakarta-tomcat-catalina jakarta-tomcat-jasper_tc5 jakarta-tomcat-util jakarta-servletapi-5-servlet jakarta-servletapi-5-jsp jakarta-regexp commons-el commons-modeler txt2html-task jakarta-struts junit jndi jakarta-site2 jdbc jaas jta ldap commons-beanutils commons-fileupload commons-launcher commons-collections commons-digester commons-dbcp commons-pool commons-logging commons-daemon xml-apis.

Here’s the Jetty 4.x dependencies: ant commons-logging xml-xerces mx4j xml-apis.

It’s 35 to 5, by my count. In the game of Bloat, lower scores win.

Apache friends I trust said they’ve had much better luck with Jetty and its more focused design, so I followed their advice. I’ve been very pleased. It’s easy to configure, starts very quickly, and has great documentation. Only a few of the book examples aren’t working yet, mostly those related to security. Servlets are portable but their security configurations (i.e. user lists) aren’t.

Tomcat definitely gets a bad rap. The whole dependency game is a real PITA, as many people have discussed before. One of the biggest flaws that I have found with Tomcat is that you can’t embed it. Just talk to the Geronimo folks about that pain… and why do you see so much JBoss/Jetty.

I *have* noticed speed improvements with the 5.0 branch of Tomcat. It has definitely improved from that regard, and isn’t a total dog anymore. Being a reference implementation doesn’t help too, as that role brings different challenges into the mix.

When I think of it, I have enjoyed working with most of the Servlet containers. Resin is speedy, Orion is pleasant. Anything that doesn’t use Jasper as the JSP compiler is a pro (not having to use JSP is in general a pro too ;). As long as you stear from the heavy containers unless you need too, there are some great choices out there!

Aug 18

RE: Components, Design, and Functions

Tech 1 Comment »

I liked reading Brian’s ditty on Components, Design, and Functions.

It is good to see more examples of how people are using IoC and simple containers such as NanoWeb.

I think the following says a lot:

I used nanoweb here as it is a great for short-and-sweet type things (like this example) and has mostly replaced ruby/cgi for minimal web apps for me as it simply gives you so much for so little.

Faster development??? Now *that* is good to hear.

Aug 17

Vonage: Local phone company putting a spanner in the works

Personal 32 Comments »

I got a Vonage VoIP setup, and it has proved to be a pain in the arse, mostly NOT to do with Vonage.

The local phone company obviously doesn’t want to lose out, so what have they done? If someone in my area code dials either: XXX-YYYY or XXX-YYY-ZZZZ it is meant to come through (7 digits still work here which is nice).

However, ONLY 1-XXX-YYY-ZZZZ seems to actually work from a local land line in the same area code. The company will NOT route another number through. This is just another PITA things that they are doing to drag their heals. I have also heard that although you are meant to be able to transfer your numbers around, they sometimes make it REALLY hard. :(

Aug 17

Be a language designer…

Tech 21 Comments »

Eric Gunnerson, formerly of the C# team, got an email stating:

When I’m writing code, I often come across a situation where my code throws an exception because another component called with a null parameter. I’d like a way to prevent that from happening.

People started down the path of having an Annotation which would be able to enforce the contract that nulls can’t be passed in (@NullNotAccepted void doFoo(String whee) { }).

I don’t know how valuable this would be, as you can do checks yourself, or even use AOP to do some of this for you.

The key for me is having a decent trace on what the hell is going on when a NullPointerException is thrown. I want my system to tell me exactly what was going on when this happened. With the right info you can then attack the problem, but how often do you get a NullPointerException with zero information and have no idea what the hell is going on! This just comes down to having a nice policy of being good with exception handling, and having precise reporting.

Aug 16

Tangosol Info via RSS

Tech 45 Comments »

I use RSS so much these days that I rarely hit any websites unless they come from links in my reader.

Now I don’t have to remember to hit Tangosol’s site, as they have an RSS feed.

Now-a-days, if you don’t have an RSS feed, you are probably missing a lot of people. PUSH has won ;)

Aug 16

Explaining why Dependency Injection is good

Tech No Comments »

Rickard has done a really good job and explaining why DI is good.

In a very simple, scientific way, he details the simpliest of examples (Foo depending on Bar), and shows how the properties of different designs affect your agility.

I really like how he explains these properties:

This code has the following properties:

Bar can be a class, an abstract class, or an interface
Foo does not need to know how Bar is instantiated
The Bar instance can be used by other components
Bar can have any configuration needs
The user of Foo needs to know how to provide a Bar

Many people know that they enjoy moving to this model when designing their code, but don’t know how to explain why they like it so much. On one hand people say “it is just a constructor / setter / …”.

Aug 16

Tapestry, and Less Configuration

Java, Tech, Web Frameworks No Comments »

Mike Henderson is on a roll with his entries on Tapestry, and custom hooks.

Less Configuration – Enhanced Tapestry Component Resolution, Part Two, Part Three.

I like to be able to organize files into groups with folders and I also don’t like to do too much configuration file maintenance. Tapestry will find components in the /WEB-INF directory in my WAR without configuration but with many pages and components in an application it becomes unwieldy. Tapestry allows me to add these components to my specification, specifying the path, relative to the /WEB-INF folder, and provides an ant-task to automate the maintenance of these component declarations. What if I could structure my pages and components into any directory structure I want and not have worry about maintaining the application specification file, even with an automated tool? I could add components while testing without a restart. Since servlet containers can explode a deployed WAR file into a directory structure this method would even work in a deployed Tapestry application.

Fortunately, Tapestry has a number of extension points which can be used to extend various framework behaviors. One of these is the ISpecificationResolverDelegate interface.

I wonder if any of this will change with 3.1…. especially with the enhanced HiveMind stuff.

Aug 16

David Geary gets blogging on JSF

Java, Tech, Web Frameworks No Comments »

David Geary is a friendly chap who is on the No Fluff Just Stuff Symposium tour.

He has started a blog, which has been talking about JSF (he is on the Expert Group, has the book [Core JavaServer Faces], etc).

His latest post discusses the fact that JSF can render some things on the client side.

He also had a reply to Matt’s thoughts on working with JSF

Aug 13

No more troubles with ternary

Tech No Comments »

I am a fan of the ternary operator. I get bored of if(), and prefer to jump into a ? : if it makes sense.

I think part of the reason that I like it, is that I like the shortcuts in life. I really used to enjoy:

my $foo = $bar || “In case”;

die “Naughty” unless $you_were_good;

One of the things that bugged me about the ternary operator in Java, was that it would catch some people out on items such as:

String str =”whee”;

StringBuilder builder = “whee”;

boolean mutable = true;

CharSequence chars = mutable ? builder : str;

This used to fail all the time, even though both String and StringBuilder (and StringBuffer) implement CharSequence.

Luckily, this now works in JDK 1.5, and we don’t have to resort to the ugly:

CharSequence chars = mutable ? (CharSequence)builder : (CharSequence)str;