JavaScript:SpiderMonkey:Coding Style: Difference between revisions

Jump to navigation Jump to search
→‎Namespaces: Update rules per IRC conversation.
(→‎Namespaces: Update rules per IRC conversation.)
Line 298: Line 298:
== Namespaces ==
== Namespaces ==


* Instead of JS/js and JS_ prefixing for public function and type names, respectively, use
* Public functions and types should be in the JS:: namespace, in preference to the old JS/JS_ name prefixes.
namespace JS { ... }
* Library-private and friend functions should be in the js:: namespace, in preference to the old js_ name prefix.
* Instead of js_ prefixing for library-private and "friend" functions,
* Compile-time-evaluated functions (i.e., template meta-functions) should be in 'js::tl::', the "template library" namespace, to avoid collision with their runtime counterparts.
namespace js { ... }
* In SpiderMonkey .cpp files, it is okay to have 'using namespace js;', but it is not okay to do the same with any other namespace, like JS:: or mozilla::. These can introduce ambiguities that come and go depending on which .cpp files the build system decides to unify.
* Compile-time-evaluated functions (i.e., template meta-functions) are kept in the "template library" namespace to avoid collision with their runtime counterparts.
* If you do have names in JS:: that should be readily available throughout SpiderMonkey, you may add a 'using' declaration to js/src/NamespaceImports.h.
namespace js { namespace tl { ... } }
* Avoid unnamed namespaces unless they are necessary to give a class's members internal linkage.  Although the C++ standard officially deprecates 'static' on  functions, 'static' has the following advantages over unnamed namespaces:
* Avoid unnamed namespaces unless they are necessary to give a class's members internal linkage.  Although the C++ standard officially deprecates 'static' on  functions, 'static' has the following advantages:
** It is difficult to name functions in unnamed namespaces in gdb.
** It is difficult to name functions in unnamed namespaces in gdb.
** Static says "this is a translation-unit-local helper function" on the function, without having to look around for an enclosing "namespace {".
** Static says "this is a translation-unit-local helper function" on the function, without having to look around for an enclosing "namespace {".
* Other namespaces? Are these names too short and likely to collide?


== Enums ==
== Enums ==
Confirmed users
497

edits

Navigation menu