3 ms·
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 bette
by wouldbecouldbe 1y 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.
- EGreg 1y agoIt’s not really chaining More like thenables / promises
- wouldbecouldbe 1y agoIt looks like chaining, but with possibility of adding custom functions?
- bapak 1y agoIt'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 1y agoIt requires parentheses `(3).myMethod()` but you can by monkey patching the Number prototype. Very bad idea, but you absolutely can.
- senfiaj 1y agoYou can just add extra dot: `3..myMethod()`.
- EGreg 1y agoNot 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
- bapak 1y agoNothing 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 1y ago> 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 https://news.ycombinator.com/item?id=44794656
- te_chris 1y agoDots call functions on objects, pipe passes arguments to functions. Totally missing the point.
- Martinussen 1y agoWhen 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.
- chilmers 1y agoI'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 1y agoPresumably it's up to the change proposers to produce said study showing the opposite.
- 38 1y ago[dead]
- purerandomness 1y agoIf 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.
- hajile 1y agoChaining 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.