Istanbul Bilgi University Department of Computer Science
Previous Home > Standards Project > Programming Standards Draft Next
Home
   About This Site
   Academic Policies
   Academic Staff
   Courses
   Curiosity Corner
   High School Computer Clubs Project
   Lab Rules
   Links
   Member Help
   News
   Other Stuff
   Standards Project
      Doc. Resource 111
      Doc. Standards
      Java CodingStyle (pdf)
      Programming Standards
      Programming Standards Draft
      Report Guideline
      Rules For Good Programming
      Sortlistweek6 (pdf)
   Turing Days
   Usage Statistics
   Yarışma

 
Programming standards (draft)

This is intended to be a proposal for a joint coding standard for all the C family programs written in the department.

So with some differences marked in the text, this should cover C, C++, Java, PHP and the other languages that resemble C syntactically

As these are suggestions I have indicated preferences by reference to exiting standards.
 

Indentation and bracketing.

GNU style curly brackets (start on a new line), Torvalds style indentation ( tabs, tab set to 8).
All other layout Torvalds style.
 

Naming

Classes (C++ and Java) start with a big letter.
methods, functions, variables start with a small letter
inFixCaps style (Each new word in a name starts with a big letter). No underscores in names.
local variable names should be short, class level and/or global names should be descriptive
functions and method names should start with a verb.
variable names should start with a noun.
constants (Java statics) should be all caps (big letters)
set and get methods (C++ and Java) should be given anme sthat start with "set" and "get"
 

Readability

Do not use switch, do..while, break, goto.
Always curly bracket the clause following while, if, for, even it is only one statement.
Only use for for definite iteration - no "clever" programming with the for loop.
Only use global variables (or class level variables between methods in Java and C++) when absolutely necessary. (This is genrally only true when interfacing to code that you do not control  -counting the number of times qsort calls compare is a good example)
Always use access methods to "set" and "get" Class variables in Java and C++, even inside the class.
 

Comments

Every method and function ( except simple set and get methods and one line functions) should be preceded by a comment block in Sun Java style:-

/**
 * comments here
 *
**/

The comment block should include:
Purpose
Algorithm
Parameters and their exact meaning
Return value and its exact meaning
Side effects

Comments within functions/methods should be // style (this allows commenting out of blocks of code safely). Follow the Sun Java recommendations about alignement and spacing.

Data declarations of class level and global variables and constants (statics in Java) should be fully commented in // style with clear statements of valid value ranges and the meanings of the values. Local vraibale should only be commented when the meaning is not clear ( making it clear wouldbe a better alternative.)