I highly recommend sorting symbols in code by invariant properties such as access level and lexicographic order. It does not take much effort up front—it becomes automatic—and guarantees that you will know where to look for the existence of any symbol in any source file. It reduces cognitive load when creating, editing, and reading code. Any semantic order will quickly be lost by your brain. I only make exceptions for function parameters and SDK protocol interfaces.
One of my most steadfast programming beliefs is that we should try to reduce cognitive load at every scale: lines, files, modules, abstractions. We should aggressively reduce the number of decisions we need to make, and the number of decisions we need to reconstruct from first principles. We have so much else to think about.
I find it unsettling when I see code that, for example, intermixes private var
and public let
properties. You pay the price each time you need to get up to speed.
Additionally, this is the only code organization principle that can survive edits by multiple people over a long period of time. Else, someone will miss that you had a “helpers” section and a “network calls” section, or will not be able to reconstruct what you thought the difference between a private helper function and private network function was. Just like future you. We may as well be a new person every month.