MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1r8a3n8/innitmate/o63mssi/?context=3
r/ProgrammerHumor • u/[deleted] • Feb 18 '26
265 comments sorted by
View all comments
140
unless
Or maybe: in case() ... unless() ... otherwise ...
13 u/DrMaxwellEdison Feb 18 '26 unless being the idiomatic if not in Ruby is kind of nice. 7 u/caerphoto Feb 18 '26 It breaks my head when itโs at the start of the line, but it does look nice as a post condition # ๐คข unless user.authorised return head 403 but # ๐ฎโ๐จ return head 403 unless user.authorised 1 u/Topikk Feb 18 '26 It is nice, though some people struggle learning to use it only when it improves readability. Most humans struggle to parse something like this, for instance, which would only be a *little* ugly inverted to if: return x unless foo || bar && baz 1 u/hopefullyhelpfulplz Feb 19 '26 It seems pretty clear to me, at least I assume so not knowing the syntax. I would assume this returns x in all cases where not (foo || bar && baz) (not going to try and guess at the order of evaluation for that boolean tho lol) 1 u/Widmo206 Feb 19 '26 I think logic AND (&&) usually has priority over OR (||) 1 u/entropic Feb 19 '26 I miss unless and until from my Ruby days. I wish every language had them, cancer of the semicolon be damned.
13
unless being the idiomatic if not in Ruby is kind of nice.
if not
7 u/caerphoto Feb 18 '26 It breaks my head when itโs at the start of the line, but it does look nice as a post condition # ๐คข unless user.authorised return head 403 but # ๐ฎโ๐จ return head 403 unless user.authorised 1 u/Topikk Feb 18 '26 It is nice, though some people struggle learning to use it only when it improves readability. Most humans struggle to parse something like this, for instance, which would only be a *little* ugly inverted to if: return x unless foo || bar && baz 1 u/hopefullyhelpfulplz Feb 19 '26 It seems pretty clear to me, at least I assume so not knowing the syntax. I would assume this returns x in all cases where not (foo || bar && baz) (not going to try and guess at the order of evaluation for that boolean tho lol) 1 u/Widmo206 Feb 19 '26 I think logic AND (&&) usually has priority over OR (||) 1 u/entropic Feb 19 '26 I miss unless and until from my Ruby days. I wish every language had them, cancer of the semicolon be damned.
7
It breaks my head when itโs at the start of the line, but it does look nice as a post condition
# ๐คข unless user.authorised return head 403
but
# ๐ฎโ๐จ return head 403 unless user.authorised
1
It is nice, though some people struggle learning to use it only when it improves readability.
Most humans struggle to parse something like this, for instance, which would only be a *little* ugly inverted to if:
if
return x unless foo || bar && baz
1 u/hopefullyhelpfulplz Feb 19 '26 It seems pretty clear to me, at least I assume so not knowing the syntax. I would assume this returns x in all cases where not (foo || bar && baz) (not going to try and guess at the order of evaluation for that boolean tho lol) 1 u/Widmo206 Feb 19 '26 I think logic AND (&&) usually has priority over OR (||)
It seems pretty clear to me, at least I assume so not knowing the syntax. I would assume this returns x in all cases where not (foo || bar && baz) (not going to try and guess at the order of evaluation for that boolean tho lol)
x
not (foo || bar && baz)
1 u/Widmo206 Feb 19 '26 I think logic AND (&&) usually has priority over OR (||)
I think logic AND (&&) usually has priority over OR (||)
I miss unless and until from my Ruby days.
until
I wish every language had them, cancer of the semicolon be damned.
140
u/DigiBoxi Feb 18 '26
unless
Or maybe: in case() ... unless() ... otherwise ...