3 ms·
The difference is that the API has changed from: search_for_object_in_database which returns the result or a failure indication to: if_object_in_database
by gwright 13y ago
The difference is that the API has changed from:
search_for_object_in_database
which returns the result or a failure indication to:
if_object_in_database_do { this_with_the_object }
The handling of a failed search is now internal to the API instead of in the client code. In this example, 'this' is simply not executed if the search fails. The client code is passing instructions on what to do when the search succeeds instead branching on success or not.
The idea of passing code in addition to data is a powerful one and when the language makes it easy (Ruby blocks, Javascript function objects, lisp functions) it really does change the way you think about the design of APIs.