STYLEGUIDE.md
September 23, 2024 · View on GitHub
Mingle Style Guide
1. General Coding Style
- Prefer
async/yeildfor asynchronous programming. - Use
snake_casefor all method and function names:- Example:
void perform_async_task()
- Example:
- Type identifiers should be in
CamelCase:- Example:
GtkButton,MyClass
- Example:
- Enum members and constants should be in ALL_CAPS:
- Use underscores to separate words.
- Example:
MY_ENUM_VALUE,MAX_RETRIES
- Implicit typing (
var) should only be used when the type is obvious:- Example:
var list = new List<int>();
- Example:
- Casting with
asshould only be done if you check fornullafterward:var button = widget as Gtk.Button; if (button != null) { // Safe to use button } - Use string interpolation with
@"..."for cleaner string concatenation:var name = "Alice"; message(@"Hello, $name!");
2. Object Initialization
- Use inline property initialization whenever possible. This makes the code cleaner and easier to read:
- Preferred:
var button = new Gtk.Button() { label = "Click Me!", halign = Gtk.Align.CENTER, css_classes = { "suggested-action", "pill" } }; - Not Preferred:
var button = new Gtk.Button(); button.label = "Click Me!"; button.halign = Gtk.Align.CENTER; button.add_css_class("suggested-action"); button.add_css_class("pill");
- Preferred:
3. Properties and Accessors
- Use property syntax for getters and setters instead of manually declaring methods:
public int count { get; private set; }
4. Logging and Messaging
- Use
message(),warning(),critical()for logging debug information:message(): General informational messageswarning(): Warnings that don’t require immediate action but could lead to issuescritical(): Serious issues that need immediate attention
message("Process started."); warning("Low memory."); critical("File not found."); - Use
print()orstdout.printf()for messages intended for users:print("Process complete."); stdout.printf("User %s logged in\n", username);