Coding style
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.
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.5 2010/10/28 01:08: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.5 2010/10/28 01:08: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
{
/* ... */
};
/* 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).Generally speaking, any widget or function obsoleted at any point should be avoided whenever possible.
Dialog windows should use the GtkDialog class by default.
Any spacing set manually between widgets should be set to 4 pixels. This is easily managed through GtkHbox and GtkVbox:
- use gtk_vbox_new(TRUE/FALSE, 4) or gtk_hbox_new(TRUE/FALSE, 4)
- pack widgets with zero additional spacing, as in gtk_box_pack_start(GTK_BOX(vbox), widget, FALSE, TRUE, 0)
- spacing between the box and its container should be set with gtk_container_set_width()
Tree views should be displayed with the rules hint set only when it improves readability.