News for hackers. Stuff that matters.
Re:You might not need if statements: a better approach to br... by meesterdude on Sunday January 22, 2017 @10:02PM (#13459381)

  Imagine discovering this code — having never seen it before — 
  and trying to work out what happens for non-logged in users that haven’t searched yet.
I'd run.

Overall, this seems to advocate for moving all your branching logic into one big file. I mean - I guess there could be a situation where I would want this - but it seems decoupled from real world examples and usage.

This is functionally, not much different from a function or method with a lot of branching logic embedded in itself. this just changes the format. So I don't see how this is new or better.

So I'll share one of my favorites related to reducing if statements that I use with some regularity:

before:

  if user.signed_in?

    if user.admin?

      do_magic

    end

  end
After:

  return unless user.signed_in? && user.admin?
  do_magic

There are no comments on this comment yet.