Code guide - ParadoxZero/libgeneric GitHub Wiki

This guide may change.

This page describes coding style specifications used in the project including the naming convention for APIs and general structure.

Anything not specified in the guide is left upon the judgment of author.

Spaces instead of tabs

Intend code by using 4 spaces instead of tabs.

Naming conventions

APIs

  • All APIs should follow camel case and the first character should be g.
  • The first word of the API name should be the name of the container it manipulates.

E.g.

void* gStackCreate()

Local variables

All lower case. Avoid generic names like i, j, ptr etc. unless being used as an iterator.

E.g.

int array_length;

Constants

  • All caps, words separated by an underscore (_).

  • If a global constant, prefix it with g.

#define gGLOBAL_CONSTANT 10
#define LOCAL_CONST

const int gANOTHER_GLOBAL_CONST = 10;
const int ANOTHER_LOCAL_CONST = 10;

Code format

Braces

The opening brace should come next to the block header.

E.g.

int function() {
   // code
}

for (int i=0; i<5; ++i) {
    // do stuff
}

API design

The first parameter of any API should be a pointer to the container.

API should return an integer which would represent the status of the operation as defined in generic.h ( only if it is not retrieving any data, in that case gErrorCode must be set).

E.g

int gPushStack(gStack *, void *);

Doc Comments

Every header function should be preceded by a docstring. A docstring is a multiline comment which describes the functions.

Optionally it can contain a small example.

The format of doc string should be:

/**
 * Function: <function name>
 * ----------------------
 * < A brief explanation of API >
 *
 *  @param <param name>:    <param description>
 *
 *  @return:                <return value description>
 *
 */

E.g

/**
 * Function: gCreateList
 * ----------------------
 * Creates and initializes a List
 *
 *  @param itemSize:    The itemSize of data members that are to be stored.
 *
 *  @return:            A pointer to the List that was created.
 *
 *  Example
 *  To create a list to store integers.
 *      gList *list = gCreateList(sizeof(int));
 */
⚠️ **GitHub.com Fallback** ⚠️