Skip to content

File Organization isn't consistent with most Swift code out there #32

Closed
@dalemyers

Description

@dalemyers

What convention is being referenced?

The ordering in a file suggests most "important" to least "important", where how important it is is proportional to its visibility. i.e. public is the most important and private is the least important. This gives an interesting example of a code like this (trimmed here):

public class House {

    // public functions
    public init {
    // ...
    }

    private var size: Int = 0

}

You can see that the instance variable is at the bottom of the definition.

How do you propose this convention could be improved? Please provide rationale and examples if possible.

This rule is overly broad and not particularly helpful. Convention across the last several decades of programming has us put instance variables at the top of the file usually. We should correct to allow for this at the very least.

I'd also argue that a small private helper method makes more sense to be located next to the public method that uses it, rather than at the other end of the file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    issueIssue in an existing convention

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions