Repository navigation
The use of canHandle #952
Replies: 8 comments 5 replies
|
On the specific case:
I would contest that point actually. However, I don't think the justification with relation to In this case, the "jurisdiction" of In general:
There is a difference between "is this handler the right one?" (applicability) and "will the handler succeed?" (preconditions). We don't see it in #938, because this handler always succeeds when it applies, i.e., it's a handler for allowing Compare this to this case: if an owner uses their
But not all preconditions are applicability conditions.
There is an important difference between "failing because it was not my job" and "my job failed" throughout the server.
That would involve us writing and testing dozens of those for every specific case, whereas |
|
I want to spend more time on this later potentially, but I already wanted to provide some example use cases of where the
|
That's a good one! "YES I am able to handle this, and I am going to do that by absolutely failing!" |
|
Thanks for the almost inhumanly quick reply! 😄 However, I think, mostly from @RubenVerborgh's response, that you do not get the core of what I'm saying. To be clear: I do not want to contend the value of the watterfall pattern, nor that there is currently in the code a practical distinction between "applicability" and "preconditions". What I do want to argue is that this makes the structure of all handlers dependant on the implementation of the @RubenVerborgh, you said that "there is a difference between 'Is this handler the right one?' (applicability) and 'Will the handler succeed?' (preconditions)," and that "the applicability should be judged solely based on the actor itself." I would argue that these statements are contradictory. Let's take the example case you used.
This short functional analysis would seem to translates to the following logic:
Note that I had to improvise what happens in the cases under the last point, because the functional analysis came a bit short. But this improvisation is obviously not what we want: solely based on the actor itself we would prefer not to send an email and not just do 'whatever' if the user is not the owner or uses other permissions. Instead, we would like to do nothing, and if possible be informative of why we do nothing. But that is exactly the same as when the email is incorrect, which leaves us with:
Solely based on the actor itself then, the handler would only need a method that performs all checks, if successful sends the email, and otherwise fails. There seems to be no reason to distinguish different types of checks: functionally the handler an sich is just as "inapplicable" when the email is incorrect as when the user is not the owner or uses other permissions. The point here is really to see that the concept of "applicability" or "jurisdiction", as you named it, only comes into play in relation to the This is not just a theoretical nicety, but also has practical consequences. The way the handlers are currently implemented, code that takes a handler and (only) calls the If all voices are set on this design, I'll politely stop bugging, of course 😉 |
I don't follow that argument, as my previous explanation was unrelated to To make sure we are fully aligned, what we are aiming to achieve with handlers in general is provide generic implementations of the composite pattern. Simply said, there are several places in the code that accept a single component, whereas actually that single component delegates to multiple components. And there are multiple ways to perform such delegation. The strength of the
To give you an idea of how frequent these patterns are:
So those are 24 places where we've been able to simplify classes to expect a single object, and a generic solution allows them to leverage the behavior of multiple objects. The above explanation, and the above numbers, show that we are not coding against So first point: I see no evidence for
No, that last line should be
That is in the contract of
No, we want to fail with an error. And that is the major difference. When an actor's I think some of the confusion might stem from However,
So when it would be the last or only actor in a Also shows once again that we are not coding against
So no, I disagree with that, because we have other composite behaviors.
Yes. Because If that's not what you need, use
Questions and suggestions are always welcome 🙂
But what would that look like? How much more code would we need if we replace the 3 composite handlers, which currently deal with 24 cases, with something else? |
|
I'll leave the very long posts to @RubenVerborgh, can't beat those ;) Some remarks though. @RubenVerborgh, minor remark: the I'm also mostly interested in how such a This might be cheating a bit of course since it probably is the most "complex" handler flow that we have (although there are some similar ones). Note: from this point on I'm going to make assumptions on how such a SwitchHandler would work and make conclusions based on that. These assumptions could of course be wrong or missing essential features. I'm wondering how we would encode such behaviour easily in a SwitchHandler? Would the idea then be to split up the behaviour in 2 handlers per step, one for doing the initial check and one for returning the result? First thought is that this might actually work although from a configuration point of view it would probably be more complicated since there would be more nested components. I also wonder from a design point of view if that would not force the developer to actually have to take the handler situation even more into account. Take the
Discussions like these are like the most fun part of software development :D. Although this might have been better suited for a discussion instead of an issue. Also this reply did turn out a bit longer than expected. |
|
Another aspect to consider: part of our approach is to make behavior configurable via Components.js JSON-LD files. |
Thank you, GitHub, for your flexibility 🙏 @RubenVerborgh, no need to explain the composite pattern 😉 I know it, and we use (almost) the same generic handlers in our own code. So I do definitely not want to get rid of those. However, as @joachimvh already pointed out, the The composite pattern itself, after all, does not contain the concept of "applicability". In fact the pattern is exactly why I would expect a simple handler to be exchangeable with an identical handler wrapped in our generic handlers (which, contrary to what @RubenVerborgh seems to imply, is also not the case for the
I actually think that question speaks to my argument, since it shows how the applicability‒preconditions distinction is a lot harder to make when not taking the current generic composition implementations into account.
Ultimately, I think the issue I have lies in this contract, and stems from a difference in our approaches to programming. Within OO, I guess this is perfectly fine, but I've mostly worked in very functional contexts, and try to retain most of those best practices wherever I go. For me, a method is just a function with an extended scope; and a function's domain is only limited by its implementation, not by some comment refering to another function. (On a side note:, since we're working in TypeScript, if this is really the contract we want, solely based on the actor itself we should enforce so in our input types.)
The effect of only 'describing' the domain by reference is that 'do nothing' cannot be enforced. If the handle function only contains checks for preconditions, and not for applicability, there is not logic to decide what to do if the To be honest, I do not have an immediate alternative (I never claimed to). I just wanted us to take the time to think about it. Here are some initial thoughts:
|

Uh oh!
There was an error while loading. Please reload this page.
I'd like to take @RubenVerborgh's comment on #938 as an opportunity to look into the use of the
canHandlemethod of the handlers, if not to change it then at least to align our opinions on it.The comment expresses surprise about the
canHandlemethod containing all the checks (in casu: whether the requesting agent is the owner of the accessed pod), while thehandlemethod itself hardly contains anything. @joachimvh responded this is the case so that when thecanHandlecheck fails, the next handler will be called, implying the use of aWaterfallHandler. Indeed, the way theWaterfallHandleris implemented, this is not possible if the checks are (only) done in thehandlermethod.The reason @RubenVerborgh expressed surprise can, I think (but correct me if I'm wrong), be understood in the context of what he wrote in #118:
In the case of the comment on #938, however, the checks in
canHandleare preconditions, not (mere) checks for applicability. That these preconditions cannot be put in thehandlemethod, where they belong, because of the implementation of theWaterfallHandler, i.m.o. points to a conceptual problem with this distinction, and thus with the use ofcanHandle, which has been on my mind for quite some time: there is no real conceptual difference between "preconditions" and "applicability" (most immediately: applicability conceptually is also a precondition). Here they simply mean "checks on which the waterfall needs to abort" and "checks on which the waterfall needs to continue". This makes handlers responsible for more than they should be: they have to make sure they behave within the specific context of — and even enable the correct behavior of — theWaterfallHandler, a class on whose implementation they should in fact not depend.Personally, I would prefer to step away from
canHandleandhandleSafealtogether, moving the "applicability" check to the start of thehandlemethod, and letting theWaterfallHandlercontinue on every error. If we really want (conceptually clear) "applicability", i.e. some kind of "switch", then the logic thereof should be contained in a separate handler (e.g. a "SwitchHandler") rather than in the handlers it can contain.All reactions