4 ms·
Messages are inherently decoupled from the methods they invoke, unlike function calls or function pointers. For example, in Smalltalk you can rewrite this: d
by Pharoer_ 11y ago
Messages are inherently decoupled from the methods they invoke, unlike function calls or function pointers. For example, in Smalltalk you can rewrite this:
dictionary at: aKey put: aValue
to:
dictionary perform: #at:put: with: aKey with: aValue
where #at:put: is just a Lisp-style symbol object, an identifier, and perform:with:with: sends a message to the receiver with the first argument as the selector and second and third as its arguments. As one example, this allows you to have a button object that you configure to send some message selector to some object when clicked. Obviously, you can accomplish this equally well with anonymous functions, and since Smalltalk has probably the most concise syntax for anonymous functions (just pairs of "[" and "]"), they are often used instead.
Speaking of anonymous functions and OO, it's bizarre to see FP zealots cite their gradual introduction into mainstream OO languages as proof of some move away from OOP and towards FP, when Smalltalk has had them since 1972 and uses them much more extensively than many "pure" functional languages do (though admittedly in part due to currying and partial application as in Haskell subsuming many of their use cases).