Changes

Jump to: navigation, search

OOP344 Temporary

6,483 bytes removed, 02:07, 29 October 2009
Coding Standards OOP344 northWind87: Moved coding standards to their own page and linked them here
== Coding Standards ==
Coding standards are important if we want code to be readable. Now the idea of these rules is that they're "common sense" with readability in mind. The most important section is the commenting section as it is basically arbitrary while all the others should be more or less common sense. In any case, the entire thing is up here for reference purposes. We should all attempt to follow these guidelines when writing code.<br/><br/>While no one will be prosecuted or killed if they forget one or more of these, the others will gently '''remind''' the person in question to '''follow the guidelines''' :) === Naming Conventions ===* ''' Camel Notation ''' should be used for variable names and function names ** ''' ie ''' <code>myVar, bigInt, getNumber(), myFunction()</code>* Class names should always be ''' First-Letter Capitalized '''** ''' ie ''' <code>TestClass, DynamicStack, PeanutButter, Hammer</code>* Compiler directives should always be written in ''' All Lowercase '''** ''' ie ''' <code>#define, #ifndef</code>* Compiler definitions should be ''' All Uppercase ''' and should only use underscore where a gap is required ** ''' ie ''' <code>IO_CTL_LARGEFILE, SOME_DEFINITION</code>* Header file defines should be preceeded and followed with ''' Two Underscores '''** ''' ie ''' <code>__CIOL_H__, __IO_FORM_H__</code> === Other Conventions ===* Pointer declaration should ''' emphasize the type ''' with the <b>"*"</b> being pushed against the right side of the data type as opposed to the left side of the variable name.** ''' ie ''' <code>char* str, int* num, void* addr</code>* Binary operators should now have a space between them and their constituents ('''Note:''' This does not apply to unary operators such as ++ or own page [[OOP344_Temporary_CodingStandards | here]]).** ''' ie ''' <code>x = 7, z += y, int i = 10, judge = y > 5</code>* As well, please leave a space after every comma and every semicolon if something follows it.** ''' ie ''' <code>foo(int firstInt, int secondInt, int thirdInt), x = bugSquish(parm1, parm2), for (int i = 0; i < 10; i++)</code>* When indenting, please indent by using ''' two spaces ''' as opposed to the tab character as the tab character changes size between systems** ''' ie '''<pre>if (x == y) { doStuff(); doSomeMoreStuff();}</pre>* Finally, <code>void</code> should always be explicitly declared.** ''' ie ''' <code>void doStuff(void), int getInt(void)</code> === Statement Notation ===The first left parenthesis on a function declaration should open immediately after the function name while the first left parenthesis on a loop declaration should open one space after the loop declaration.<br />''' ie Functions: '''<pre>int hello(char goodbye(void getQuestion(</pre> ''' ie Loops: '''<pre>while (for (do (</pre> In the same sense, the first left parenthesis should immediately follow the function name when a function is called.<br/>''' ie ''' <code>x = getInt(), someInt = y + bigSum(y, r)</code> === Code Blocks ===Both function blocks and loop blocks should open on the same line as the declaration statement preceding them; however, function blocks should open immediately after the last right parenthesis while loop blocks should open one space after the last right parenthesis.<br />''' ie Functions: '''<pre>int hello(){char goodbye(){void getQuestion(void){</pre> ''' ie Loops: '''<pre>while (var < 15) {for (int i = 0; i < 15; i++) {do (blah) {</pre> === Comment Blocks ===All functions should have a comment block preceding them which should explain what the function does in a few brief sentences, what parameters it receives with each parameter having a section preceded by <code>@param</code>, and anything that the function may return preceded by <code>@return</code> at the end of the block. Try to keep things lined up so that they're easier to read. Here is an example from Assignment 1 utilizing the io_strcpy() function:<pre>/*Copies a given number of characters from one string to another. *Self copying is allowed. Does not stop at null-terminator, always copies *the given number of characters. * *@param const char* src address from which to copy characters. *@param char* dest address to which characters will be copied. *@param int n number of characters to copy. * *@return the address of dest if copy was successful, NULL otherwise. */char* io_strcpy(char* dest, const char* src, int n){</pre>Commenting within the function should be generally organized, that's about it for in-function commenting. As well, please ensure that a small commented header is at the top of every file (implementation if .cpp or header if .h). It should contain information such as the file name, project name, last modified date, last modified by, etc...Using the example of ciol.c from assignment 1, it should be in the following form:<pre>/* ########################################################################## Project: OOP344 Assignment 1 File Name: ciol.c File Desc.: Implementation file for console input output (CIOL) library.  Last Changed By: $Author$ Last Changed Date: $Date$ Last Changed Rev: $Rev$ ##########################################################################*/</pre> When you commit the file, the $ keywords will be expanded automatically by svn to look like the following<pre>/* ########################################################################## Project: OOP344 Assignment 1 File Name: ciol.c File Desc.: Implementation file for console input output (CIOL) library.  Last Changed By: $Author: ops344_093svn111 $ Last Changed Date: $Date: 2009-10-28 12:14:38 -0400 (Wed, 28 Oct 2009) $ Last Changed Rev: $Rev: 8 $ ##########################################################################*/</pre> SVN is expanding these keywords because of the <code>$Author$ $Date$ $Rev$</code> keywords and the svn:keywords property. <code>Author</code> will show the last person to have modified the file, <code>Date</code> will show the date that this file was last modified on, and <code>Rev</code> will indicate the revision at which this file was last changed. The svn:keywords property has already been globally set and propagated so it's in full use right now and all files that need a header should have one in the specified format.<br/><br/>That's about it folks, feel free to add or remove anything if you feel so compelled but please consult the rest of the group first if it is a major change.<br/>
'''-northWind87'''

Navigation menu