Remix.run Logo
wouldbecouldbe 8 days ago

It’s really not needed, syntax sugar. With dots you do almost the same. Php doesn’t have chaining. Adding more and more complexity doesn’t make a language better.

chilmers 7 days ago | parent | next [-]

I'm tired of hearing the exact same arguments, "not needed", "just syntax sugar", "too much complexity", about every new syntax feature that gets added to JS. Somehow, once they are in the language, nobody's head explodes, and people are soon using them and they become uncontroversial.

If people really this new syntax will make it harder to code in JS, show some evidence. Produce a study on solving representative tasks in a version of the language with and without this feature, showing that it has negative effects on code quality and comprehension.

robertlagrant 7 days ago | parent | next [-]

Presumably it's up to the change proposers to produce said study showing the opposite.

38 7 days ago | parent | prev [-]

[dead]

bapak 8 days ago | parent | prev | next [-]

Nothing is really needed, C89 was good enough.

Dots are not the same, nobody wants to use chaining like underscore/lodash allowed because it makes dead code elimination impossible.

pjmlp 8 days ago | parent [-]

K&R C was good enough for UNIX System V, why bother with C89.

boobsbr 7 days ago | parent [-]

K&R C was the apex, we've just been going downhill since.

lioeters 7 days ago | parent [-]

This but unironically.

troupo 8 days ago | parent | prev | next [-]

> With dots you do almost the same.

Keyword: almost. Pipes don't require you to have many different methods on every possible type: https://news.ycombinator.com/item?id=44794656

hajile 7 days ago | parent | prev | next [-]

Chaining requires creating a class and ensuring everything sticks to the class and returns it properly so the chain doesn't blow up. As you add more options and do more stuff, this becomes increasingly hard to write and maintain.

If I'm using a chained library and need another method, I have to understand the underlying data model (a leaky abstraction) and also must have some hack-ish way of extending the model. As I'm not the maintainer, I'm probably going to cause subtle breakages along the way.

Pipe operators have none of these issues. They are obvious. They don't need to track state past the previous operator (which also makes debugging easier). If they need to be extended, look at your response value and add the appropriate function.

Composition (whether with the pipe operator or not) is vastly superior to chaining.

Martinussen 7 days ago | parent | prev | next [-]

When you say chaining, do you mean autoboxing primitives? PHP can definitely do things like `foo()->bar()?->baz()`, but you'd have to wrap an array/string yourself instead of the methods being pulled from a `prototype` to use it there.

purerandomness 7 days ago | parent | prev | next [-]

If your team prefers not to use this new optional feature, just enable a PHPStan rule in your CI/CD pipeline that prevents code like this getting merged.

EGreg 8 days ago | parent | prev | next [-]

It’s not really chaining

More like thenables / promises

wouldbecouldbe 8 days ago | parent [-]

It looks like chaining, but with possibility of adding custom functions?

bapak 8 days ago | parent [-]

It's chaining without having to vary the return of each function. In JS you cannot call 3.myMethod(), but you could with 3 |> myMethod

cyco130 8 days ago | parent | next [-]

It requires parentheses `(3).myMethod()` but you can by monkey patching the Number prototype. Very bad idea, but you absolutely can.

senfiaj 2 days ago | parent [-]

You can just add extra dot: `3..myMethod()`.

EGreg 7 days ago | parent | prev [-]

Not only that

In chaining, methods all have to be part of the same class.

In C++ we had this stuff ages ago, it’s called abusing streaming operators LMAO

te_chris 8 days ago | parent | prev [-]

Dots call functions on objects, pipe passes arguments to functions. Totally missing the point.