Re: "connect" naming

On 23 May 2011 11:57, Robert O'Callahan <robert@ocallahan.org> wrote:

> On Mon, May 23, 2011 at 2:58 PM, Chris Rogers <crogers@google.com> wrote:
>
>> Think of it this way, it's like plugging a cable into a plug.  For example
>> if a guitarist plugs a guitar into a guitar amplifier it would be like this:
>> guitar.connect(amplifier);
>>
>> Of course, in this case, the guitar is the source of audio.
>>
>> If there's a distortion pedal in between the guitar and amplifier, then it
>> would be:
>> guitar.connect(distortionBox);
>> distortionBox.connect(amplifier);
>>
>> So, it reads left to right as source connects (to) destination.
>>
>
> That makes sense *if* you know that the source is on the left and the
> destination is on the right --- but a casual reader isn't going to know
> that. There are lots of APIs on the Web and elsewhere that use patterns like
> "stream.write(data)" where the source is on the right and the destination is
> on the left ... in fact having the data flow from right to left is probably
> dominant for OO APIs because "write", "send" etc are are methods on the
> destination object.
>

A small tweak to the method name that could improve it's casual literacy
comes directly from Chris's explanation: rename the 'connect' method to
'connectTo'.

    guitar.connectTo(overdrive);
    overdrive.connectTo(compressor);

How does that sound?


Anthony.

Received on Tuesday, 24 May 2011 07:10:44 UTC