0
def create() -> socket.socket:
    ...
    return sock

def create_(func: callable)-> None:
    ...
    func(sock)
    return

What are the names of those two interfaces between* a socket creator and code using that socket?

Perhaps touch on situations in which one is considerably more appropriate.

* - sockets are just an example application

2 Answers 2

5

With respect to functional programming, I think the term you may be looking for is continuation-passing style. This is contrasted with returning a result directly like in your first example.

2
  • Cool, you named both: continuation-passing style; returning a result directly. That's an answer.
    – Vorac
    Commented Dec 15, 2020 at 0:02
  • In object oriented programming this is called message passing to an output port. Commented Dec 15, 2020 at 6:59
3

In your code example, func is commonly called a callback function.

As far as I'm aware, there's no real name for the method itself, other than describing it as using a callback function. Continuation methods fill the same functional requirement but their implementation is conceptually different.

4
  • +1 return an object vs accept a callback is a valid answer. I am accepting the other one because it taught me the term continuation-passing.
    – Vorac
    Commented Dec 15, 2020 at 0:05
  • This only names the structure used. Just because you have a callback function doesn't mean you have to pass it a result. Commented Dec 15, 2020 at 7:01
  • One difference in a callback function is that they typically take two arguments, one of which is null: the result, and an error. This make them more applicable in older procedural or OO style languages.
    – user949300
    Commented Feb 8, 2022 at 7:53
  • @user949300: It's significantly more common to have two callbacks (success and error), not a single callback where you have to nullcheck to see which parameter is not null.
    – Flater
    Commented Feb 8, 2022 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.