
You might not need if statements: a better approach to branching logic - bubble_boi
https://hackernoon.com/you-might-not-need-if-statements-a-better-approach-to-branching-logic-59b4f877697f#.ruqzpakyw
======
dTal
If I might offer the author some constructive criticism - this article
contains a huge amount of filler, fluff and nonsense, which it descends into
at random times in an ADHD-like way. Like the way you use the word "gander"
and then suddenly feel compelled to type four paragraphs about geese and pygmy
marmosets. This makes it very annoying to read because the reader's flow is
constantly interrupted. The liberal use of "um" and the rambling first person
narrative style (complete with bizarre roleplay-style actions like "[wriggles
interestingly]") combine to present the impression that 1) you do not value
the reader's time and 2) you haven't sufficiently distilled what you are
actually trying to say.

I suspect this article would read very much better if you deleted it and
rewrote it from scratch, omitting the cutesy crap and narrative details about
your mood while you were thinking about this problem, and saying only what you
need to say.

------
shaftway
I like how the author just re-invented if statements. Even still called them
"if". Compare:

    
    
      [snip] {
        title: 'Has the user searched yet?',
        test: !!pageData.searchKeyword,
        if: {
          true: {
            [snip]
          },
          false: {
            [snip]
          },
        },
      }, [snip]
    

vs.

    
    
      // Has the user searched yet?
      [snip] if (decisionData.searchKeyword) {
        [snip]
      } else {
        [snip]
      }
    

I expected something like a state machine, instead of OOJSON.

------
meesterdude

      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

------
geophile
Jesus H. Christ, what an irritating writer.

------
Cozumel
That guy couldn't code his way out of a wet paper bag O.o

