Hacker News new | ask | show | jobs
by skybrian 673 days ago
Making analogies like this doesn't prove anything, they're just suggestive. All I'm getting out of this is that you think for loops are old-fashioned.
1 comments

That's because they are. Functional code is more readable. And if you look back, basically all advances in programming languages have been about "making stuff more readable". Thus, for loops (for this usage) are "old".
> Functional code is more readable.

There is no way that

    name: R.pipe(R.prop('name'), R.toUpper),
    age: R.prop('age'),
    isAdult: R.always(true)
is more readable than

    name: user.name.toUpperCase(),
    age: user.age,
    isAdult: true
Certainly so! The first example is needlessly contrived.

But instead of

  for (const i=0; i < data.length; i++) {
    new_data[i] = old_data[i].toUpperCase();
  }
you can write

  const new_data = old_data.map((x) => x.toUpperCase());
I think it's both more clear and less error-prone.
The second code does not compile and introduces a new dependency.
Sorry, are we speaking about the same language?

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBCA2ATA...

My apologies, I thought it was C++. I should learn typescript, it is one of those I'm postponing.
But those are both functional, or can easily be.
You say it’s more readable and I disagree with that!

Is this just fashion? Is there a way to settle it other than “I like it better?”

> Is this just fashion?

Yes.

Readability is a characteristic of the reader, not what is being read.

This simple truth seems to be so hard for many people to internalize. My theory as to why is that most programmers never get exposed to drastically different and unfamiliar languages and styles of programming. If they were forced to confront and internalize 2-3 different ways of writing code, they would realize this truth.

Personally, I once thought Lisp was unreadable... until I learned it. I once thought BASH was unreadable... until I learned it. Same with half a dozen other languages. Same for styles. "Readability" is just a familiarity and proficiency of the reader.

30 plus years ago, it was a common trope in programming circles that C code is unreadable, except to, or perhaps even to the author.
> Functional code is more readable.

All I get out of that is that you like functional code.