Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Fighting Boolean Traps

Fighting Boolean Traps

Presented at WaffleJS meetup. Jan 10, 2018. San Francisco.

Ever encounter some code that looks like new Slider(true /*horizontal*/)? Perhaps you are confused by the semantics exhibited by setState(true, false)? Did you get a headache when trying to unpack double negatives as in filter.caseInsensitive = false? These are typical API blunders often denoted as Boolean Traps. Learn how to recognize such a mistake and also more importantly, how to prevent it from happening!

Ariya Hidayat

January 10, 2018
Tweet

More Decks by Ariya Hidayat

Other Decks in Programming

Transcript

  1. s1 = new Slider({ orientation: "vertical" }); s2 = new

    Slider({ orientation: "horizontal" });
  2. Ping-pong, Anyone? // Expand + animate treeItem.setState(true, true); // Expand

    + don't animate treeItem.setState(true, false); // Collapse + animate treeItem.setState(false, true);
  3. this.callMe = "Adam"; flight.from = SFO; flight.to = JFK; this.name

    = "Adam"; flight.departure = SFO; flight.destination = JFK;
  4. var x = Math.sqrt(-2) isNaN(x) true x === NaN false

    isNaN('hola') true x == NaN false
  5. SHStripMneumonic “Why is the function SHStripMneumonic misspelled?” Raymond Chen, Microsoft

    http://blogs.msdn.com/b/oldnewthing/archive/2008/05/19/8518565.aspx