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.
- But is that standard-C++ in any way?
- Is this some mozilla specific stuff?
- Where is this defined?
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. 🙂