3.5. Paint Pot Refactoring and Documentation

This lesson modifies the app enhanced in the 'Paint Pot Projects', not to change any functionality, but to improve the code, a process called refactoring. In this case we will introduce the concept of a programmer-defined procedure that will help reduce the complexity of our code and make it easier to read and maintain. A procedure is a named grouping of instructions that can be used where needed in a program by invoking its name. This is known as 'calling a procedure.' This lesson reinforces the enduring understanding that procedures are useful abstractions that are used by programmers to structure and simplify programs (procedural abstraction). We will also add comments as a way of documenting the purpose of the procedure.

Professional Development

The Student Lesson: Complete the activities for Mobile CSP Unit 3 Lesson 3.5: Paint Pot Refactoring and Documentation.

Materials

  • Presentation system (LCD projector/Interactive whiteboard)
  • Access to computer, laptop, or Chromebook (install the Companion app on Chromebooks)
  • Access to mobile device with the Companion app installed or access to the emulator installed on the computer or laptop. 
  • Paint Pot Refactoring Text Version or Videos
  • Wikipedia article on refactoring

3.5.1. Learning Activities

Estimated Length: 45 minutes

  • Hook/Motivation (5 Minutes): Here are some suggestions.
    • Show the students the lyrics of a children's song where there is a chorus like This Old Man and have them point out any lines that are repeated. These can be pulled out into a procedure called chorus and called whenever needed. This is procedural abstraction.
    • Show the students the code from a finished Paint Pot app or the template for this app. Ask them to find the duplicated code, i.e. the same blocks of code that are used in more than one event. They should identify the blocks to update the dot size label. Explain that you will learn how to create procedures, which give a name to a block of code that can then be reused in the program. You will also be adding comments to the procedure to document what it does for yourself and other programmers.
  • Experiences and Explorations (20 minutes): Instructors can lead students through the tutorial, can show the video (4:32), or can allow students to watch it on their own. Students can work in pairs to either update their existing app from the Paint Pot Projects lesson, or they can use the template provided in the lesson.
  • Rethink, Reflect and/or Revise (20 minutes):
    • Students should work on completing the self-check exercises. If time, review them as a class to ensure students are writing procedures correctly.
    • In their portfolios, have the students answer the portfolio reflection questions found in the Mobile CSP lesson. Now that they've refactored their code, ask them how many blocks would need to change in the code if they wanted to use a slider or another UI component to display the dot size to the user? Do they think it is easier or harder with the procedure? Can students think of where they might add comments or procedures in other apps they have created?

AP Classroom

The College Board's AP Classroom provides a question bank and Topic Questions. You may create a formative assessment quiz in AP Classroom, assign the quiz (a set of questions), and then review the results in class to identify and address any student misunderstandings.The following are suggested topic questions that you could assign once students have completed this lesson.

Suggested Topic Questions:


  • Topic 1.4 Identifying and Correcting Errors 

Assessment Opportunities and Solutions

Solutions Note: Solutions are only available to verified educators who have joined the Teaching Mobile CSP Google group/forum in Unit 1.

Assessment Opportunities

You can examine students’ work on the interactive exercise and their reflection portfolio entries to assess their progress on the following learning objectives. If students are able to do what is listed there, they are ready to move on to the next lesson.

  • Interactive Exercises:
  • Portfolio Reflections:
    LO X.X.X - Students should be able to ...
  • In the Paint Pot App, look for:
    - Correct definition of a procedure
    - Correct calling of a procedure
    - Appropriate use of comments to document the procedure

Differentiation: More Practice

Students can watch this 1-minute video on defining a procedure or read more about procedures in the AI Documentation.

Differentiation: Enrichment

Students can review previous apps to see if they should add comments or procedures anywhere else.

3.5.2. Professional Development Reflection

Discuss the following questions with other teachers in your professional development program.

  • How does this lesson help students toward the enduring understanding that programming is facilitated by appropriate abstractions, such as procedures?

    I am confident I can teach this lesson to my students.
  • 1. Strongly Agree
  • 2. Agree
  • 3. Neutral
  • 4. Disagree
  • 5. Strongly Disagree