Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Good code needs few unit tests. Parent comment
Pulling an example out of thin air, shorter total code:
var counter = 0; function foo() { log("Incremented"); counter++; } function bar() { log("Incremented"); counter++; }
var counter = 0; function increment() { log("Incremented"); counter++; } function foo() { increment(); } function bar() { increment(); }
var Counter = (function () { var counter = 0; return { increment : function() { log("Incremented"); counter++; }, current : function() { return counter; } }; }); function foo() { Counter.increment(); } function bar() { Counter.increment(); }
There are no comments on this comment yet.
Pulling an example out of thin air, shorter total code:
Code with an abstraction which makes foo and bar shorter: Even longer code, but which encapsulates the counter variable, possibly making it easier to reason about: