Sergi Reyner wrote:
First required reading....
https://xkcd.com/386/
Second required reading...
http://paulgraham.com/avg.html
Skip down the section "The Blub Paradox"
Now having said that :) even though I'm not an expert in either Java
or Smalltalk, I'm happy to have a crack (and learn something in the
process where I'm wrong)
You might not need to win the debate, but some examples might be
useful. First showing how /this/ & /thisContext/ are different
while /this/ & /self/ are the same.
Object subclass: #ContextExampleA.
ContextExampleA subclass: #SubA.
ContextExampleA>>whoAreYou
^ 'I am A'.
SubA>> whoAreYou
^ 'I am SubA'.
ContextExampleA>> report1
Transcript show: self whoAreYou.
ContextExampleA>> report2
Transcript show: thisContext whoAreYou.
----------------
So evaluating...
MySuper new report1.
MySub new report1
outputs...
I am A
I am SubA
and evaluating...
MySuper new report2
produces Error - /thisContext/ does not understand message #whoAreYou
---------------
Object subclass: #ContextExampleB.
Object subclass: #ContextExampleC.
ContextExampleB>>whoAreYou
^ 'I am B'.
ContextExampleC>>whoAreYou
^ 'I am C'.
ContextExampleA >> reportA
ContextExampleB new reportB.
ContextExampleB >> reportB
ContextExampleC new reportC.
ContextExampleC >> reportC
| context |
context := thisContext.
3 timesRepeat:
[ Transcript
show: context printString ;
tab ;
show: context receiver whoAreYou;
cr.
context := context sender.
].
thisContext inspect.
----------
So that evaluating...
ContextExampleA new reportA
outputs...
ContextExampleC>>reportC I am C
ContextExampleB>>reportB I am B
ContextExampleA>>reportA I am A
-----------
Here the execution call stack has been traversed to send a message to a
receiver a few levels down. I'm not sure of the practical utility of
that, but how would Java do a similar thing?
cheers -ben