Back to all reviewers

Encapsulate implementation details

ghostty-org/ghostty
Based on 3 comments
Other

When designing APIs, create appropriate abstractions that hide platform-specific or low-level implementation details from consuming code. Avoid exposing raw interfaces outside their designated modules and minimize unnecessary dependencies.

API Other

Reviewer Prompt

When designing APIs, create appropriate abstractions that hide platform-specific or low-level implementation details from consuming code. Avoid exposing raw interfaces outside their designated modules and minimize unnecessary dependencies.

Good Practice:

  • Isolate platform-specific code in dedicated modules
  • Use abstractions that hide underlying implementation complexity
  • Only bind to resources that are actually used
  • Consider direct imports for external dependencies when appropriate

For example, instead of binding to an unused protocol:

// AVOID: Unnecessary binding that adds dependencies
if (registryBind(
    xdg.WmDialogV1,
    registry,
    global,
)) |wm_dialog| {
    context.xdg_wm_dialog = wm_dialog;
    return;
}

Instead, simply check if the protocol is available without binding:

// BETTER: Just compare against the name and set a flag
if (isProtocolSupported(registry, global, "xdg_wm_dialog")) {
    context.has_wm_dialog_support = true;
    return;
}

Similarly, avoid using raw C interfaces outside their dedicated modules. Create proper abstractions that isolate platform-specific details, making the codebase more maintainable and portable.

3
Comments Analyzed
Other
Primary Language
API
Category

Source Discussions