| > JS is more readable, without a doubt In what sense? Haskell's: strSum = sum . map read . words in JS would be: const strSum = str => str.split(' ').map(Number).reduce((a, b) => a + b, 0); for a person who's not already a JS programmer, the first one would be more readable (without a doubt), it literally reads like plain English: "sum of mapped read of words". Haskell's version is more "mathematical" and straightforward. Each function has one clear purpose. The composition operator clearly shows data transformation flow. No hidden behavior or type coercion surprises. Whereas JS version requires knowledge of: - How Number works as a function vs constructor - Implicit type coercion rules - Method chaining syntax - reduce()'s callback syntax and initial value - How split() handles edge cases So while the JS code might look familiar, it actually requires more background knowledge and consideration of implementation details to fully understand its behavior. Javascript is far more complex language than most programmers realize. btw, I myself don't write Haskell, but deal with Javascript almost daily and I just can't agree that JS is "more readable" than many other PLs. With Typescript it gets even more "eye-hurting". |
It's funny to me that you quote the FP-like version of that in JS.
The more traditional version would be more like this:
I do sincerely think this is more readable, no matter your background. It splits the steps more clearly. Doesn't require you to keep almost anything in your head as you read. It looks stupid, which is great! Anyone no matter how stupid can read this as long as they've had any programming experience, in any language. I would bet someone who only ever learned Haskell would understand this without ever seeing a procedural language before.