[Development] A modest proposal: disable lower-case keywords (emit, foreach, forever, signals, slots) by default

André Pönitz apoenitz at t-online.de
Fri Feb 21 20:30:47 CET 2020


On Fri, Feb 21, 2020 at 08:40:23AM +0000, Alex Blasche wrote:
> > -----Original Message----- From: Kai Köhne
> 
> > Another alternative is to actually use C++ attributes for this:
> > 
> >   [[qt::emit]] somethingChanged();
> 
> I think a fallback to 
> 
> somethingChanged() 
> 
> without any annotation is not what we want. We'd miss vital
> information and reduce readability. Having said that I hate Q_EMIT
> even more. It just is ugly as hell. Therefore, I am very glad about
> Kai's suggestion. Personally, I don't think we need an extra namespace
> after all what are the odds to have a clash here 😉 but.... that's
> details. 

One could have a convention to add an emit_* inline function, i.e.

    class Foo : public QObject
    {
        Q_OBJECT

    ...

        void emit_somethingChanged();

    signals:
        void somethingChanged()
    };


That would require only one character to change on the user side,
instead of 

    ...
    emit somethingChanged()
    ...

it would be

    ...
    emit_somethingChanged()
    ...

Also, the use of the emit_-prefixed version would be optional as
before, just using 'somethingChanged()' is possible for those
who prefer that style.
    
> Last but not least, I don't see why we'd want to disable all other
> keywords when only one of them has a clash.  If the current macro
> enforces this then we should differentiate more. Let's not be too
> hasty when there is no need.

I fully agree.

Andre'


More information about the Development mailing list