Re:My Thoughts on “Bad Code”
by p1necone on Thursday March 16, 2023 @11:57PM
(#35192888)
I'm big fan of separating functions into validation and logic using early returns:
[ Parent
| on HN ]
The term for that is a "guard". Swift took it literally and introduced guard statements which force you to terminate the containing scope (return, throw, continue, break) or call a function that is marked as never returning. If control flow can ~~enter~~ exit the body of the guard statement without hitting one of those, it's a compiler error.
EDIT: Exit the body of the guard statement, not enter.
> ~~enter~~
I get you’re going for the non-standard markdown strike through, but that looks confusing and calls attention to something you meant to remove. You can (well, could) remove the word when editing.
It is possibly the one Markdown feature I'd like HN to have. I use it all the time on Reddit to correct my comments without making replies look like nonsense.
You can use unicode, l̶i̶k̶e̶ ̶t̶h̶i̶s̶