Hard disagree, it's only more readable if your definition of readability is pinned to that of a beginner. As we become more knowledgeable our idea of readability should move with us.
Take this for example, beginners often don't know about ternaries:
const x = a ? b : c;
The more "readable" approach as you put it would be like this:
let x;
if (a) {
x = b;
else {
x = c;
}
Not only is this noisier and harder to parse for anyone more experienced but it's also opened up the need to track the mutability of the variable reference that didn't exist with the ternary approach.
I was goin with that if statements read more like english.
Shifting everything into one line does shorten things. And those of us that know what a turnarys does can read it faster.
But it's not more "readable" if that makes sense.
Kinda like object parsing:
const getDataFromObj = ({data}) => data;
Is quick and easy and those of us who know how it works understand how useless of a getter it is
Buuuuuut, I would argue this is more readable
var getDataFromObj = function(obj){ return obj.data; }
I'm writing this on my phone so I apologize for the formatting.
Anyways, the point is while shortcuts are nice and convenient it does come at a cost of readability and we do have to be aware of that.
Youre not wrong, it is noisier, but it still closer to english which is the goal of readability.
To be clear even as a junior I understand the benefits of using these newish techniques and I implement them myself.
But they're not more readable. That's just false. It's like saying Moby Dick is more readable than see spot run. Yes it's a better book but, it's substantially harder to read.
It's more readable in code which is a distinct type of language. Your second code snippet there isn't more readable, it merely has more words in it. Is that all that matters? Would you prefer add(1, 2) over 1 + 2 for this reason?
If you're keen for traditional language-esque readability then you ought to try Haskell, which ironically demonstrates extremely well that programming is closer to mathematics than anything else. That we currently can best express it linguistically is an irrelevance.
I respect your perspective. One of the nicer things about Haskell is that sometimes the code comes together like this: andFinallyThis . andSomethingElse . doAThing Hopefully we'll see something similar if TC39 approves the pipeline operator proposal.
The trouble is that if you optimise for linguistic familiarity above all else you sacrifice other really important properties, properties that inherently exist because programming is, or at least can and in my view should be, a logical venture.
Taking forEach as an example, if you were to use this for mapping an array, you'd have a program that's harder to quickly parse (again, for anyone other than a beginner), and crucially the logic of the program would be harder to follow. See:
We have to keep track of the mutability of strs (in practice, in a functional codebase, you consider const to mean truly immutable). We have to track the iteration over nums and ensure we're not doing anything different in some loops.
Functor mapping implies a pure function, so when you read this code you know beyond all reasonable doubt that it will map an array given the provided function and that's it. No changes to nums, and a predictable value at strs. This is an enormous benefit to readability that can only be realised if you're willing to raise your definition of readability vis a vis the lowest common denominator.
4
u/[deleted] Nov 10 '20
Hard disagree, it's only more readable if your definition of readability is pinned to that of a beginner. As we become more knowledgeable our idea of readability should move with us.
Take this for example, beginners often don't know about ternaries:
The more "readable" approach as you put it would be like this:
Not only is this noisier and harder to parse for anyone more experienced but it's also opened up the need to track the mutability of the variable reference that didn't exist with the ternary approach.