2.1 KiB
Bazaar Code Style Rules
Thanks for your interest in contributing to Bazaar! Here are the code style rules which you must adhere to in order to keep a clean and consistent codebase:
Formatting
Bazaar uses the GNU C style. The .clang-format file at the root project
directory will configure clang-format to follow the proper conventions.
General Rules
-
Always prefer using
g_auto,g_autofree,g_autoptr,g_autolist, andg_autoslistover calling*_unrefor*_freemanually. If a variable needs to escape the scope, either increment its reference count or useg_steal_pointer. -
When you are otherwise forced to call
*_unrefor*_freemanually, always useg_clear_pointerorg_clear_object. This prevents use-after-free bugs. -
Always prefer using the libdex API over the older GTask API for async operations. It is cleaner and easier to read, and it prevents callbacks from cluttering the source file. This often means spawning a fiber and using
dex_await. To wrap a call to a function which uses GTask, use dex_async_pair_new. Seesrc/bz-download-worker.cfor an example of this. -
Always declare variables first and initialize them to
0orNULL. Function calls must not be made in the declaration section of a scope. -
The general layout of a
.cfile must be in this order:- License comment with your name mentioned
#include "config.h"- Include external headers, like
#include <gtk/gtk.h> - Include internal headers, like
#include "env.h" - If applicable, define the class's internal struct
- If applicable,
G_DEFINE_TYPE (...)or equivalent - If applicable, the property enums and
static GParamSpec *props[LAST_PROP] = { 0 }; - Declare static functions (which are not virtual methods)
- If applicable, define class virtual methods (
dispose,class_init,snapshot, etc) - Define the public API (non-
staticfunctions which were declared in this.cfile's associated.hheader file) - Define the static functions which were previously declared in this file