Coding style

Wiki page by khorben on 28/10/2010 03:10:42

General rules

Indenting and spaces

Throughout all of the project, a tab spacing of 8 spaces has been used. This is the default on most platforms, and the only one tolerated for the project. Most text editors can be set to other tab sizes at your convenience, and still save files with the adequate size when configured properly.

Likewise, a maximum width of 80 characters per line is enforced, for the following reasons:

  • it is easier to read shorter lines,
  • more generally, to maintain readability on each and every text console,
  • to be also as readable as likely on even smaller screens (eg embedded devices)
  • to enforce source code to be written with a maximum of three sub-scopes per function.

Generally speaking, the natural indenting algorithm of the Vim text editor is considered the correct one. Exceptions to this rule are documented in the files concerned, by means of a Vim modeline (like for most XML files).

Spurious spaces at the end of lines, or lines containing solely white-space characters are forbidden.

Specific to the C programming language

Any function and variable that is not meant to be exported (available to other objects) must be declared "static", and prefixed with an underscore ("_").

The code is written in an object-oriented manner wherever possible, considering objects as pointers to hidden structs (through typedef definitions). Header files should be organized as follows:

/* $Id: Coding\040style,v 1.7 2013/12/15 02:55:54 khorben Exp $ */
/* Copyright (c) Year Full Name <email@addre.ss> */
/* This file is part of DeforaOS Category Package */
/* License terms */



#ifndef PACKAGE_FILENAME_H
# define PACKAGE_FILENAME_H

# include <header.h>
# include "optional.h"


/* Class */
/* public */
/* types */
typedef struct _Class Class;


/* functions */
Class * class_new(void);
void class_delete(Class * class);

/* accessors */
void class_set(Class * class, ...);

/* useful */
void class_operation(Class * class, ...);

#endif /* !PACKAGE_FILENAME_H */

Likewise, source code should be presented as follows:

/* $Id: Coding\040style,v 1.7 2013/12/15 02:55:54 khorben Exp $ */
/* Copyright (c) Year Full Name <email@addre.ss> */
/* This file is part of DeforaOS Category Package */
/* License terms */



#include <other.h>
#include "class.h"


/* Class */
/* private */
/* types */
struct _Class
{
Revisions
NameDateAuthorMessage
1.7 (diff)khorben
1.6 (diff)khorben
1.5 (diff)khorben
1.4 (diff)khorben
1.3 (diff)khorben
1.2 (diff)khorben
1.1khorben