General Coding Guidelines

Varun Juyal
Fri May 06 08:51:42 2016

Purpose

Create uniform coding habits

Benefits:

  • Maintainability, readability and reusability. Code walk-thrus become less painful
  • Reliability. Fewer mistakes and no personal style
  • Business productivity. Emphasis on business concerns

File and Directory Naming

Consistent naming convention as per project guidelines

Benefits:

  • Identify project files
  • Differentiate files e.g. fx_ or Pr_
  • Directories and sub-directories can be used to link projects together.

Procedure/Module/Package Design

  • Single cohesive and decoupled unit
  • Container or wrapper of source code
  • Calls generic and reusable procedures or functions
  • One source code file per procedure
  • Choose Meaningful name that signifies the purpose .e.g. EmpWiseDailyUtilReport

Source File Layout

  • Header
  • Imports/Includes
  • Constants and Macros definition
  • Data Types/Table types definitions
  • Variable definitions
  • Subroutines/Functions

Information Headers

Place a header at the beginning of each source file(function/procedure…) to include the following:

  • Copyright(if any)
  • File Name
  • Project Name
  • Brief description of the purpose
  • Input and output
  • Revision History notes

Functions/Subroutines/Procedures

  • Independent, cohesive and decoupled unit
  • Factor Repetitive sections
  • Choose meaningful names. e.g. _ or , getEmpid or get_empid
  • No more than one page

Variables & Comments

  • Choose meaningful variable names. e.g. , emp, signum
  • Add comments judiciously
  • Comments describe the logic/intent not syntax

Code Layout

  • One statement per line
  • Add comments
  • Consistent indentation for readability
  • Add blank line between each algorithm step

Error Handling

Anticipation, detection, and resolution of programming, application, and communications errors

Benefits:

  • Improves user experience
  • Aides debugging and hence maintainability

Report specific errors at the lowest level

Logging and Notifications

Log errors, debug information and performance statistics based on project need.

Benefits:

  • Aides debugging and troubleshooting
  • Gather trends
  • Perform Analysis

Use logging and notifications judiciously.

Questions