New Layout: Coding Conventions
Updated: March 10, 1998See the modularization docs for component model information.
Naming Conventions
- For (almost) all conventions the name is a sequence of one or more case shifted words with the first word starting with uppercaes (e.g. AddRef and QueryInterface).
- We use "ns" for our private prefix to define a namespace (we cannot use C++'s namespace facility everywhere yet so we have to do things manually still). For classes, structs, enumerateds the prefix is a lowercase "ns". For macros and global procedures the prefix is a "NS_".
- Class names look like "nsFoo" for a given class Foo; for interfaces it's "nsIFoo".
- typedef's for primitive types are all lower case. Example: "nsuint32" is a 32 bit unsigned integer.
- Method names (static or not) look like "MethodName" (they have no prefix).
- Instance variables are prefixed with a lowercase "m" (e.g. mInstanceVariable).
- Method arguments are prefixed with a lowercase "a" (e.g. aArgument).
- Private global variables are prefixed with a lowercase "g" (e.g. gGlobal).
- Private global constants are prefixed with a lowercase "k" (e.g. kKonstant).
- Global procedures (e.g. factory methods) are prefixed with "NS_"
- Macros are all uppercase with underscores between each word (that is, they stick out like a sore thumb when reading the code) (e.g. NS_MACRO_FOO) and they are prefixed with "NS_" when they are exported symbols.
- Enumerated tags are prefixed with "eType_". Example: enum nsFoo { eFoo_x ... };
Coding Conventions
No whitespace after a method name and the opening left parenthesis. Curly braces on the same line as the if, for, while or switch statement. Curly braces on a new line for method implementations. No tabs in source files. Indenting for a given source file should be 100% consistent and be 2 spaces.
License Information
The following comment will used at the top of every source file:/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public License * Version 1.0 (the "NPL"); you may not use this file except in * compliance with the NPL. You may obtain a copy of the NPL at * http://www.mozilla.org/NPL/ * * Software distributed under the NPL is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL * for the specific language governing rights and limitations under the * NPL. * * The Initial Developer of this code under the NPL is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */Note that this comment is taken from the Netscape Public License, which may change. Thus, please check the license page for specific language. Note too that as a developer who is not working at Netscape, you may be interested in submitting your source code under the Mozilla Public License, which differs from the Netscape Public License. We are not lawyers; this is not legal advice. More information is available from our license page.