2012-10-16

Coding guidelines

It is time to start merging the codes from the different groups. Unfortunately we have all used different techniques and no file structure. We have now agreed upon some standard that we are going to use in the final product.

First of, the file structure layout:
/
    js/
         lib/  -- here goes external libraries that we haven't coded ourselves
         -- here goes our own javascript code
    css/ -- here goes all css files
    img/ -- here we have all static images
    -- here goes html files

It is a very simple layout, it might expand if needed.

Since the different groups have used different coding styles the common ground that we agreed on is trying to minimize global variables and functions and use prototype to create objects. Each object or set of objects is stored in its own file. This way it is a lot easier to get a grip of the system, minimize coupling, easier maintainability etc.

A short simplified example of the system using prototype. We will use these styles when creating classes and their methods. This content will be written in a file called ClassName.js

function ClassName(varA, varB) {
this.a_ = varA; // Private
this.b = varB; // Public

/* One way of creating functions */
this.getB = function() {
return this.b;
}
}

/* Another way of creating functions */
ClassName.prototype.getA = function() {
return a_;
};


We also agreed on some naming convention. Just some basic stuff. Each class have to start with a capital letter. All variables and functions start on a lower case letter. If a name is a composition of multiple names it may look something like this: yourName. Not underscore like your_name. Constants are named with capital letters and underscores, eg. YOUR_CONSTANT.

For indentation a tab character is used. NOT spaces.

In this way we hope to get more readable code and a structure that gives a good overview and easier maintenance.

jQuery is used for manipulating the html code, hide divs etc.

No comments:

Post a Comment