[Interest] Are slots even needed these days?

André Somers andre at familiesomers.nl
Thu Mar 17 10:18:44 CET 2016



Op 17/03/2016 om 08:35 schreef Till Oliver Knoll:
>
>> Am 16.03.2016 um 22:37 schrieb André Pönitz <apoenitz at t-online.de>:
>>
>> On Wed, Mar 16, 2016 at 02:31:33PM +0000, Gian Maxera wrote:
>>>> I can connect to Foo::bar either way. If I don't intend to ever use
>>>> the old-style connect syntax, is there a reason to have "public
>>>> slots:" anymore?
>>> One reason that for me it’s fundamental: Readability of your code !!!
>> It doesn't make the code more readable then a comment
>>
>>    // This is a slot !!!
>>    void foo();
> Extend your example to a dozen or so slots and you'd quickly agree that
>
> private slots:
>    void foo();
>    void bar();
>    void baz();
>    ...
>
> is much more readable, as compared to, say, repeating your comment or writing something like "The following 12 methods are slots (but the 13th isn't! And I'm pretty sure that the next Joe Programmer will insert his/her "barFooWhichIsNotASlot()"-method randomly between the first 12 methods anyway... so whatever!)"
>
> Off course you can try to emphasise your slots with nice ASCII art comments, start a fight with your colleagues about the style guide for comments...
>
> Or just write
>
>    private slots:
>
> ;)
>

I find that just the "private:" part tells me all I need to know in 
terms of code documentation. No need for the comment, nor a need for the 
slots part. If you want to make stuff callable for QML or something like 
that it's another story of course.

André




More information about the Interest mailing list