The most common refactor I add to code is a guard clause.

Consider the following pseudo code.

if a:
do_a()
if not b:
do_other()

Compared to this clean up:

if not a:
do_other()

if b:
do_a()

Why? I've simplified this code for brevity. Generally, though, when I find 1 nested if, there's usually an intent to add more base cases, such as "if c".

It's a small thing, but it leads to more maintainable code.

0

If you have a fediverse account, you can quote this note from your own instance. Search https://mastodon.social/users/raiderrobert/statuses/115565637596452460 on your instance and quote it. (Note that quoting is not supported in Mastodon.)