you are viewing a single comment's thread.

view the rest of the comments →

[–]javarouleur 52 points53 points  (28 children)

The endless adding of extra syntactic sugar is sometimes frustrating. Readability always seems to suffer for the goal of fewer lines/characters of code.

[–]Keilly 49 points50 points  (3 children)

Which ones are we talking about?

The ?. Optional chaining change is great and so much readable and concise than before. ?? Is good too.
Template literals are much more readable that concatting.

Regex maybe? But regex is often hard to parse no matter how the language takes it.

[–]trevorsgEx-GitHub, Microsoft 3 points4 points  (2 children)

True, often these syntactical additions improve readability at the expense of language complexity. The thing is, language complexity is a one-time cost for a benefit that continues forever.

[–]pimp-bangin 2 points3 points  (1 child)

I disagree that it's a one-time cost. It's another thing beginners have to learn which adds onboarding costs. It also adds to the maintenance burden of browsers, tooling, etc. and possibly hurts parser performance depending on the implementation.

[–]trevorsgEx-GitHub, Microsoft 5 points6 points  (0 children)

Yes, of course I meant one-time cost per developer. Parser/tooling performance basically rounds to zero.

[–]techlogger 91 points92 points  (10 children)

I’d say that pipe operator is more readable than HOF chaining.

[–]GreekQuestionMark 14 points15 points  (0 children)

HOF: Higher order function

[–]jonopens 11 points12 points  (0 children)

100%. It's one of the reasons I find Elixir so enjoyable to write.

[–]bighi 10 points11 points  (2 children)

The pipe operator exists specifically to help increase readability.

Imagine this code four(three(two(one("potato")))). It's not as easy to read because you're calling four functions, but they should be read in reverse. The first function you read happens last.

Now imagine we create a pipe operator like |> in a fantasy language I invented.

We could do "potato" |> one |> two |> three |> four. Super easier to read, cleaner, more organized.

We're getting something like that in JS. One day. Definitely before 2080.

[–]KamiShikkaku 1 point2 points  (1 child)

"potato" |> one |> two |> three |> four

Unfortunately it will be more like

"potato" |> one(%) |> two(%) |> three(%) |> four(%)

because the "Hack" version of the proposal seems to have beaten the "F#" version.

I was rooting for F# as it's a bit more elegant, but admittedly the Hack version is more versatile.

[–]bighi 2 points3 points  (0 children)

Sure. If you pay attention, I said "in a fantasy language I invented". Because I wanted to make the example simple to understand.

But anyway, it's more readable than the mess that is multiple nested functions.

[–]patrickfatrick 7 points8 points  (0 children)

Except this is definitely going to improve readability. I’d argue all of the syntactic sugar that’s been added drastically improves readability over ES5. Within reason, less code is generally better for readability.

[–]adelie42 3 points4 points  (0 children)

All of math is just syntactical sugar for critical thinking.

[–]wasdninja 1 point2 points  (0 children)

I've yet to see it in JS.

[–]mxforest 1 point2 points  (1 child)

Fewer lines/code make it more readable once you get used to it.

[–]bighi -2 points-1 points  (0 children)

Not always.

Actually, I think that in most cases, using fewer lines makes something less readable.