Month: March 2016

Introducing conservative-pad 0.4

Speed Read This
Posted by on March 24, 2016

Npm-logo.svg

There’s been some controversy lately in the Javascript world about micro-packages, version pinning, and the NPM package repository’s regulatory regime. For a serious take, I wrote a comment on the HN thread. There is a looming spectre threatening our entire software ecosystem, of which the deplorable decline of our dependency hygiene is but one example. The left has gone too far. That’s why I’m writing conservative-pad, a string-padding function free from the constraints of political correctness.

Here’s the original:

module.exports = leftpad;
function leftpad (str, len, ch) {
str = String(str);
var i = -1;
if (!ch && ch !== 0) ch = ' ';
len = len - str.length;
while (++i < len) { str = ch + str; } return str; }

This is terrible. You can expect that my replacement version will:

  • Be O(n). The original version uses Shlemiel the Painter's algorithm, which is mumble slur mumble.
  • Be written in LISP, to protect purity. These immigrant Javascript programmers are driving down wages and destroying our precious modularity.
  • Make web development great again.
  • Remove the unnecessary 'ch' parameter, a ridiculous piece of political correctness. It isn't our fault that string-padding is dominated by ' '; it won fair and square, and we shouldn't make exceptions to meritocracy just because someone wants a string-padding character that isn't white.
  • Compile with -Wall, because otherwise the bugs will keep coming back over the border.

Thank you.