DRAFT document on coding conventions in kde libraries

David Faure faure at kde.org
Mon Mar 6 00:10:24 GMT 2006


On Sunday 05 March 2006 22:53, Friedrich W. H. Kossebau wrote:
> So I ask what makes a slot method special at all, except being additionally 
> available for signal/slot connections to some events. Where would tagging a 
> method "slotMethod()" make the code more readable? 
You know when reading the method, that it will be called as a result of a signal
emission, not (or rarely) as a direct method call.

> And doesn't it even make  
> the code more unreadable in places where the signal/slot tricks are not used 
> but the method being called just normally?
If it is called normally, then I wouldn't call it slotFoo()

> Unless there is I would even ask to, ahem, forbid the "slotX" naming convention... :)
Veto! ;)

> See, it seems not to be used in Qt itself, either!
I agree that it's not widely used in Qt, but still:
./network/qhttp.cpp:85:    // private slots
./network/qhttp.cpp:87:    void slotReadyRead();
./network/qhttp.cpp:88:    void slotConnected();
./network/qhttp.cpp:89:    void slotError(QAbstractSocket::SocketError);
./network/qhttp.cpp:90:    void slotClosed();
./network/qhttp.cpp:91:    void slotBytesWritten(qint64 numBytes);
./network/qhttp.cpp:92:    void slotDoFinished();

See, connected() would look like a method that returns a boolean telling the caller
whether we are connected. On the other hand slotConnected() tells me right away
that this is the slot connected (no pun intended!) to the connected signal.
Same thing with closed() vs slotClosed().

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).




More information about the kde-core-devel mailing list