Sum Type as Boolean
Sun Jun 21 2026

Today, I have encountered a scenario where I think passing a boolean as parameter affects readability and maintainability more than I though.

Example
func CancelOrder(ctx context.Context, force bool, notifyUser bool) error {
    // ...
}

func Usage(ctx context.Context) error {
    // At call site, a caller needs to inspect a method signature to see
    // what `false` and `true` are, this is bad and prone to error.
    err := CancelOrder(ctx, false, true)
}
My Approach

And my goal is to make code more readable on caller site (can interprete meaning easily without seeing method signature which also helping on code review too) with type safety.

type CancelOrderForceBoolean bool

const (
    Force = ForceBoolean(true)
    NotForce = ForceBoolean(false)
)

type NotifyUserBoolean bool

const (
    NotifyUser = NotifyUserBoolean(true)
    NotNotifyUser = NotifyUserBoolean(false)
)

func CancelOrder(
    ctx context.Context,
    force ForceBoolean,
    notifyUser NotifyUserBoolean,
) error {
    // ...
}

func Usage(ctx context.Context) error {
    // This is more readable without a need to see the method signature.
    err := CancelOrder(ctx, NotForce, NotifyUser)
}

Of course!, the final code is more verbose, that is a trade-off that we need to consider when using this approach.