unclebobmartin on Nostr: If I encountered an API that forced me to pass a handler for no reason other than to ...
If I encountered an API that forced me to pass a handler for no reason other than to force me handle a result, I'd be miffed. The handler is inconvenient to say the least. For example, handlers prevent the simple composition of functions.
I cannot say f(g(x)) if g returns its value through a handler.
Instead I have to do something horrible like this:
interface H {handle(x)};
class H_imp : H {x get(); handle(x) {this.x = x;}};
H h = new H_imp;
g(h, x);
f(h.get);
From: (benc) at 05/24/23 08:44:34 on wss://nos.lol
CC:
unclebobmartin (npub19mu…jnft)>---------------
>The real life scenario that inspired this quest dealt with life cycle. The value returned was supposed to be used to allow a caller to manage the result.
>
>We found instances where consumers where simply ignoring the result leaving things in a bad state.
>
>The handler forces the consume to provide _something_ to manage the result. I think this fits the Tell Don’t Ask idea.
Published at
2023-05-24 13:59:26Event JSON
{
"id": "000442ee82b390c3f457b6f563090063fad9a7ee98447c6e7b1450dd7125d359",
"pubkey": "2ef93f01cd2493e04235a6b87b10d3c4a74e2a7eb7c3caf168268f6af73314b5",
"created_at": 1684936766,
"kind": 1,
"tags": [
[
"e",
"a6c7bc078a43171033f4b0557fb6ccb4706740dcb2c1e0af80f13a4f1740173a",
"",
"root"
],
[
"e",
"fe345cc42c4d861aba32eca6e6ceaa2402e1f142944f92dfba646b778c488de8",
"",
"reply"
],
[
"p",
"2c405fa031a9f4770a4aeec06b4959f92969d4560525e684bb596b57aa018370"
],
[
"client",
"more-speech - 2023-05-23T09:23"
],
[
"p",
"2ef93f01cd2493e04235a6b87b10d3c4a74e2a7eb7c3caf168268f6af73314b5"
],
[
"nonce",
"1007",
"12"
]
],
"content": "If I encountered an API that forced me to pass a handler for no reason other than to force me handle a result, I'd be miffed. The handler is inconvenient to say the least. For example, handlers prevent the simple composition of functions. \n\nI cannot say f(g(x)) if g returns its value through a handler. \n\nInstead I have to do something horrible like this:\n\ninterface H {handle(x)};\nclass H_imp : H {x get(); handle(x) {this.x = x;}};\n\nH h = new H_imp;\ng(h, x);\nf(h.get);\n\n\nFrom: (benc) at 05/24/23 08:44:34 on wss://nos.lol\nCC: #[4]\n\u003e---------------\n\u003eThe real life scenario that inspired this quest dealt with life cycle. The value returned was supposed to be used to allow a caller to manage the result. \n\u003e\n\u003eWe found instances where consumers where simply ignoring the result leaving things in a bad state. \n\u003e\n\u003eThe handler forces the consume to provide _something_ to manage the result. I think this fits the Tell Don’t Ask idea.",
"sig": "6d5e96d6eb864540cfdc9c55d14550f4737dd594eb900c61c866ce5943e6370cfafac1b17fb002c50d7b61e989d046153f2f1104b2f7091e53b1f52e9e6ff462"
}