What happened to all of the “JVM on hardware” solutions? Web Services and Unix Pipes
Mar 12

I still like Named Parameters ;)

Tech Add comments

Cedric has written up a history of why Named Parameters were not added to C++.

I understand the point made. It is true that named parameters don’t give you new functionality, yet I still prefer the “look” of methods in this manner.

I much prefer:

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

to:

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

OR (if you don’t happen to return an yourself on your set)

Window w = new Window();
w.setX(0);
w.setY(0);
w.setColor(blue);

Also, this is just looking at constructors…. what about the other 99% of methods?

foo.doX(String firstName, String lastName);

versus:

foo.doX(firstName=x, lastName=y);

Also, even for constructors you may want to say “this object HAS to be constructed with a Foo, a Bar, and a Baz”. If you have to call set*() methods then you need to verify your state in other ways.

This is really a matter of taste, and I just happen to like them (and understand if you don’t).

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: What are the first four letters in the word British?