ABC


Advice

When no strong semantic or conventional ordering exists, prefer lexicographical order. This provides a consistent, discoverable rule that reduces ambiguity for contributors.


Scope

This principle applies both to argument lists and to struct/class property declarations when no stronger convention exists.


Context

In cases where functions have an expectation around order this should be respected:

In other cases it makes sense to go lexicographical to optimise for human readers. This has a couple of benefits:


Examples

Good

struct Car {
    let color: String
    let make: String
    let mileage: Double
    let model: String
    let numberOfDoors: Int
    let year: Int
}

Bad

struct Car {
    let make: String
    let model: String
    let year: Int
    let color: String
    let numberOfDoors: Int
    let mileage: Double
}