Closed mindplay-dk closed 8 years ago
The delegate is
$next
in one place and$frame
in another.
I am in favor of:
DelegateInterface $delegate
Finally, the first line of the description of
MiddlewareInterface
reads: [ ... ]
I don't think that Response
and Request
need to be capitalized in descriptions, otherwise I agree with your suggestions.
I have a habit of capitalizing domain terms, but maybe that's just me.
:+1: to DelegateInterface $delegate
.
I removed the capitalization in this PR, and didn't change the method name, so it'll now come out as e.g. return $delegate->next($request)
which seems reasonable.
I'm unsure which signature provides the most meaningful semantics - please see an example of two different terminologies applied here:
https://gist.github.com/mindplay-dk/0b24ad9ed73383e5b723847c545a26bc
The last line of each option is what delegation inside middleware would look like.
@http-interop/http-middleware-contributors please reply with A or B here, and I will update the PR accordingly?
Thanks.
I prefer option B; the delegate is handing off processing to the next layer.
On Sep 17, 2016 9:21 AM, "Rasmus Schultz" notifications@github.com wrote:
I'm unsure which signature provides the most meaningful semantics - please see an example of two different terminologies applied here:
https://gist.github.com/mindplay-dk/0b24ad9ed73383e5b723847c545a26bc
The last line of each option is what delegation inside middleware would look like.
@http-interop/http-middleware-contributors https://github.com/orgs/http-interop/teams/http-middleware-contributors please reply with A or B here, and I will update the PR accordingly?
Thanks.
— You are receiving this because you are on a team that was mentioned. Reply to this email directly, view it on GitHub https://github.com/http-interop/http-middleware/issues/15#issuecomment-247774536, or mute the thread https://github.com/notifications/unsubscribe-auth/AABlVwXZoMPoE23JPMyrs8Qdce5x8fLLks5qq_dygaJpZM4Ju5ie .
@weierophinney are you sure about the method-name though? it does not imply any action. I feel like there should be a verb in there somewhere?
processNext()
is a little more verbose, but more consistent with process()
in the middleware interface maybe?
To me, a method called next()
has not sense here, because the DelegateInteface
is not a queue or a stack of elements that you can move (there's no a prev()
, or if you call next()
twice the same compontent is executed two times instead move two positions). I interpret the DelegateInterface
as the "next" itself, so the only thing you can do is execute it. To me $next->process()
or $delegate->process()
is more appropiate.
And even, if the DeletageInterface
is callable (as the middleman implementation $next()
is more meaningful, so my preferred signature is $next->process($request) / $next($request)
@oscarotero you make some very good points.
$next->process()
would be consistent with MiddlewareInterface::process()
, which is really what both of those methods do - one just happens to be a delegate to middleware which then processes, but the net result of calling either method are identical.
The only pitfall here is, are we overlooking a case where the same class would need to implement DelegateInterface
and MiddlewareInterface
for some reason?
Probably not - I don't think it would make much sense.
But that, in my opinion, would be the only reason not to use the same terminology.
Renaming DelegateInterface::next()
to process()
would be technically incorrect, as the delegate is not responsible for processing, but only for delegating to the next available middleware. The semantics are pretty obvious, in my opinion:
// Delegate response creation to the next available middleware
return $delegate->next($request);
Technically incorrect?
In my experience it's completely normal to name a method according to what the method does - whether it delegates to some other method for the actual work, in my opinion, is completely beside the point. Most implementations delegate some part or all of their work to some other function or method.
In my opinion, a method-name should describe the action you're performing when you call the method.
Client code is asking the delegate to process the request - because it's a delegate, it delegates that responsibility to some other party, but that's an implementation detail; from the consumer's point of view, you're asking the delegate to process the request.
I guess that's fair. @oscarotero can you make a PR please?
@shadowhand PR created #24
I'm not sure if you want to rename also the variable $delegate
to $next
or not (As I can see, it was renamed previously from $next
to $delegate
)
@oscarotero thanks, merged!
Happy with this now. Close?
@shadowhand and the next release will be 0.2.0
since the method-name change was a breaking change, yeah?
Released 0.2.0.
FYI, middleman 2.0 now supports/requires ^0.2
MiddlewareInterface
has this signature:But
ServerMiddlewareInterface
has this signature:The delegate is
$next
in one place and$frame
in another.I don't recall precisely what we decided, but I think there was general agreement not to refer to the delegate as a "frame"? Inline documentation for
ServerMiddlewareInterface
also presently says:I would suggest the following:
Also, the
DelegateInterface
method is namednext()
, so when middleware code delegates to the next middleware, it comes outreturn $next->next($request)
, which is not very semantic - something likereturn $next->delegate($request)
orreturn $delegate->process($request)
would be more meaningful.(I don't think using the name
process()
in the middleware-delegate would be an issue? I can't imagine a case where a middleware delegate implementation is also a middleware component, can you?)Finally, the first line of the description of
MiddlewareInterface
reads:But this interface is for middleware that works on both for client and server-requests, right? So:
@http-interop/http-middleware-contributors I can PR these changes if there is no disagreement? Let me know.