Suggestion: Dispatcher interface should have return values as public constants
After writing yet another Dispatcher, I've come to think that the Dispatcher interface should have return values as public constants. The trouble is one of readability, and quite minor, but worse when there is a bunch of return statements, or when reviewing a long dispatcher (when you come to the end of the function, and have to reason... now, is true or false the correct return value?). Basically, I would change this: 028public interface Dispatcher 029{ 036boolean dispatch(Request request, Response response) throws IOException; 037} To this: public interface Dispatcher { boolean dispatch(Request request, Response response) throws IOException; public static final boolean HANDLED =true; public static final boolean CONTINUE=false; } Which would let someone write return HANDLED; because the constants come with the interface. It's easy enough to add these constants in every dispatcher, but unlike other (more errant) uses of interface constants that I've seen, this seems to me to be very relevant to the contract of the interface; and it could serve to make dispatchers more readable. I don't think that Java inlines final constants anymore, so there could be a trivial performance penalty. Just a thought... very low-impact on my side. -- Robert Hailey
Re: Suggestion: Dispatcher interface should have return values as public constants
I like this suggestion. :) Could you file a JIRA please? On Wed, 04 Jun 2014 14:35:45 -0300, Robert Hailey rhai...@allogy.com wrote: After writing yet another Dispatcher, I've come to think that the Dispatcher interface should have return values as public constants. The trouble is one of readability, and quite minor, but worse when there is a bunch of return statements, or when reviewing a long dispatcher (when you come to the end of the function, and have to reason... now, is true or false the correct return value?). Basically, I would change this: 028public interface Dispatcher 029{ 036boolean dispatch(Request request, Response response) throws IOException; 037} To this: public interface Dispatcher { boolean dispatch(Request request, Response response) throws IOException; public static final boolean HANDLED =true; public static final boolean CONTINUE=false; } Which would let someone write return HANDLED; because the constants come with the interface. It's easy enough to add these constants in every dispatcher, but unlike other (more errant) uses of interface constants that I've seen, this seems to me to be very relevant to the contract of the interface; and it could serve to make dispatchers more readable. I don't think that Java inlines final constants anymore, so there could be a trivial performance penalty. Just a thought... very low-impact on my side. -- Robert Hailey -- Thiago H. de Paula Figueiredo Tapestry, Java and Hibernate consultant and developer http://machina.com.br - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Suggestion: Dispatcher interface should have return values as public constants
On 2014/06/04 (Jun), at 12:51 PM, Thiago H de Paula Figueiredo wrote: I like this suggestion. :) Could you file a JIRA please? Filed: https://issues.apache.org/jira/browse/TAP5-2347 -- Robert Hailey - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org