JavaScript:SpiderMonkey:Coding Style: Difference between revisions

Jump to navigation Jump to search
no edit summary
(→‎Namespaces: Update rules per IRC conversation.)
No edit summary
Line 344: Line 344:


Initializer lists can break in one of two ways. The first may be preferable when constructors take few arguments:
Initializer lists can break in one of two ways. The first may be preferable when constructors take few arguments:
  class Ninja : public WeaponWeilder, public Camouflagible,
  class Ninja : public WeaponWeilder, public Camouflagible,
               public Assassinatable, public ShapeShiftable
               public Assassinatable, public ShapeShiftable
Line 352: Line 353:
               ShapeShiftable(MPCost(512)) {}
               ShapeShiftable(MPCost(512)) {}
  }
  }
The other permitted style mitigates longer-identifiers-squishing-text-against-the-right-side-of-the-screen-syndrome by using a half-indented colon:
The other permitted style mitigates longer-identifiers-squishing-text-against-the-right-side-of-the-screen-syndrome by using a half-indented colon:
  class Ninja
  class Ninja
   : public WeaponWeilder, public Camouflagible, public Assassinatable,
   : public WeaponWeilder, public Camouflagible, public Assassinatable,
Line 367: Line 370:


If the method in question fits on one line and is branch free, do a one liner:
If the method in question fits on one line and is branch free, do a one liner:
  class Eater
  class Eater
  {
  {
     void eat(Eaten &other) { other.setConsumed(); }
     void eat(Eaten &other) { other.setConsumed(); }
  };
  };
If it's too long, put the type, declarator including formals (unless they overflow), and left brace all on the first line:
If it's too long, put the type, declarator including formals (unless they overflow), and left brace all on the first line:
  class Eater
  class Eater
  {
  {
Line 380: Line 386:
     }
     }
  };
  };
For out-of-line inlines (when the definitions are too unwieldy to place in the class definition) use the inline keyword as an indicator that there's an out-of-line inline definition:
For out-of-line inlines (when the definitions are too unwieldy to place in the class definition) use the inline keyword as an indicator that there's an out-of-line inline definition:
  class SpaceGoo
  class SpaceGoo
  {
  {
Line 391: Line 399:
     /* ... */
     /* ... */
  }
  }
== Boolean Types ==
* We would like to use the C++ 'bool' type wherever possible, but we must avoid breaking public and 'friend' APIs that use JSBool.  So public header files (and semi-public headers, like 'jsopcodes.h') should continue to use 'JSBool', 'JS_TRUE', and 'JS_FALSE'.  In all SpiderMonkey '.cpp' files, use 'true' and 'false', never 'JS_TRUE' or 'JS_FALSE'.  Use 'bool' whenever doing so would not conflict with a declaration in a public or semi-public header.


== References ==
== References ==
638

edits

Navigation menu