Early Returns Debate

This cluster centers on debates about using early return statements versus nested conditionals or implicit returns for better code readability, guard clauses, and error handling in functions across various programming languages.

➡️ Stable 0.5x Programming Languages
3,041
Comments
20
Years Active
5
Top Authors
#7034
Topic ID

Activity Over Time

2007
9
2008
24
2009
50
2010
51
2011
97
2012
169
2013
186
2014
131
2015
152
2016
152
2017
178
2018
222
2019
211
2020
185
2021
250
2022
242
2023
256
2024
212
2025
256
2026
8

Keywords

e.g PHP StrToBool BSD JIT vlang.io return returns function boolean returning statements early values explicit returned

Sample Comments

arithma • Jan 5, 2019 • View on HN

The best light I saw this recommendation is: apart from guard statements at the top of a function which have return's, the advice should hold

SomeOldThrow • Jun 13, 2019 • View on HN

Why doesn't go enforce using return values (or explicitly swallowing them)?

finnh • Feb 18, 2023 • View on HN

early return solves so many readability problems. i structure my code in favor of it.

anonbanker • May 30, 2015 • View on HN

Why shouldn't return be considered a function?

uriel • Jul 17, 2011 • View on HN

The lack of return statements is rarely missed, although it could be handy in some cases, there are ways around it.There is nothing weird about ifs' behavior once you understand it.Byron's rc tried to 'fix' ifs, and made everything worse.

SquibblesRedux • Jan 29, 2022 • View on HN

I prefer to use explicit return statements everywhere -- for greppability.

ztjio • Mar 26, 2018 • View on HN

Haven't looked into it for a while, but, it used to undermine the JIT compiler to use multiple return statements in a single method in Java.That said, I entirely disagree with the premise. I find it vastly easier to reason about a function/method that does not return early. To me, this is on par with writing switch statements that don't cover all the possible values: a sin.

fire_lake • Apr 1, 2025 • View on HN

People really like their early return statements however.

arghwhat • Jul 4, 2017 • View on HN

Early returns ftw (if (!cond) return; instead of if(cond) do();)!

Buttons840 • Jun 29, 2019 • View on HN

We can all agree that convoluted logic is bad, but there are functions with early returns which are not convoluted.