Coding Specifications --------------------------------------------------------------------------- SPIDERtel is currently working on a formal coding specifications document that defines all elements of PHP, HTML, ASP, and JavaScript proper and standard coding rules. These rules pertain to the way in which indentation, variable naming, and source module layout should be done. For now, please excuse the brievity of this document, spelling errors, grammer, etc. I'm hoping the code examples will speak for themselves. PHP ---- The dGrid object gives an excellent example of how I will expect PHP code to look. All code should be indented with tabs ONLY. Please do not use spaces for indents at any level. The simple reason for this is that all programmers have different feelings about the number of spaces that a single tab should represent. If tab characters are used, then any developer can set up their tabbing to 2 or 4 or 8 characters wide and regardless of who writes the module, the tabs will look correct within each programmer's editor. All braces should be placed on a line by themselves. For example, we prefer if ($var == 3) { // Do multiple things } To if ($var == 3) { // Do multiple things } If the conditional block contains only a single statement, then we do NOT use braces at all, i.e. if ($var == 3) $var == 4; This should be done for PHP and JavaScript both. When it comes to string concatenation, please use the '.' string concatenator instead of inserting the variables inside of a string: $val = "text"; $str = "This is some: " . $val; Instead of: $str = "This is some: $val"; The reason is that using the dot concatenator is much faster than including the variable within the string. When coding PHP, please use consistent indentations: foreach ($ary as $key => $val) if ($key == "number") if ($val == "0") print $key . " => " . $val . "\n"; Statements such as "if" and "for" are NOT functions and therefore should NOT be placed immediately adjacent to their (), i.e. if ($val == 3) The following is NOT correct: if($val == 3) If we're calling a function, then the parens should be placed adjacent to the function name: function my_func($val = "") { return $val; } Calling this function: $var = my_func(3); This is NOT proper: $var = my_func (3); ------------------------------------------------------------------------- JavaScript All of the placement rules and indenting rules do NOT apply to JavaScript. The reason that we throw these out is to save space and bytes when delivering javascript to a web browser. However, just because we do not have the same requirements, we do not expect the code to be messy. An example of good code in JavaScript is as follows: Note that we use spaces to indent with - not a problem in JavaScript. Note that we allow the conditional statement to be immediately adjacent to the 'if' statement. All of these things are done in the interest of saving space - but in the process we do not sacrifice readability by using no indent at all. Variable names are kept short, but not to single character names. Quality still needs to exist, even though we have sacrificed some level of readability.