dev@glassfish.java.net

Re: AMX (DeploymentMgr)

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Fri, 21 Jul 2006 14:42:07 -0700

Lloyd L Chambers wrote:
> A get/set operation would destroy the macro if the port were resolved
> automatically.
>
> int port = listener.getPort(); // assume it *was* $
> {HTTP_LISTENER_PORT}, but resolves to a number automaticallyl
> listener.setPort( port ); // value is now whacked to fixed value

Yeah, but then, think about how hard it would be to correctly write the
code that obtains the port number in integer!

I bet people would just write code like this without knowing that:

   int port = Integer.parseInt( listener.getPort() );

and it predictably fails. (This is also related to why type-safety is a
good thing.)

This is bad because API is driving people to the bad code.

I guess you need a few more abstractions. Something like

class Expression<T> {
   Expression(String text);
   T eval();
   String toString();
}

HTTPListenerConfig {
   Expression<Integer> getPort();
   void setPort(Expression<Integer>);
}

or something. I don't know. I agree it's hard to get this kind of API
easier to use.



-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com