The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

What to name this function?

What I've got here is a simple switch statement that detects when the enter key is pressed.

switch (wparam) {
  case VK_RETURN :

        break;
}

What I am programming is a game, tetris.
What I want is when the enter key is pressed at the menu the current option the user has selected will be sent to a function that knows what to do with that information.

So if my menu is

  Start
  Options

When enter is hit and start is selected, I want to game to be run, if options is selected when enter is hit, I want some kind of option menu screen to be displayed.

My problem is I'm not sure what to name such a function that would do this thing. It's job would be soley to recieve information about what menu option was selected when the enter key was hit and to do some specific action depending. What would I call such a thing? checkThis(), passAndCheckMe(), whatToDo()?

Really not sure.

Monday, October 30, 2006
 
 
I'm not sure why you're asking such a trivial question here, but.... how about "CheckForEnterKey" ?
xampl
Monday, October 30, 2006
 
 
void EnterKeyPressed (int iCmd)
{
  switch (iCmd)
  {
    case RUN_GAME:
      RunGame ();
      break;

    case GAME_SETTINGS:
      GameSettings ();
      break;
  }
}
asmguru62 Send private email
Monday, October 30, 2006
 
 
EnterKeyPressed! That seems like an awful name. It doesn't give any real information about what the function is trying to do.

I would rather the function be named something very descriptive of it's goal, like IManageMenuScreen()

Monday, October 30, 2006
 
 
theFunctionThatIAskedAnUnbelievablyTrivialQuestionAboutOnJOSAndThenWasUngratefulWhenAnyoneBotheredToReply()
ever helful
Monday, October 30, 2006
 
 
ProcessMenuAction?

I think what you're trying to do is describe what it accomplishes, yet name it after what it utilizes. I also suspect you're doing it this way because you're thinking ahead to adding support for other input devices. For example, you might have a set of functions that use the enter key, and another set of functions that respond to a stylus.

My advice? Don't worry about it for now.

Just name it after what it does, and if you feel you need to make it clear that it uses the enter key, say so in the comments.

When Microsoft finally makes stylus-based input universal, they'll likely express it as another VK style macro.
TheDavid
Monday, October 30, 2006
 
 
How about: OnEnterKeyPressed()

"On..." is Microsoft's standard terminology for event functions. The GPL may have a different convention.
dev1
Monday, October 30, 2006
 
 
That goes to show how creative programmers are :)

Gota ask for help with naming a function.

no wonder we cant do any graphic design :)


I'd name is MYFunction2399()
ElCreativo
Monday, October 30, 2006
 
 
Man,

I though My questions were stupid.. :)


no offense.. ofcourse :)
Stucko
Monday, October 30, 2006
 
 
DoStuff() always works for me.

If you have a second, similar function, try DoMoreStuff()
Macbeth
Monday, October 30, 2006
 
 
DoMoreStuff() should extend DoStuff(); the correct name for the second function would be DoOtherStuff().
Paul Brown Send private email
Tuesday, October 31, 2006
 
 
I prefer the grammatically incorrect, but programatically accurate doStuffs()

especially if it's a 300 line method.
Shane Harter Send private email
Tuesday, October 31, 2006
 
 
Freaking classic...Cream of the Crop rising yet again on JoS.

Oh well to be constructive to the thread since I did this to myself by reading such  nonsense, here is my suggestion since it seems to work on so many levels:

DestinedForManagement()
Chris Send private email
Wednesday, November 01, 2006
 
 
Chris, Do you expect that every single user of JoS be the best of the best? Joel never said that, and I don't think he implied it.

Every time a beginner or less-skilled developer posts a question there's someone there just dying to throw joels words back at him.

Please.
Shane Harter Send private email
Wednesday, November 01, 2006
 
 
I believe this thread just answered the question earlier in the main forum if JOS forum jumped the shark: http://discuss.joelonsoftware.com/default.asp?joel.3.410751.24
Mellowman Send private email
Friday, November 03, 2006
 
 
how about ripping out the switch statement for a "Command" pattern?  Saves the trouble of naming it entirely!
Another Anonymous Coward
Monday, November 06, 2006
 
 
Well,

call it
OnEnterKeyPressed() if it is generic, if it is exactly only this menu call it
OnProcessSelectedMenuItem().

Such things are Events, prefix them with "On...".
For things that are external, give them names like
"SetValue()" or "GetSomething()".

If you use the function internally only, like
"SetValue()" checks for parameter validity and you need to do something complicated for adding a value, create a new function called
"DoSetValue()" which is private and can be called from inside your class.

Just some hints...

Naming is something to be done thoughtful if you need the code 6 months later.
Husker Send private email
Monday, November 20, 2006
 
 
I think DoSuff should be extracted to an Interface called IDoSuff() and IDoSomeStuff()

Tuesday, November 21, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz