“Tell, Don't Ask” vs "Ask, Don't Touch"

L'eclat des jours - なんで? 経由で、The Pragmatic Programmers, LLC: Tell, Don't Ask というのがあるのを知って、ナンダッテーッ!?とか思って読んでみたら、たんなる“ask”違いでした(^_^;)。前者は「(前もってあれこれ)尋ねるな」で、後者は「(メッセージを介して)頼め」なのですね。


ちなみに“Ask, Don't Touch”のほうは、アデル・ゴールドバーグが Smalltalk におけるメッセージングを用いたプログラミングを特徴づける際に使ったセリフとされています。ざっと調べてみたのですが、正確なでどころは見つけられませんでした。私のグーグル力も衰えたものだな…。ふっ。


追記:

見つけました。

In order to do anything in Smalltalk, we have to send a message. Sending a message is quite different to calling a function; it is a request to perform some action rather than an order to jump to a particular piece of code. This indirection is what provides much of the power of Object Oriented Programming; it allows for encapsulation and polymorphism by allowing the recipient of the request to decide on the appropriate response. Adele Goldberg has neatly characterised this as "Ask, don't touch".

Smalltalkで何かをするためには、メッセージを送らなければなりません。メッセージの送信は、関数を呼び出すのとは全く違います。メッセージは、特定のコード片にジャンプする命令ではなく、何らかのアクションを実行するための要求なのです。この間接性は、オブジェクト指向プログラミングのパワーの多くを提供するもので、リクエストの受信者が適切なレスポンスを決定できるようにすることで、カプセル化ポリモーフィズムを可能にします。Adele Goldbergはこれを「お願いするのよ…触っちゃダメ」とうまく表現している。[DeepL訳]

A Tour of the Squeak Object Engine by Tim Rowledge

追記 [2022-12-12] DeepL訳を付けて、本文を一部改編しました。^^;