[Development] [Feature] Q_INFO: Annotations for classes, methods, properties and enums
Stefan Merettig
stefan-merettig at nuriaproject.org
Wed Sep 11 22:19:33 CEST 2013
Am 11.09.2013 21:49, schrieb Thiago Macieira:
> On quarta-feira, 11 de setembro de 2013 12:03:52, Matt Broadstone
> wrote:
>> Q_ANNOTATE(bar, foo = "baz", abc = "cde")
>> (this annotates the aforementioned property, and is a specialization
>> of the
>> "normal" Q_ANNOTATE, and can appear anywhere in the class definition)
Something like this is simply unparsable. Consider this example:
class Foo {
Q_ANNOTATE("bar" = "baz")
void foo();
}
This would be ambiguous to the reader. That's why I always stressed
that the
macro is *prepended* to whatever it applies to:
Q_ANNOTATE("foo" = "bar") class MyClass { ...
> Sorry, I'm setting my foot down now: do not use Q_INFO / Q_ANNOTATE /
> whatchamacallit for properties. Place the annotation inside the
> Q_PROPERTY.
>
> Compare the two proposals above:
>
> Olivier used Q_INFO before Q_PROPERTY. Matt used Q_PROPERTY before
> Q_INFO.
It's beyond me why we would like to set the name explicitly in the
macro.
Just think of overloaded methods .. Sounds like fun. I just want a
uniform
API for this, both in the Qt API and in the header file. While placing
the
annotation data in the Q_PROPERTY is a violation of this thought, I can
live
with it as long it's the only exception. Though I want to point out
that it's
confusing that Q_PROPERTY 'appends' this information while everything
else
has it prepended. Appending the annotation data to everything is too
hard to
read (Think of classes, would you ever look at the end to find a
annotation?)
and sometimes even dangerous:
void myFunc () Q_INFO(...) { .. }
void myFunc () { .. } Q_INFO(...)
Just think of future fun moments in #Qt because people put their
annotations
at the wrong position. A 'always prepend' rule is pretty simple to
communicate on the other hand, even with a exception for Q_PROPERTY.
> class Q_INFO("Foo" = "bar") Q_DECL_EXPORT Q_DECL_ALIGN(16) Foo :
> public Bar
> { };
See above.
> I'm not sure which of those are valid syntax and which ones aren't;
> which ones
> apply to which, etc. Also, apparently there's a disagreement between
> the GCC
> syntax and the C++11 syntax.
Maybe I'm the only one with that problem, but the positions of C++11
attributes
and their implications confuses me all the time. That's why I
explicitly stated
that Q_INFO/Q_ANNOTATE is always prepended, that is, it's in front of
the
declaration itself. Nowhere else, simply because IMO it's the only
readable
version.
Something like:
void Q_INFO(...) myFunc();
void myFunc () Q_INFO(...);
void myFunc Q_INFO(...) ();
is barely readable.
Note: I used Q_INFO and Q_ANNOTATE here as I pleased. I'm fine with
both.
Also, do we agree that the current syntax is: Q_ANNOTATE("key" =
"value") ?
More information about the Development
mailing list