What is Nostr?
unclebobmartin /
npub19mu…jnft
2023-05-24 13:37:56
in reply to nevent1q…ch5q

unclebobmartin on Nostr: Generally speaking you would use the handler if the function that returns the value ...

Generally speaking you would use the handler if the function that returns the value is asynchronous. In that case the handler is just a callback from the asynchronous process.

You might also pass a handler if the function returning the value might return many values over time. i.e. it runs in a loop and produces intermediate values that have to be handled by the external handler.

Still another scenario is the "Tell-Don't-Ask" discipine which says that no function should return a value, rather they should all forward their results to other functions in other objects. This is not a discipline that I adhere to very closely; but others swear by it.


From: (benc) at 05/24/23 08:27:50 on wss://relay.damus.io
CC: unclebobmartin (npub19mu…jnft)
>---------------
>unclebobmartin (npub19mu…jnft)​ I got an interesting question I’d like to hear your take on.
>
>Is there any wisdom when comparing the pros and cons of returning a value versus passing an interface?
>
>// two options for handling a value.
>class Foo {
> int returnValue();
> void passInterface(Handler);
>}
>
>interface Handler {
> void handle(int);
>}
Author Public Key
npub19mun7qwdyjf7qs3456u8kyxncjn5u2n7klpu4utgy68k4aenzj6synjnft