News for hackers. Stuff that matters.
Re:Avoid Else, Return Early (2013) by toomanybeersies on Monday March 26, 2018 @08:49AM (#16678422)
I was more or less required to use guard clauses by my manager at my previous job.

I used to hate being forced to use them, just because as a recent computer science graduate I was happy with nested conditionals everywhere. But guard clauses make life so much easier, I eventually discovered.

They make testing your code a lot easier, and also make reasoning about the code and reading it so much easier.

Ruby makes writing methods with guard clauses a breeze, since you can just write something like `return if x > 7`.

Re:Avoid Else, Return Early (2013) by rimliu on Monday March 26, 2018 @11:18AM (#16679521)
guard also lets you unwrap your optionals and have them in scope for the rest of the function.
Re:Avoid Else, Return Early (2013) by gwbas1c on Monday March 26, 2018 @01:21PM (#16680622)
It makes logging easier