Naming Conventions

File Extensions

All JS++ source code files should end with the .jspp or .jpp file extensions. All compiled JS++ files should end with the .jspp.js or .jpp.js file extensions.

Variables and Functions

1
2
3
4
var lowerCamelCase;
function lowerCamelCase() {
    // ...
}

All variables and functions should be in lowerCamelCase. This means that all variable identifiers and function names should begin with a lowercase letter. Each subsequent new word should begin with an uppercase letter.

Example:

Phrase: My Pet Dog
lowerCamelCase: myPetDog

Classes, Modules, and Enums

1
2
3
4
5
6
module UpperCamelCase {
    class UpperCamelCase {
        public var myField = 1;
        public void myMethod() { }
    }
}

Classes and modules should be in UpperCamelCase. This means that all class names and module identifiers begin with an uppercase letter. For class fields and methods, use lowerCamelCase just as you would for variables and functions.

Example:

Phrase: My Pet Dog
lowerCamelCase: myPetDog
UpperCamelCase: MyPetDog

In addition, organization-specific code should be organized under a root namespace with the company name. Libraries and products should be featured directly under the company's root namespace, with all sub-modules to follow. For example:

Example:

Organization: Onux
Root Namespace: Onux
Library Name: Vendor.Onux.MyCustomLibrary Sub-modules: Vendor.Onux.MyCustomLibrary.Tests

Interfaces

1
2
3
interface IFoo {
    // ...
}

Interfaces should be in UpperCamelCase and should always be prefixed with "I" (uppercase i).

Example:

Phrase: My Pet Dog
Interface: IMyPetDog

Generic Type Parameters

1
2
3
4
class AssociativeArray<K, V>
{
    // ...
}

Generic type parameters should be uppercase letters.

Common naming schemes for type parameters include:

Name Description
TType. Most common (like i for for loops)
S, U, V, ...Second, third, fourth types and so on if T was the first type parameter. (Like j, k, and so on for for loops)
KKey (e.g. in a key-value pair)
VValue (e.g. in a key-value pair)
EElement (e.g. in a collection)
NNumber (e.g. if constrained to numeric reference types)

Constants

1
2
final string UPPERCASE;
final int JAVASCRIPT_PLUS_PLUS;

For constants, use all UPPERCASE identifiers. When there is more than one word in the constant, use underscores (_) to space them apart.

Loop Counters

1
2
3
for (int i = 0; i < 5; ++i) {
    // ...
}

The counter variable used in a loop (e.g. a for loop) should be named i, j, or k. The order is sequential. Therefore, with nested loops, the topmost loop will have a counter variable named i, while the first nested loop will have a counter variable named j, and so on.

Prototypes

1
2
3
4
function MyConstructorFunction() {
}
MyConstructorFunction.prototype.fooBar = 1;
MyConstructorFunction.prototype.baz = 2;

With prototypal inheritance, constructor functions are UpperCamelCase. The properties of both the instance and the prototype object are lowerCamelCase.

Example:

Phrase: My Pet Dog
lowerCamelCase: myPetDog
UpperCamelCase: MyPetDog

Share

HTML | BBCode | Direct Link