Upgrade to Pro — share decks privately, control downloads, hide ads and more …

M250 Unit 2 Subsection 4 - Message arguments (8)

Avatar for Matt Matt
January 08, 2020

M250 Unit 2 Subsection 4 - Message arguments (8)

Here we explore the exciting world of message arguments.

Avatar for Matt

Matt

January 08, 2020
Tweet

More Decks by Matt

Other Decks in Education

Transcript

  1. Firstly let’s recall that objects can receive messages and that

    the code to make this happen is called a message-send. For example, kermit.jump() Arguments
  2. Some messages also include extra information that is placed in-between

    its brackets. Each piece of information inside of a message’s brackets is called an argument. For example, a message sent to a Frog object could be: setPosition(3) Here, 3 is the argument. Sending this message would set a Frog object’s position to 3.
  3. A message might take multiple arguments. For example, let’s imagine

    a message that could be sent to HoverFrog objects called setPositionAndHeight(). It would take two arguments that represent the position and height that we want to set the object’s position and height attributes to respectively. Assuming gribbit is an instance of HoverFrog, we might construct the following message-send: gribbit.setPositionAndHeight(5, 3)
  4. The important thing to remember is that some messages require

    no arguments, some require one argument, and some require multiple arguments. And this depends on how the message is programmed to work.
  5. Messages and message names When a message does require an

    argument (or multiple arguments) that message isn’t complete until the argument is provided. This makes sense when you think about it. A message like setPosition() isn’t complete until we provide it with a value to set a position to. (Note the use of camelCase for message names.)
  6. For this reason it is not strictly correct to use

    the phrase “the message setPosition()”. Because setPosition() isn’t a message because it requires an argument and we haven’t provided it. We use the term message name to refer to the name of the message without its arguments. That is: • The “message” is the message name AND its required arguments. E.g. setPosition(10) • The “message name” is the message WITHOUT its required arguments. E.g. setPosition()
  7. But note. If a message doesn’t take any arguments then

    the message and the message name are the same thing. They are identical. For example, the message jump() doesn’t take any arguments – therefore the message is jump() and the message name is also jump().
  8. But also note that to be more concise when we’re

    learning about programming concepts, the gap between what is technically a message and what is technically a message name does tend to get blurred. It’s important to recognise the difference, but many programmers would happily use a phrase like “the message setPosition()”, even though technically this is a message name.
  9. Questions Identify the message, message name, arguments, and receiver of

    the following: 1] kermit.setPosition(5) 2] gribbit.croak()