▲ | 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. | |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
▲ | 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. | |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
▲ | 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 | |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
▲ | te_chris 8 days ago | parent | prev [-] | ||||||||||||||||||||||||||||||||||||||||
Dots call functions on objects, pipe passes arguments to functions. Totally missing the point. |