This document is to present an updated version of a coding standards that I had written to be used by a company and updated for another. I indicate those standards that are not applicable to Ramapo Courses. Note every company will have coding standards, but the lack of them can lead to a lot of problems.
All new code was require to adhere to these standards. (New standards do not usually require that old code be modified to meet them.) The reason that these coding standards were created was to support the development of code that is easy to read, debug, maintain, and replace. This standard was for code written in C++ and C. There is still a LOT of legacy C code around.
Note: coding standards can cause a lot of fights. An an entry level programmer, you don't get much choice. If your company has coding standards, you live by them or quit. Some people good weird about standards. I once had an experienced programmer freak out over capitalization.
/**/
/*
spmLongShort::processNewOpens() spmLongShort::processNewOpens()
NAME
spmLongShort::processNewOpens - processes new opens for this model.
SYNOPSIS
bool spmLongShort::processNewOpens( spmTrObj &a_obj, double a_capital
, Jar::Date a_date );
a_obj
--> the object to be opened.
a_capital --> the amount of capital to apply.
a_date
--> the date we are processing in the simulation.
DESCRIPTION
This function will attempt to open the object a_obj with the
specified amount of capital. Before attempting the open, it
will apply portfolio constraints. If any of the portfolio
constraints are not met, this object will be opened as a phantom.
The status flags and phantom flag will be set appropriately.
RETURNS
Returns true if the open was successful and false if it was
opened
as a phantom. One of those two
cases will always occur.
AUTHOR
Victor Miller
DATE
6:27pm 9/1/2001
*/
/**/
void
spmLongShort::processNewOpens( spmTrObj &a_obj, double a_capital, Jar::Date a_date )
{
The "/**/" will allow the function description to be parsed
from the code for external documentation. There are
products available to parse out comments.
After the closing brace of the function implementation
there should be a comment appended that contains the function
prototype. For the current example, it would be:
/*void spmLongShort::processNewOpens( spmTrObj &a_obj,
double a_capital, Jar::Date a_date ); */
This comment allows us to know the function we are viewing
even if the beginning is not visible.
Note: If you are using C#, it automatically generates a template
similar to the comment header
that I described. So, for C# programmers, you may used
this template, as long as you
supply the same information.
// Badly written code.
if( condA == OK ) {
if( condB == OK ) {
do_something();
return OK;
} else {
return ErrorB;
}
} else {
return ErrorA;
}
// Rewrite for better flow.
if( condA != OK ) {
return ErrorA;
}
if( condB != OK ) {
return ErrorB;
}
do_something();
return OK;