Commit 174293a7 authored by Guido Gunther's avatar Guido Gunther

HACKING: Use syntax highlighting

This makes it a bit nicer to read in gitlab while still looking o.k. in
an editor.
parent 3c3a11d6
......@@ -6,7 +6,9 @@ Pull requests
=============
Before filing a pull request run the tests:
ninja -C _build test
```sh
ninja -C _build test
```
Use descriptive commit messages, see
......@@ -32,14 +34,18 @@ what GNOME upstream projects do.
*Good*:
static gboolean
button_clicked_cb (HdyDialerCycleButton *self,
GdkEventButton *event)
```c
static gboolean
button_clicked_cb (HdyDialerCycleButton *self,
GdkEventButton *event)
```
*Bad*:
static gboolean
button_clicked_cb (HdyDialerCycleButton *self, GdkEventButton *event)
```c
static gboolean
button_clicked_cb (HdyDialerCycleButton *self, GdkEventButton *event)
```
Braces
......@@ -48,16 +54,20 @@ Everything besides functions and structs have the opening curly brace on the sam
*Good*:
if (i < 0) {
...
}
```c
if (i < 0) {
...
}
```
*Bad*:
if (i < 0)
{
...
}
```c
if (i < 0)
{
...
}
```
Signals
......@@ -66,11 +76,13 @@ Prefix signal enum names with *SIGNAL_*.
*Good*:
enum {
SIGNAL_CYCLE_START = 0,
SIGNAL_CYCLE_END,
SIGNAL_LAST_SIGNAL,
};
```c
enum {
SIGNAL_CYCLE_START = 0,
SIGNAL_CYCLE_END,
SIGNAL_LAST_SIGNAL,
};
```
Also note that the last element ends with a comma to reduce diff noise when
adding further signals.
......@@ -82,11 +94,13 @@ Prefix property enum names with *PROP_*.
*Good*:
enum {
PROP_0 = 0,
PROP_CYCLE_TIMEOUT,
PROP_LAST_PROP,
};
```c
enum {
PROP_0 = 0,
PROP_CYCLE_TIMEOUT,
PROP_LAST_PROP,
};
```
Also note that the last element ends with a comma to reduce diff noise when
adding further properties.
......@@ -97,11 +111,15 @@ In comments use full sentences and proper capitalization, punctation.
*Good*:
/* Make sure we don't overflow. */
```c
/* Make sure we don't overflow. */
```
*Bad:*
/* overflow check */
```c
/* overflow check */
```
Callbacks
......@@ -110,11 +128,15 @@ Signal callbacks have a *_cb* suffix.
*Good*:
g_signal_connect(self, "clicked", G_CALLBACK (button_clicked_cb), NULL);
```c
g_signal_connect(self, "clicked", G_CALLBACK (button_clicked_cb), NULL);
```
*Bad*:
g_signal_connect(self, "clicked", G_CALLBACK (handle_button_clicked), NULL);
```c
g_signal_connect(self, "clicked", G_CALLBACK (handle_button_clicked), NULL);
```
Static functions
......@@ -123,15 +145,19 @@ Static functions don't need the class prefix. E.g. with a type foo_bar:
*Good*:
static gboolean
button_clicked_cb (HdyDialerCycleButton *self,
GdkEventButton *event)
```c
static gboolean
button_clicked_cb (HdyDialerCycleButton *self,
GdkEventButton *event)
```
*Bad*:
static gboolean
foo_bar_button_clicked_cb (HdyDialerCycleButton *self,
GdkEventButton *event)
```c
static gboolean
foo_bar_button_clicked_cb (HdyDialerCycleButton *self,
GdkEventButton *event)
```
Note however that virtual methods like
*<class_name>_{init,constructed,finalize,dispose}* do use the class prefix.
......@@ -146,26 +172,30 @@ non public function:
*Good*:
static gboolean
expire_cb (FooButton *self)
{
g_return_val_if_fail (BAR_IS_FOO_BUTTON (self), FALSE);
...
return FALSE;
}
```c
static gboolean
expire_cb (FooButton *self)
{
g_return_val_if_fail (BAR_IS_FOO_BUTTON (self), FALSE);
...
return FALSE;
}
```
And for a public function:
*Good*:
gint
foo_button_get_state (FooButton *self)
{
FooButtonPrivate *priv = bar_foo_get_instance_private(self);
```c
gint
foo_button_get_state (FooButton *self)
{
FooButtonPrivate *priv = bar_foo_get_instance_private(self);
g_return_val_if_fail (BAR_IS_FOO_BUTTON (self), -1);
return priv->state;
}
g_return_val_if_fail (BAR_IS_FOO_BUTTON (self), -1);
return priv->state;
}
```
User interface files
--------------------
......@@ -178,11 +208,15 @@ Use minus signs instead of underscores in property names:
*Good*:
<property name="margin-left">12</property>
```xml
<property name="margin-left">12</property>
```
*Bad":
<property name="margin_left">12</property>
```xml
<property name="margin_left">12</property>
```
Automatic cleanup
-----------------
......@@ -191,13 +225,17 @@ automatic resource cleanup when possible.
*Good*:
g_autoptr(GdkPixbuf) sigterm = pixbuf = gtk_icon_info_load_icon (info, NULL);
```c
g_autoptr(GdkPixbuf) sigterm = pixbuf = gtk_icon_info_load_icon (info, NULL);
```
*Bad*:
GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
...
g_object_unref (pixbuf);
```c
GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
...
g_object_unref (pixbuf);
```
Using the above is fine since libhandy doesn't target any older glib versions
or non GCC/Clang compilers at the moment.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment