👨‍💻
Software Engineering
Tidy First?: A Personal Exercise in Empirical Software Design
Tidy First?: A Personal Exercise in Empirical Software Design
  • Tidy First?
  • Foreword
  • Preface
  • Part 1: Tidyings
    • 1: Guard Clauses
    • 2: Dead Code
    • 3: Normalize Symmetries
    • 4: New Interface, Old Implementation
    • 5: Reading Order
    • 6: Cohesion Order
    • 7: Move Declaration & Initialization Together
    • 8: Explaining Variables
    • 9: Explaining Constants
    • 10: Explicit Parameters
    • 11: Chunk Statements
    • 12: Extract Helper
    • 13: One Pile
    • 14: Explaining Comments
    • 15: Delete Redundant Comments
  • Part 2: Managing
    • Coming soon
  • Part 3: Theory
    • Coming soon
Powered by GitBook
On this page
  1. Part 1: Tidyings

1: Guard Clauses

Code like this:

if(condition)
... some code ...

Or like this:

if(condition)
    if(not other condition)
        ... some code ...

Tidy the code above to something like this:

if(not condition) return
if(other condition) return

... some code ...

As a reader, it's easy to get lost in nested conditions.

Code with guard clauses is easier to read & analyze because the preconditions are explicit.

Don't overdo guard clauses - a routine with sever or eight clauses is NOT easier to ready.

PreviousPrefaceNext2: Dead Code

Last updated 23 days ago