Why You Shouldnt Nest Your Code
Why You Shouldn't Nest Your Code
Metadata
- Author: CodeAesthetic
- Full Title: Why You Shouldn't Nest Your Code
- Category: #articles
- Summary: I'm a Never Nester and you should too.
Access to code examples, discord, song names and more at https://www.patreon.com/codeaesthetic
Correction: At 2:20 the inversion should be "less than or equal", not "less than"
Highlights
- We've now taken a reasonably readable function and dramatically increased
the amount of conditions your brain must simultaneously hold.But what can we do about it?Well, there's two methods you can use to denest: Extraction.This is where you pull out part of the function into its own function.And inversion, which is simply flipping conditionsand switching to an early return. (View Highlight)