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.

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.

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.3 2010/10/28 01:02:45 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.3 2010/10/28 01:02:45 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
{
        /* ... */
};


/* constants */


/* variables */


/* prototypes */
static void _class_helper(Class * class, ...);


/* public */
/* functions */
/* class_new */
Class * class_new(void)
{
        Class * class;

        return calloc(1, sizeof(*class));
}


/* class_delete */
void class_delete(Class * class)
{
        free(class);
}


/* accessors */
void class_set(Class * class, ...)
{
        /* ... */
}

/* useful */
void class_operation(Class * class, ...)
{
        /* ... */
}


/* private */
/* functions */
static void _class_helper(Class * class, ...)
{
        /* ... */
}

Specific to the Gtk+ library

Any function that is not available in Gtk+ 2.4 should not be relied upon; the program must compile and work normally without them. It is encouraged to use newer, better functions when available; they must however be accompanied by an alternative version of the code (which may have less features).

Dialog windows should use the GtkDialog class by default.
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