Slide 1

Slide 1 text

@ariyahidayat

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.

Slide 7

Slide 7 text

{ type: "Program", body: [ { type: "VariableDeclaration", declarations: [ { type: "VariableDeclarator", id: { type: "Identifier", name: "answer" }, init: { type: "Literal", value: 42, raw: "42" } } ], kind: "var" } ] } var answer = 42;

Slide 8

Slide 8 text

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

function detect_console(code) { function check(node) { if (node.type === 'CallExpression') { if (node.callee.type === 'MemberExpression') { if (node.callee.object.name === 'console') { alert('console call at line', node.loc.start.line); } } } } var tree = esprima.parse(code, { loc: true }); estraverse.traverse(tree, { enter:check }); } http://ariya.ofilabs.com/2013/04/automagic-removal-of-javascript-logging.html

Slide 12

Slide 12 text

reload(x, y, false) function checkLastArgument(node) { var args = node['arguments']; if (args.length < 2) { return; } if (typeof args[args.length - 1].value === 'boolean') { report(node, 'Dangerous Boolean literal'); } }

Slide 13

Slide 13 text

http://ariya.ofilabs.com/2012/10/detecting-nested-ternary-conditionals.html var str = (age < 1) ? "baby" : (age < 5) ? "toddler" : (age < 18) ? "child": "adult";

Slide 14

Slide 14 text

http://ariya.ofilabs.com/2012/12/complexity-analysis-of-javascript-code.html if (true) "foo"; else "bar";

Slide 15

Slide 15 text

http://ariya.ofilabs.com/2013/05/continuous-monitoring-of-javascript-code-complexity.html

Slide 16

Slide 16 text

“YOU SHALL NOT PASS!” — Darth Vader

Slide 17

Slide 17 text

http://ariya.ofilabs.com/2013/01/javascript-code-complexity-visualization.html

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Non-Destructive Regenerative http://ariya.ofilabs.com/2013/06/javascript-source-transformation-non-destructive-vs-regenerative.html

Slide 20

Slide 20 text

http://ariya.ofilabs.com/2012/02/from-double-quotes-to-single-quotes.html console.log('Hello') console.log("Hello")

Slide 21

Slide 21 text

http://ariya.ofilabs.com/2013/05/es6-and-block-scope.html function f() { let j = data.length; console.log(j, 'items'); for (let i = 0; i < j; ++i) { let j = data[i] * data[i]; console.log(j); // squares } } function f() { var j = data.length; console.log(j, 'items'); for (var i = 0; i < j; ++i) { var j$0 = data[i] * data[i]; console.log(j$0); // squares } }

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Alice Bob Chuck Dan ... Bob Alice Dan Chuck ...

Slide 24

Slide 24 text

Array.prototype.swap = function (i, j) { var k = this[i]; this[i] = this[j]; this[j] = k; } function sort(list) { var items = list.slice(0), swapped = false, p, q; for (p = 1; p < items.length; ++p) { for (q = 0; q < items.length - p; ++q) { if (items[q + 1] < items[q]) { items.swap(q, q + 1); swapped =true; } } if (!swapped) break; } return items; }

Slide 25

Slide 25 text

http://ariya.ofilabs.com/2012/01/scalable-web-apps-the-complexity-issue.html Array.prototype.swap = function (i, j) { var k = this[i]; this[i] = this[j]; this[j] = k; } Array.prototype.swap = function (i, j) { Log({ name: 'Array.prototype.swap', lineNumber: 1, range: [23, 94] }); var k = this[i]; this[i] = this[j]; this[j] = k; }

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

function inc(p, q) { if (q == undefined) q = 1; return p + q/q; } assert("inc(4) must give 5", inc(4) == 5); http://ariya.ofilabs.com/2012/12/javascript-code-coverage-with-istanbul.html

Slide 29

Slide 29 text

http://ariya.ofilabs.com/2012/09/the-hidden-trap-of-code-coverage.html

Slide 30

Slide 30 text

http://ariya.ofilabs.com/2013/05/hard-thresholds-on-javascript-code-coverage.html istanbul check-coverage --statement -5 --branch -3 --function 100

Slide 31

Slide 31 text

“If you think JSLint hurts your feelings, wait until you use Istanbul.”

Slide 32

Slide 32 text

...I gave you my heart But the very next day you gave it away...

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

http://ariya.ofilabs.com/2012/12/quality-code-via-multiple-layers-of-defense.html

Slide 35

Slide 35 text

Mr. Reviewer

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

@ariyahidayat ariya.ofilabs.com/highlights speakerdeck.com/ariya Some artworks are from http://openclipart.org.