Skip to content

Instantly share code, notes, and snippets.

Created April 5, 2015 06:22
Show Gist options
  • Star 28 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/8a163db3f7f3d81d5296 to your computer and use it in GitHub Desktop.
Save anonymous/8a163db3f7f3d81d5296 to your computer and use it in GitHub Desktop.
Your goals are to reduce the number of things that you have to keep in your head at any given moment, and to rely as little as possible on your own ability to consistently do things right.
If you make a thing immutable ('let' in swift), you never have to think about what happens if it changes, or what other parts of the code you'll effect if you change it.
If you split complex functions into several smaller functions that only interact by passing arguments or getting return values, then you limit the amount of code you need to consider when hunting for a bug, and you can test each small piece separately.
If you understand what things must be true in your code (aka invariants, for example "a person's age must be greater than 0"), and either provide no function that can cause them to be untrue, or check and crash immediately when they're untrue, then you don't have to debug issues caused by incorrect assumptions.
If you remove possibilities (for example, Swift removes the possibility of things being nil unless you specifically ask for it back), then you don't need to reason about as many combinations of possibilities.
If you put the code for doing different things in different places, you reduce the amount of code you have to look at when something goes wrong. The same is true for putting code that does the same thing in the same place.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment