4 ms·
Yin the OOP world I’ve seen this pattern called chaining : usually either method or object chaining.
by memco 2y ago
Yin the OOP world I’ve seen this pattern called chaining : usually either method or object chaining.
- pxc 2y agoIt's a style I really enjoy, and it's definitely not exclusive to one language or paradigm, exactly. I see it as more of less of a kind with pipelines in Unix shells, too. In Scala, a language with OOP heritage and support, plus lots of functional programming features, some of the most common methods you use in such chains are monads.
- riffraff 2y agoSmalltalk (and Dart) also have "cascading" which is method chaining with special supporting syntax e.g. in ST you'd send four different messages to the same object with something like scene add: sprite; add: otherSprite; setBackGround: stage; start I'm not sure if it matches the "reuse values from previous computation" but it should since messages will affect the object, you just don't have local variables.
- zelphirkalt 2y agoIt is using ';' instead of parenthesizing the messages to the objects, correct?
- klibertp 2y agoIn Smalltalk, `;` does two things: terminates the current message (EDIT: while ignoring its return value) and propagates the target object of the current message as a target for the following message. So this: scene add: sprite; add: otherSprite; setBackGround: stage; start is equivalent to: scene add: sprite. scene add: otherSprite. scene setBackGround: stage. scene start. In Dart, they use `..` prefix instead of `;` postfix: https://dart.dev/language/operators#cascade-notation https://dart.dev/language/operators#cascade-notation var paint = Paint() ..color = Colors.black ..strokeCap = StrokeCap.round ..strokeWidth = 5.0; You can model this with monads easily, but it's just one, very limited application of them - monads are much more general.
- zem 2y agovisual basic has the `with` statement for that https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/with-end-with-statement https://learn.microsoft.com/en-us/dotnet/visual-basic/langua...
- elcritch 2y agoNim has a similar `with` for the same use case. It can be handy!