Keith Ray writes about multiple return values in Python and Smalltalk...
# Python example...
beforeNotAfter, afterNotBefore = foo.findNonOverlappedElements( before, after )
# do stuff using beforeNotAfter
# do stuff using afterNotBefore
foo findNonOverlappedElementsOf: before and: after
doing: [ :beforeNotAfter :afterNotBefore |
"do stuff to beforeNotAfter".
"do stuff to afterNotBefore" ]
The other aspect of the Smalltalk solution here is "tell, don't ask". We tell 'foo' to find the non-overlapped elements, and we tell foo what to do with the resulting lists of elements (execute our block). This forces a certain cohesion to our code. The Python example is violating the spirit of the Law of Demeter, if not the actual Law (1) because we ask and then work the results of what we asked.
But I don't see how the Law of Demeter is involved in this. Neither the Python nor the Smalltalk examples divulge anything about the implementation of
foo. There are no undue dependencies.
In fact this is one use of a
Block in Smalltalk that obfuscates the code. Python's simple syntax for returning tuples into a multiple assignment is the simplest mechanism for this scenario.