- Follow the GNOME HIG Writing Style
- Use Adwaita's Style Classes
- Mark user-visible strings as translatable (e.g.
_("Example")
) - Prefer high-level widgets like
Adw.StatusPage
andGtk.Stack
- Prefer properties like
Gtk.Box:spacing
toGtk.Widget:margin-top
for layout - Avoid hard-coded height and width, except for e.g. images with fixed geometry
- Prefer HIG terms (Radio Groups, Checkboxes) over technical ones (Checkbuttons)
- If you need icons, it is possible to use custom icons but prefer included Adwaita icons set.
- Use Adwaita's Named Colors
- Use Adwaita's Style Classes
- Use 2-space indentation for all elements
- Use one space between colon and values (e.g.
property-name: value;
) - Use double-quotes for strings (e.g.
"quoted"
)
- Use 2-space indentation for all elements
- Use one space between colon and values (e.g.
property-name: value;
) - Use double-quotes for strings (e.g.
"quoted"
) - Mark user-visible strings as translatable (e.g.
_("Example")
)
Prefix the object id with the name of the class.
- KO:
next_button
- OK:
button_next
// OK
Parent {
child: Box {
property-name: value;
};
}
// NOT OK
Parent {
child:
Box {
property-name: value;
};
}
- Use construct-time properties, when possible
- Use properties (eg
widget.sensitive
) over methods (egwidget.set_sensitive
)
- Prefer
async
/await
- Use ESModules for imports
- Do not use
async
signal handlers, instead usemyFunction().catch(logError)
- camelCase for functions for example
function openFile
- snake_case for variables/constants for example
const button_ok
- Use named functions except for inline callbacks where you should use anonymous functions
- Use 2-space indentation for all elements
Gio._promisify()
should be directly below theimport
statements
- All errors should be caught using
console.error
Please see existing code, or ask. Add anything you learn here.
- Prefer
async
/yield
- snake_case for functions for example
open_file
- Type identifiers in
CamelCase
- Enum members and constants in
ALL_CAPS
, words seperated by underscores - implcit typing with
var
only when the type is obvious due to the assignment, for examplevar foo = new Window ();
- only use casting with
as
when you also check the variable fornull
afterwards - Make valadoc style code comments when it makes sense
- Use functions-in-functions when the same handler needs to be connected to multiple signals
- Use
@"blub $foo blob $(bar.baz)\n"
instead of"blub " + foo.to_string() + ...
- Errors should be catched with
try { ... } catch { ... }
- For enum members, use
button.valign = CENTER
instead ofbutton.valign = Gtk.Align.CENTER
where possible - Initialize objects with properties where possible:
// OK
var button = new Gtk.Button () {
label = "Click Me!",
halign = CENTER,
css_classes = { "suggested-action", "pill" }
};
// NOT OK
var button = new Gtk.Button ();
button.label = "Click Me!";
button.halign = CENTER;
button.add_css_class ("suggested-action");
button.add_css_class ("pill");
- Use 4-space indentation
- Property get, set, default declaration all on one line, seperated by semicolons, if default implementations are used
- If properties have implementations, then
get {
,set {
open new lines - Attributes on their own line
- Use
message ()
,warning ()
andcritical ()
for debug messages (depending on the severity) - Use
print ()
/stdout.printf ()
for messages that are intended to be seen by the user