Slide 1

Slide 1 text

Fighting Boolean Traps

Slide 2

Slide 2 text

Readable, consistent, crystal clear Thank you, Captain Obvious!

Slide 3

Slide 3 text

https://twitter.com/AriyaHidayat/status/455892955765551105

Slide 4

Slide 4 text

I HAVE A BAD FEELING ABOUT THIS…

Slide 5

Slide 5 text

A long time ago in a galaxy far far away…

Slide 6

Slide 6 text

var powerSlider = new Slider();

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

var anotherSlider = new Slider(false);

Slide 9

Slide 9 text

IT’S A TRAP!

Slide 10

Slide 10 text

IT’S A BOOLEAN TRAP!

Slide 11

Slide 11 text

s2 = new Slider(false); s1 = new Slider(true);

Slide 12

Slide 12 text

s2 = new Slider(false /*horiz*/); s1 = new Slider(true /*vertical*/);

Slide 13

Slide 13 text

Code is written once, read many times.

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

s2 = new VerticalSlider(); s1 = new HorizontalSlider();

Slide 16

Slide 16 text

contacts.find(str);

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

// Check the cache first contacts.find(str, true); // Fresh search only contacts.find(str, false);

Slide 19

Slide 19 text

IT’S A MODIFIER TRAP!

Slide 20

Slide 20 text

the more the merrier

Slide 21

Slide 21 text

Ping-pong, Anyone? // Expand + animate treeItem.setState(true, true); // Expand + don't animate treeItem.setState(true, false); // Collapse + animate treeItem.setState(false, true);

Slide 22

Slide 22 text

DOM Event event.initKeyEvent("keypress", true, true, null, null, false, false, false, false, 9, 0);

Slide 23

Slide 23 text

Double Negatives X.disabled = false; Y.setHidden(true); filter.caseInsensitive = true; X.enabled = true; Y.setVisible(false); filter.caseSensitive = false;

Slide 24

Slide 24 text

picker.yearFrom = 1980; picker.yearTo = 2020; picker.minimumYear = 1980; picker.maximumYear = 2020;

Slide 25

Slide 25 text

this.callMe = "Adam"; flight.from = SFO; flight.to = JFK; this.name = "Adam"; flight.departure = SFO; flight.destination = JFK;

Slide 26

Slide 26 text

var x = Math.sqrt(-2) isNaN(x) true x === NaN false isNaN('hola') true x == NaN false

Slide 27

Slide 27 text

https://twitter.com/AriyaHidayat/status/393034774245171200

Slide 28

Slide 28 text

GarlicNaN != NaN Future JavaScript?

Slide 29

Slide 29 text

Best Practices

Slide 30

Slide 30 text

#1: Private by Default Public = Irreversible

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

SHStripMneumonic “Why is the function SHStripMneumonic misspelled?” Raymond Chen, Microsoft http://blogs.msdn.com/b/oldnewthing/archive/2008/05/19/8518565.aspx

Slide 33

Slide 33 text

-- yours truly “You’d fail your first two attempts anyway.”

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

#2: Mandatory API Review

Slide 36

Slide 36 text

“Write 3 examples which use the API.”

Slide 37

Slide 37 text

#3: Build and Use TOOLS

Slide 38

Slide 38 text

Summary

Slide 39

Slide 39 text

Boolean traps (and other API mistakes) lead to FEAR

Slide 40

Slide 40 text

[Yoda]

Slide 41

Slide 41 text

Thank You Some artworks are from https://unsplash.com/ and http://openclipart.org. speakerdeck.com/ariya @ariyahidayat