Session 4 Preparation — Videos, Reading and Quizzes

Quizzes:

Do this Quiz on Session 4 as you watch the videos and do the reading (as listed below). This document is a Microsoft Word document; here is the same Quiz on Session 4 (pdf) as a PDF.

You can either:

In either case, turn it in via the Session 4 Dropbox on our Moodle site.

Videos and Reading (online and textbook):

All of the following are required except the items labeled Optional are, well, optional (i.e., things that may be interesting but do not directly pertain to your success in this course).

  1. The Debugger

    Note: Do not try to learn all the details of the Debugger — just breeze through this video to get the ideas, and return to it later as needed. The questions in the quiz highlight the main points.

    • Video (embedded in a web page) [13:04 minutes]
    • Video (as an mp4 that you can download if you want)
  2. The Accumulator Pattern — Summing
    • Video (embedded in a web page) [7:32 minutes]
    • Video (as an mp4 that you can download if you want)
  3. Functions as Black Boxes
    • Textbook reading: Section 5.1 (2 pages).
      • The link is to a scanned copy for your convenience. The real textbook is easier on your eyes.
      • This is a very nice, very important section; read it carefully. After reading it, you should be quite clear about the following (some of which you have seen before this reading):
        • What it means to call a function.
        • What arguments are, and what it means for them to be “sent to” the function.
        • What it means for a return value to “come back from” the function.
        • How the two previous items are totally different concepts from input and output to the Console.
        • How to capture a returned value in a variable.
        • Why a function can be thought of as a black box, and what this term means.
  4. Implementing and Testing Functions
    1. Textbook reading: Section 5.2 (4 pages).
      • The link is to a scanned copy for your convenience. The real textbook is easier on your eyes.
      • Focus your attention on:
        • The syntax (notation) for defining functions, as shown nicely in diagrams Syntax 5.1 (page 223) and Syntax 5.2 (page 224).
        • The special role that we choose, by convention, to give to the main function.
    2. Textbook reading: Programming Tip 5.1 on page 226, at the end of Section 5.2 (1 page)
      • The link is to a scanned copy for your convenience. The real textbook is easier on your eyes.
      • This tip explains the importance of comments, but you have seen that forcefully presented in a preceding video on specifications. This section contrasts the style used in the text with the style that we use in your assignments.

        As the section points out, the key is not which style you use (that depends largely on the coding standards of your organization) but rather that [from page 226]:

        The function comment does not document the implementation (how the function does what it does) but rather the design (what the function does, its inputs, and its results). The comment allows other programmers to use the function as a “black box”.

  5. Functions with Parameters and Returned Values
    1. Read this explanation of Functions with Parameters
      • Read this important explanation carefully!
      • It reinforces what you saw previously in a video on functions.
      • BRING your QUESTIONS about it (and the reading below from your textbook) to class.
    2. Textbook reading: Section 5.3 — Parameter Passing (3 pages).
      • The link is to a scanned copy for your convenience. The real textbook is easier on your eyes.
      • Focus your attention on:
        • What parameters are.
        • How a function's parameters get values when the function is called.
        • The fact that each time the function is called, the function's parameters get a new set of values.
    3. Optional textbook reading: Section 5.4 — Return Values (9 pages).
      • The link is to a scanned copy for your convenience. The real textbook is easier on your eyes.
      • You will have already absorbed the key ideas of this section from other sources and the exercises you have already done in class. However, you might (or might not) find the following valuable:
        • The How To 5.1 on pages 231 - 232.
        • The Worked Example 5.1 on pages 233 - 237.
      • You will experience the material of Section 5.4 in class, so may (or may not) feel the need also to read about it. In any case, be aware that if you do choose to read Section 5.4, it contains references to material from Chapters 3 and 4 that we have not presented yet.
    4. Textbook reading: Sections 5.5 — Functions without Return Values (1 page).
      • The link is to a scanned copy for your convenience. The real textbook is easier on your eyes.
      • When you finish reading this section, you should have a clear understanding of the difference between print and return.
  6. Scope and Namespaces
    1. Textbook reading: Section 5.8 — Variable Scope (3 pages, ending at the important Programming Tip 5.6 Avoid Global Variables).
    2. Skim/read this handout on Namespaces and Variables' Scope

    For both of the above, the quiz will help make the ideas concrete. Bring your questions to class — you are likely to have questions about this material.