maybe I missed something, but I'm wondering about the following:
At the Mozilla Developer Pages about Coding Guidelines, I read the following:
Whenever you are retrieving or setting a single value without any context, you should use attributes. Don't use two methods when you could use one attribute. Using attributes logically connects the getting and setting of a value, and makes scripted code look cleaner.
This example has too many methods:
interface nsIFoo : nsISupports { long getLength(); void setLength(in long length); long getColor(); };
The code below will generate the exact same C++ signature, but is more script-friendly.
interface nsIFoo : nsISupports { attribute long length; readonly attribute long color; };
What I'm thinking about is the attribute long length
. I assume that this syntax aucomatically creates getter/setter methods.
Mozilla uses a language called IDL (interface definition language) to define interfaces for objects that are used in multilanguage contexts, such as both C++ and JavaScript. It compiles down into code in these two languages and therefore allows developers working on the project to have a single definition for their interfaces in as many languages as they'd like. So no, this isn't standard C++ code; it's something entirely different.
On a related note, interface and readonly aren't C++ keywords either. :-)
This coding guideline applies to IDL, not C++, so no, attribute
is not part of C++. The guidelines is taking about the C++ signatures that the IDL generates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With