🌐 https://medium.com/@matryer/line-of-sight-in-code-186dd7cdea88
🎦 https://youtu.be/yeetIgNeIkc

Tags: -golangprogramming-style

Highlights & Notes

The idea is that another programmer (including your future self) can glance down a single column and understand the expected flow of the code. If they have to jump around parsing if conditions in their brains moving in and out of code blocks, it makes that task much more difficult.

Tips for a good line of sight:

  1. Align the happy path to the left; you should quickly be able to scan down one column to see the expected execution flow
  2. Don’t hide happy path logic inside a nest of indented braces
  3. Exit early from your function
  4. Avoid else returns; consider flipping the if statement
  5. Put the happy return statement as the very last line
  6. Extract functions and methods to keep bodies small and readable
  7. If you need big indented bodies, consider giving them their own function