[Kde-games-devel] Design of Qt and/or KGame based programs, part 1

Inge Wallin inge at lysator.liu.se
Sun Sep 26 15:10:06 CEST 2004


Hi,

As some of you might know, I am in the middle of redisigning Kreversi to use 
libkdegames and KGame/KPlayer.  This will eventually lead to nice features 
such as network based games.

Anyway, even though I am a pretty seasoned programmer, I am pretty much a 
newbie when it comes to Qt and event driven programming. During this work I 
have come across a number of questions regarding design that I would like to 
ask to more experienced Qt programmers, i.e. you.

One design issue that I have come across is the naming of slots.  Suppose that 
you have a slot that is pretty simple.  For example, say that it only calls a 
label widget to set the text within that widget.  I like to name my slots 
slotFoo(), where Foo is the actual name of the function.  It would look 
something like this:

void KReversi::slotScore()
{
  m_label->setText(m_game->score());
}

where
  m_label is a label widget
  m_game is a game object that can give the current score.

Now, further suppose that you want to set the score from several places from 
within the same class that the slotScore() resides in.  The call will then be 
"slotScore()" which I find kind of ugly.

How do you handle this case?  Do you

a) Just call the slot like above?

b) have a helper method with, say, the name showScore() that does the actual 
work, and then call it from within the slot?

c) Not name the slot slotFoo() from the beginning, but just foo()?

d) some other way?

I find method a) somewhat ugly, although I can't really put my finger on why. 
Method b) leads to an explosion of small methods and confusion for the people 
that try to read the code.  I like to distinguish my slots from the rest of 
the functions, so I don't like method c) either.

Currently I am leaning towards method a).  What do you think? Is there a 
common convention for this?

	-Inge



-- 
Inge Wallin               | Thus spake the master programmer:               |
                          |      "After three days without programming,     |
inge at lysator.liu.se       |       life becomes meaningless."                |
                          | Geoffrey James: The Tao of Programming.         |


More information about the kde-games-devel mailing list