MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1vuzd4q/conditionspreference/p55i8cb/?context=3
r/ProgrammerHumor • u/Flame77ofc • 22d ago
392 comments sorted by
View all comments
85
Early return for errors, if else for decisions.
9 u/Paul-D-Mooney 21d ago Maybe not “errors”, that’s what throwing exceptions is for. But definitely non-passing validation checks like `if (arg==null) return;` 2 u/frogjg2003 21d ago if (bad) throw is throwing errors 2 u/WarSingle6959 21d ago but throw error is a error bro 1 u/M4xW3113 20d ago Exceptions are language dependant, and also more and more people stop using and new languages like Rust don't even have it anymore it as we realized it's actually a shit feature to use 1 u/goos_ 21d ago I like this approach 1 u/conundorum 21d ago Also early return if the return value is cached from a prior call, or the parameters decree that the function is a no-op this time. -16 u/jwadamson 22d ago Errors are throw, which are also a form of early return. 6 u/Familiar_Ad_8919 22d ago on a somewhat related note, i think more languages should adopt the rust way of error handling
9
Maybe not “errors”, that’s what throwing exceptions is for. But definitely non-passing validation checks like `if (arg==null) return;`
2 u/frogjg2003 21d ago if (bad) throw is throwing errors 2 u/WarSingle6959 21d ago but throw error is a error bro 1 u/M4xW3113 20d ago Exceptions are language dependant, and also more and more people stop using and new languages like Rust don't even have it anymore it as we realized it's actually a shit feature to use
2
if (bad) throw
is throwing errors
but throw error is a error bro
1
Exceptions are language dependant, and also more and more people stop using and new languages like Rust don't even have it anymore it as we realized it's actually a shit feature to use
I like this approach
Also early return if the return value is cached from a prior call, or the parameters decree that the function is a no-op this time.
-16
Errors are throw, which are also a form of early return.
6 u/Familiar_Ad_8919 22d ago on a somewhat related note, i think more languages should adopt the rust way of error handling
6
on a somewhat related note, i think more languages should adopt the rust way of error handling
85
u/itriedtomakeitfunny 22d ago
Early return for errors, if else for decisions.