Monday, May 8, 2017

a rant against arcane js syntax

Elements of JavaScript Style -- I'm having trouble wrapping my head around #2 there, "Omit needless code", where
function secret (message) {
  return function () {
    return message;
  }
};
is considered blatantly inferior to
const secret = msg => () => msg;

I remember one of the reasons people starting dumping on Perl (and just dumping Perl) was because of arcane syntax...  I think there's a strength in looking like other languages.

Concise code is critical in software because more code creates more surface area for bugs to hide in. Less code= fewer places for bugs to hide = fewer bugs.
Concise code is more legible because it has a higher signal-to-noise ratio: The reader must sift through less syntax noise to reach the meaning. Less code = less syntax noise = stronger signal for meaning transmission.
This reminds me of a scifi story that talked about an alien language that was SO EFFICIENT that they could say in a single, accented, nuanced word what a human would need to say in a sentence or a paragraph.The trouble is that kind of sci-fi think misses the reality that redundancy in a language is a feature, not a bug; for example, it means the meaning is likely to be preserved over "noisy transmission" - like when someone isn't paying full attention, for example, or when fidelity over the wire isn't perfect.

I guess some of the problem is the trivialness of the currying example - even without the syntax that will be less familiar to people steeped in other languages the need for a curry (mm, curry) is a little arcane to begin with - and in this example, it's not even clear where functional code would sit! Like if the original was
function secret (message) {
  return function () {
    return message.split("").reverse().join("");
  }
};

A coworker says that would boil down to

const secret = message => () => message.split('').reverse().join('')

There's something anti-egalitarian in use of this much bleeding edge syntax.

No comments:

Post a Comment