Stop worshiping Airbnb styles

An angry love letter of a JavaScript developer

Flynn Buckingham
Jan 31, 2018 · 4 min read

I love functional programming and the concepts it presents. I really do. And do you know what else I really love? Javascript. It’s flexible, extensive, and bomblasted with all kinds of issues (just like me).

While linting a work project I discovered that nearly 200 of the linting errors thrown were caused by usage of for of iterative syntax.

Being me, a reasonably reasonable man (up to a reasonable point), decided to check their spec. Surely it must have been an oversight by their team about how awesome it is…

No. Actually, just checking it made me angry.

Observe these two blocks of code:

// synchronous  
function foo(args) {
return args.reduce((prev, arg) => prev.then(() => doSomethingAsync(arg), Promise.resolve())
}

And

async function fooStacking(args){
const stack = [];
let arg, item;
for (arg of args){
item = await someAsyncFunction(arg);
stack.push(item);
}
return stack;
}
// also, the concurrent version
async function fooConcurrent(args){
const stack = [];
for (let arg of args) stack.push(someAsyncFunction(arg));
return Promise.all(stack);
}

One of these is a functionally readable, sensible, and self documenting piece of code. The other was written by a chief engineer at AirBnb.

And guess what? Neither of them are right.

The correct way of writing this function apparently does not exist.

“Hi, this is Douglas Crockford calling about what you should be doing with your life.”

That’s why I’m angry. Every JavaScript developer on the planet will be writing (and might vouch for) code that will make you angry, especially if it’s not the way you like writing it.

They might hackishly and barbarically force the Array.reduce method to do something it’s not even meant to do, or maybe they write really old and ugly styled functions that look like they came straight out of a 1990’s programming manual.

And there is nothing you (or I) can do to stop them.

And honestly, it’s so menial anyways that there’s no point in making sense of it. There’s not even a battle to be won.

Things pissing me off at the moment (thanks to Airbnb’s spec and linting guidelines):

Loops are apparently evil, and instead I should choose to use functions that use loops to loop through items. You know… So they don’t have to use loops.

They also compare break and continue statements to GOTO statements (the ultimate evil), yet return statements can essentially do the exact same thing as both break and continue (the difference being the scope of which they do so). AirBnb also makes the bold statement that break statements are only used in loops. I guess that makes switch and if statements evil too…

Hey, are you running your production server code through Babel yet? No? Well, Airbnb thinks you should be.

There are other things as well, such as the use of require being unacceptable (which makes sense for Babel projects, but not Node ones), and being instructed to add excessive line breaks in certain declarations.

To be more constructive, I’ve decided to start writing my own eslint spec (and writing a companion how-to guide informing others how to do the same).

Standards are good to have when writing code, and so is structure. But don’t make your code look like someones else’s because it’s trendy. Make your own standards. And stop shutting down people who disagree with your unexplained choices.


Ramblings on beyond this point

JavaScript has come a long way since I started just over 8 years ago. I’ve seen some weird as-hell trends too. When I started, it was like a wild JS spaghetti western where jQuery was king, and skeuomorphism ruled all.

Now we live in a time where digital means flat. Design wise, and apparently architecturally too. Design patterns are cropping up where functions are getting flatter, and flatter, even to the extent that sometimes you can’t even tell what a function is meant to do anymore.

Me trying to read somebody's (exaggerated) method-based code as a legacy JS programmer.

To be fair, maybe we no-longer know what a function actually is. Maybe it now transcends it’s original mathematical roots (e.s.t 2015).

I had one person I know try to assign directly to the __proto__ of an object with Object.assign. Every day feels like I’m entering into a twilight zone, where Object methods become the only way to get around, and everyone starts looking like an Object method.

Maybe I’m in hell. No. Maybe I’m like everyone else, trapped in a tumbleweed language with mystical components like TurboFans and optimizer routines.

Or maybe… Maybe just like how you write your semicolons, none of this shit matters.

HackerNoon.com

how hackers start their afternoons.

Thanks to David Smooke.

Flynn Buckingham

Written by

JavaScript Developer, writer and skilled insomniac. Open Software enthusiast.

HackerNoon.com

how hackers start their afternoons.