[Newbies] Two questions about Smalltalk language design

Tim Retz human.shield.117 at gmail.com
Mon Dec 31 23:16:29 UTC 2012


I may be a total beginner, but if you think of it as objects instead of
code: One object sends a message (the sender), the receiving object (the
receiver) dies something if it understands the message, and then gives the
sender a reply. If the message where a void (no reply), the sender would
get stuck waiting for confirmation, or something along those lines. And nil
is just a name for "nothing", so returning nil would be the same as
nothing.

That's how I see it at least. And if you think about the fact that
Smalltalk was designed to teach children how to code, it makes at least
some sense.
On Dec 30, 2012 9:04 PM, "Casey Ransberger" <casey.obrien.r at gmail.com>
wrote:

> Top post: I never once thought about that, and it makes me smile.
>
> On Dec 30, 2012, at 7:40 AM, Bert Freudenberg <bert at freudenbergs.de>
> wrote:
>
> > On 2012-12-27, at 01:32, Sebastian Nozzi <sebnozzi at gmail.com> wrote:
> >
> >> Why do ST methods return "self" if nothing is explicitly returned?
> >
> >
> > One very simple reason has not been stated yet: In the Virtual Machine,
> returning self is simpler and more efficient than returning any other
> object.
> >
> > Smalltalk byte codes implement a stack machine. That means arguments are
> passed by pushing them onto a stack, rather than putting them into
> registers. In addition to the arguments as listed in the method signature,
> a hidden argument is always passed, which is the receiver of the message.
> So even for unary methods (those without arguments) the receiver is pushed
> onto the stack, then the method is executed, and the receiver value on the
> stack is how the method knows "self". By returning "self" if no explicit
> return statement is given, the VM can just leave the "self" oop on the
> stack, which saves at least one memory store operation. So from an
> efficiency and simplicity standpoint, returning "self" is the most elegant
> thing to do.
> >
> > - Bert -
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > Beginners at lists.squeakfoundation.org
> > http://lists.squeakfoundation.org/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20121231/3359edc1/attachment.htm


More information about the Beginners mailing list