JavaScript:SpiderMonkey:C++ Coding Style: Difference between revisions

Line 26: Line 26:
  }
  }
** An easy [https://bugzilla.mozilla.org/show_bug.cgi?id=489419 starter bug] to steal and patch.
** An easy [https://bugzilla.mozilla.org/show_bug.cgi?id=489419 starter bug] to steal and patch.
* Member variable names, private or public, are '''not''' decorated. Examples of improper decoration include:
class Fail
{
  size_t capacity_;  // unsightly
  T *mBegin;        // makes babies cry
  T *m_end;          // much typing
}
Sometimes a canonical argument name may conflict with a member name.  In this case, one can disambiguate with "this->", although such explicit qualification should only be added when necessary:
class C
{
  size_t count;
  bool fresh;
  void change(size_t count) {
    this->count = count;
    this->fresh = false;  // verbose and unnecessary
  }
};
* Most macros become inline helpers. With LiveConnect gone on mozilla-central, we can make the helpers methods of relevant structs or classes finally, instead of static inline functions.
* Most macros become inline helpers. With LiveConnect gone on mozilla-central, we can make the helpers methods of relevant structs or classes finally, instead of static inline functions.
* Based on 20+ years of bad experiences, we are going to go slow and resist virtual methods and bases, MI, and the like. Function pointer tables for now, as before -- see [https://bugzilla.mozilla.org/show_bug.cgi?id=408416 JSObjectOps needs a make-over].
* Based on 20+ years of bad experiences, we are going to go slow and resist virtual methods and bases, MI, and the like. Function pointer tables for now, as before -- see [https://bugzilla.mozilla.org/show_bug.cgi?id=408416 JSObjectOps needs a make-over].
* Templates are good, Mozilla has positive experience and the portability is there for the kind of [http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization RAII] helpers we need.
* Templates are good, Mozilla has positive experience and the portability is there for the kind of [http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization RAII] helpers we need.
* No exceptions, so std is hard to use. Sayrer suggests using v8's vector type to get started.
* No exceptions, so std is hard to use. There is initial work underway to make STL-like containers that mesh well with the rest of the JS engine (see js::Vector, js::HashMap, js::Pool).
* We would benefit from better hashtable API. Implementation, in targeted ways (delegate free and removed sentinel representation so that the double hashtable entry can be a word; improve bit-mixing into multiplicative hash if the cycle costs can be supported), but measurement is required and we should understand down to the bits what is going on.
** There are still improvements to be made to the new hash table: double-hash implementation; improve bit-mixing into multiplicative hash if the cycle costs can be supported (measurement is required and we should understand down to the bits what is going on); a js::HashSet or js::HashMap<T,void> specialization such that set-like use of hashtables do not waste any space on values.


== References ==
== References ==
Confirmed users
367

edits