7 ms·
Better stick to a single point of exit. https://news.ycombinator.com/item?id=20311080 https://news.ycombinator.com/item?id=20311080
by augustk 11mo ago
Better stick to a single point of exit.
https://news.ycombinator.com/item?id=20311080 https://news.ycombinator.com/item?id=20311080
- foofoo12 11mo agoThere is nothing wrong with early exit, but you have to be sensible. Just like there's nothing wrong with the ternary operator if you are sensible. I've seen nested ?: abominations that would make Jesus give you a funny look.
- loeg 11mo agoWell, maybe. Could also just use psrc directly instead of doing the manipulation in src.
- 1718627440 11mo agoThe discussion you linked to convinces me of the opposite.
- SAI_Peregrinus 11mo agoI disagree, I think returns should either be at the very start (checking inputs should be able to return before anything happens based on invalid inputs) or at the very end. Proceeding to do a bunch of stuff & then try to undo it because an input was invalid is error-prone.
- augustk 11mo agoIf the input parameters are invalid there is an error in the program so it makes more sense to use the assert function. Why would you need to undo something due to the restriction of a single point of exit?