Files
iD/docs/coding_standards.txt
Richard Fairhurst 2adf722945 Docs updated
2012-07-12 18:30:48 +01:00

44 lines
1.4 KiB
Plaintext
Executable File

Coding standards and advice for iD
==================================
Classes
-------
All constructors must initialise objects and arrays. It is not enough to say
array:[],
constructor:function() {
},
but rather, you should do
array: null, // effectively a placeholder
constructor:function() {
this.array=[],
},
or bad things will happen. You should still declare the object outside the constructor, but for clarity rather than functionality.
(This doesn't apply to simple types - numbers, strings, booleans - which you can declare as normal.)
Function names
--------------
Anything that creates and calls an Action should be prefixed with do:
doSetLatLon(lat,lon)
Anything that is called by an Action, to do the actual work, should be prefixed with an underscore:
_setLatLon(lat,lon)
and commented as such. Underscores are also used to prefix private methods.
File naming
-----------
The filename should be the name of the base class. You can add subclasses within that file for clarity. Don't add extra classes that aren't subclasses, unless they're not referenced from elsewhere.
Layout
------
* Hard tabs, indent of 4.
* Do not indent the root level of the module. Add an 'End of module' comment instead.
Useful stuff to know about Dojo
-------------------------------
* The array and lang modules are full of useful add-ons to basic JavaScript functionality. lang/hitch will save your life with scopes.