Convention and Standards
Convention and Standards
2.1.Naming Conventions
In computer programming, a naming convention is a set of rules for choosing the character
sequence to be used for identifiers which denote variables, types and functions etc. in source
code and documentation. If the first letter is capitalized, it is called Pascal case; if not, then
camel case.
2.1.1. Variables
a. Use camel casing for local variable names and method arguments i.e.
function MyMethod(elapsedTime) {
var time;
};
2.1.2. Functions/Methods
a. Use Pascal casing for type and method names i.e.
function MoveTool() {
MoveTools.prototype.SelectTool = function() { }
};
b. Name method using verb-object pair, such ShowDialog
2.2.Style
Programming style is a set of rules or guidelines used when writing the source code for a
computer program. It is often claimed that following a particular programming style will help
programmers to read and understand source code conforming to the style, and help to avoid
introducing errors.
function MyMethod() {
};
3. Coding Practices
a. Always copy the current working version to a scratch space to do any development; no one
should alert the working version other than the integration team
b. Avoid putting multiple classes in one file
c. Avoid methods with more than 200 lines
d. Lines should not exceed 80 characters
e. Avoid comments that explain the obvious. Code should be self-explanatory. Good code with
readable variable and method names should not require comments
f. Document only operational assumptions, algorithm insights and so on
g. If declaring a class always declare a class variable that is equal to ‘this’ to be used to reference
variables and perform method calls
h. With the exception of zero and one, never hard-code a numeric value; always declare a constant
instead
i. Every line of code should be walked through in a “white-box” testing manner
j. Catch only exceptions for which you have explicit handling
k. Always use a curly brace scope in an if statement, even if it conditions a single statement
l. Never hardcode strings that will be presented to end users, use resources instead
m. Never hardcode strings that might change based on deployment such as connection strings
Just like everything in JavaScript classes can be built several different ways. With the development
of this project our developers have create a framework and a template for all classes. If you need to
create a class that needs to be initialized then use the following template
bimjs.provide('bimjs.TEMPLATE');
bimjs.require('bimjs.scene');
/**
* A module for TEMPLATE.
* @namespace
*/
bimjs.TEMPLATE = function () {
var self = this;
this.classLevelVariable = 0;
bimjs.TEMPLATE.prototype.FunctionName() { };
};
Note that bimjs.provide tells the framework that this class provides the following framework and
that bimjs.require indicates that this class is dependent on another one (like the avatar class is
dependent upon the scene class).
Now if you need to create a static class use the following template
bimjs.provide('bimjs.TEMPLATE');
/**
* A Module for a template static class.
* @namespace
*/
In closing this document is subject to change under the direction of the lead developers. When
changes are made to this document is the responsibility of the individual who makes the change to
inform the development team