« Learning communties - damn, they're hard to grow | Main | Adding unit tests to a J2EE application »

Named parameters (aka Let's Join A Bandwagon)

I saw a post on Dion Almaer's blog on named parameters, and I thought I'd add my 2 cents worth.

Named parameters are certainly nice, and I wish Java had them. But readability isn't the reason. Consider this example:

Window w = new Window(x:0, y:0, color:blue);

If what I'm concerned about is readability, I can solve that with decent variable names. The bulk of the time, you'd be passing variable references in anyway, rather than primitives or consts, so that's okay.

No, what named parameters saves you on is when you mis-remember the order of the parameters (or when they get changed on you). Assume that in the Window example, all the arguments are ints or longs. If someone decides to change the order of the parameters (maybe they decide colour belongs first), your code breaks.

You can solve this some of the time via decent types for parameters, but not always. Named parameters help a lot here.

Post a comment


About

This page contains a single entry from the blog posted on March 13, 2004 4:50 PM.

The previous post in this blog was Learning communties - damn, they're hard to grow.

The next post in this blog is Adding unit tests to a J2EE application.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.35