Skip to main content
Engineering LibreTexts

2.6: Sending Messages

  • Page ID
    39575
    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    In the Pharo window, click on an open space to open the World Menu, and then select the Playground menu option. The Playground tool will open (you may recognize it as the Workspace tool, from previous versions of Pharo). We can use Playground to quickly execute Pharo code. Enter the following code in it, then right click and select Do it:

    ProfStef go.
    

    This expression will trigger the Pharo tutorial (as shown in Figure \(\PageIndex{2}\)). It is a simple and interactive tutorial that will teach you the basics of Pharo.

    Congratulations, you have just sent your first message! Pharo is based on the concept of sending messages to objects. The Pharo objects are like your soldiers ready to obey once you send them a message they can understand. We will see how an object can understand a message, later on.

    Do it menu item.
    Figure \(\PageIndex{1}\): Executing an expression is simple with the Do it menu item.
    PharoTutorial.
    Figure \(\PageIndex{2}\): PharoTutorial is a simple interactive tutorial to learn about Pharo.

    If you talk to Pharoers for a while, you will notice that they generally do not use expressions like call an operation or invoke a method, as developers do in other programming languages. Instead they will say send a message. This reflects the idea that objects are responsible for their own actions and that the method associated with the message is looked up dynamically. When sending a message to an object, the object, and not the sender, selects the appropriate method for responding to your message. In most cases, the method with the same name as the message is executed.

    As a user you don’t need to understand how each message works, the only thing you need to know is what the available messages are for the objects that interest you. This way an object can hide its complexity, and coding can be kept as simple as possible without losing flexibility.

    How to find the available messages for each object is something we will explore later on.


    This page titled 2.6: Sending Messages is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.