This site has been retired. For up to date information, see handbook.gnome.org or gitlab.gnome.org.


[Home] [TitleIndex] [WordIndex

1. CodingStyle

1.1. C

1.1.1. Introduction

The coding style is based on a number of reference models.

  1. First and foremost, we recommend reading Linus' Linux Kernel Coding Style. We take almost everything from that and it highlights all of our practises and things we try to avoid. It is also quite amusing in places.

  2. The GNOME Coding Style also expands on #1 and we also embrace these values.

Everything that follows is modification upon these existing styles. Some of what we mention below is already mentioned in the guides above, however, we will re-iterate them here for completeness.

We encourage you to follow the Tracker coding style throughout the Tracker project. For the core components (application and libs) this coding style is enforced.

1.1.2. Includes

NOTE: Some of these principles are taken from the GIMP documentation and have been in use for some time.

1. All .h files should not include anything, with two exceptions:

2. All .c files should have the following include order and have adequate spacing between groups:

#include "config.h"             /* alyways and first                         */

#include <glib.h>               /* *only* needed if the file needs stuff     */
                                /* like G_OS_WIN32 for conditional inclusion */
                                /* of system headers                         */

#include <system headers>       /* like <stdio.h>                            */

#include <glib-object.h>

#include <libtracker-sparql/tracker-sparql.h> 
                                /* see next section for when to include      */
                                /* top level header or specific headers      */

#include "module/foo.h"         /* files from modules below this one         */
#include "module/bar.h"

#include "gimp.h"               /* files from this module                    */
#include "gimpimage.h"
#include "gimpwhatever.h"

3. Each library has a top level include file, e.g. tracker-sparql.h. This includes all other headers needed for the library. For future compatibility:

1.1.3. Indentation & Spacing

1.1.4. Functions

1.1.4.1. Declarations

1.1.4.2. Prototypes

This includes in header files or prototyping in the same file:

1.1.5. Macros & Enums

1.1.6. Structures & Types

1.1.7. Conditions

1.1.8. Switches

1.2. Vala

The coding style for Vala isn't too dissimilar to C. We stick to the Vala Coding Style as documented.


2024-10-23 10:59