New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Less obtrusive hugs #486
Less obtrusive hugs #486
Conversation
It feels somehow better to go $this->hug($object) over $object->hug($this), could be because I see $this as the object wanting to hug, even though both are of course possible it seems nicer in the example and less obtrusive "give me a hug" vs "I give you a hug" <3
Hm, interesting, point! But then it's an interface on self, not on a 3rd party object. Does that still fulfill an interface? What would $this->hug() do other than call $object->hug($this)? |
The question that comes to my mind is... Is every hugger huggable? If not my solution would not work. |
Just because a hugger is huggable doesn't really mean the huggable wants the hugger to hug. It would be better if there was another interface for permissible hugging. That way you can test for the interface method and either allow or deny the hug. Not sure about the direction of hugging. Part of me thinks that hugging should be initiated by an external event. Meaning the I do think that it is still possible that you can have |
An object certainly should be able to declare if it wishes to be hugged or not. Hugging an object that does not want one is an API violation. However, the expectation is that an object indicates it wishes to be hugged by implementing Huggable. That is, an object implementing Huggable is saying that it is OK with being hugged. Which brings us to @michellesanver's question, which is more about the assumption in the spec now that hugs are always reciprocal. The spec currently states:
That is, all hugs MUST be reciprocal. If that's the case, then it doesn't matter which side initiates the hug as both will still be hugged at least once. Is that a safe assumption to make? Cases where it may not be:
The second case implies that we should allow objects other than $this to be passed; any Huggable would suffice. The first case doesn't affect what is passed, but does imply that the MUST should be softened to a MAY; that is, hugging another object implies that you're OK with being hugged back, but the receiver is under no obligation to do so. Make sense? |
I think that instead of a permission flow or required reciprocation, we should simply add a success/deny flag return to |
Hm, curious. How would that veto process work? |
If I am a god trying to make two huggables hug eachother, the only way to do so would be to call hug on BOTH objects: function hug(\PSR\Huggable $hugger, \PSR\Huggable $receiver) {
// Perform a two way hug
if (!($hugger->hug($receiver) && $receiver->hug($hugger))) {
throw new \RuntimeException('Someone didn\'t want to hug :(');
}
} On the other hand, if a huggable itself is attempting to hug another huggable, this veto process is a little more obvious: public function doWorkWithObject(FooType $object)
{
$this->doTheWork($object);
if ($object instanceof \PSR\Huggable) {
// Let's thank this object with a good ol hug
if ($object->hug($this)) {
// The hug was approved, lets complete this hug by hugging back
$this->hug($object);
} else {
// The hug was vetod, what a jerk
$this->log->debug('Hug denied!', array($this, $object));
}
}
} |
Do you need to be huggable to hug an object? I think so as whilst one object initiates the hug, it then becomes a mutual action where both objects are... being hugged by the other. |
@michaelcullum The signature for Hug currently requires you pass in the object that is receiving the hug: public function hug(Huggable $receiver); So you don't need to be huggable to initiate a hug, but you DO need to be huggable to participate in one. |
Obviously, the solution is to have a system more of an observer or event pattern than a strict object with interface implementation. With the observer pattern you can register that you are capable of receiving a hug and provided the You could further extend the system with a later specification providing a For me, the biggest problem is that you only have the What if an object registers for a cuddling and receives a hug instead? That sort of rejection could destroy objects in another language. |
@jacobsantos I'd like to see an example of a working interface for that, keep in mind that the FIG only voted to allow in a "Huggable" PSR and not to allow a "Cuddleable" PSR. |
@KorvinSzanto I think it is sad that the action wasn't left more open, but as the PSR is only a joke and in no way would this ever be accepted, I was attempting to further the joke. As with most of my jokes the punchline failed to deliver. I probably shouldn't quit my day job... as a programmer. I think this joke is further extended by people taking it a bit too seriously as programmers and pedantics are want to do. Technically, I think I'm saying that the entire system could use some events as part of the standard. It isn't something that FIG does or adds, but it would solve a lot of problems. |
You ruin the joke by explaining it ;) Pro-tip: We're all in on it |
Hugs are no joke. Can we please get back to serious discussion on this Michael C On 28 December 2015 at 23:43, Korvin Szanto notifications@github.com
|
I can certainly see the value of having a Cuddleable or Spoonable interface in general, but I feel it's inappropriate for a public standards group. Hugging is a standard feature of many projects and can be and has been implemented at many conferences. Spooning, while it probably has been implemented by some members of our community, seems more appropriate as a private API. @KorvinSzanto Your suggestion is quite interesting. It subtly changes the purpose of hug() from "I hug you, you can hug back if you want" to "Please hug me? Oh, hug you back!" That does seem safer, especially in this era of Code of Conduct rules engines. (Which somewhat gets back to @michellesanver's original point.) Technically, though, either approach is still spec legal. And there are likely cases where two objects have previously negotiated that a pre-emptive hug is allowed. (Ie, most people that know @michellesanver for instance.) So I suppose then there's two possible ways to interpret a boolean false return from hug(): "You're welcome to hug me again" and "that hug was welcome". Hm. While there are cases where another object may want to encourage two objects to hug it out, I definitely feel we should support ad hoc hugging of any interested Huggable objects at any time. |
It feels somehow better to go $this->hug($object) over $object->hug($this), could be because I see $this as the object wanting to hug, even though both are of course possible it seems nicer in the example and less obtrusive "give me a hug" vs "I give you a hug" <3