views:

25

answers:

3

I'm trying to name a function that runs when a character is received by the object.

For the caller, it should be named sendCharacter, so that it can call:

object->sendCharacter( character ) ;

That looks nice for the caller.. but for the receiver, it implements a method

/// Called when this object is do something
/// with a character
/// from the caller
void sendCharacter( char c ) ;

So for the recipient class, it looks like this method will actually send a character out, not receive one.

So then, I could call the function receiveCharacter

/// Called when this object is do something
/// with a character
/// from the caller
void receiveCharacter( char c ) ;

But now the caller does this:

object->receiveCharacter( character ) ;

Which just looks odd.

How can I better name this function?

+4  A: 

Maybe it's just the example you chose, but sendCharacter and receiveCharacter are both meaningless. Why are you sending a character to the object?

A better choice would be to pick something that indicates why the character is being sent -- for instance, appendCharacter.

Picking a specific "append" example: C# and Java both have a StringBuilder that has an Append(string) method. Sure, you're sending the string to the instance of StringBuilder, and the StringBuilder is receiving the string, but that's not the point. The point is that the string is appended to its internal buffer/array/implementation detail.

Mark Rushakoff
This is an interesting angle!
bobobobo
+1  A: 

If the method reacts on character events, then how about

void onCharacter(char c);
Nick D
+1  A: 

void processCharacter(char c) {...}

I am glad to see someone else who agonizes over method names. I spend too much time doing that ;)

Rob Goodwin
I like the "duality" of this name - it does indeed make sense for both the caller and the recipient
bobobobo