Functions in Action¶

Review Labs 7 & 8¶

  • Review functions lab
    • lab 7
      • Discuss different strategies for each problem
        • soccer fields, ponds
    • lab 8
      • color-bars
        • copy the if block vs wrap it in a function
      • refactoring from lines.py to more_lines.py
        • A single line can be handled with two while loops
        • zeros or more lines need the trigger pattern
        • Sometimes we need to redesign our approach to handle a fairly simple development
      • Boxes
        • How did you decompose drawing squares?
          • draw_red vs draw_blue_green?
          • draw_square that checks the color and adds an extra block?
        • How did you draw the sides of the square?
          • 4 calls to draw_side?
          • erase the original dot and use while bit.get_color() != color?
        • How did you handle getting passed the colored square without drawing more squares?
  • Talk about code reuse

    • Simple functions that embody a generic idea that you can reuse in multiple places
    • go, go_green, turn_around, etc.
  • Talk about the "event-stream" pattern

    • Bit moves towards a defined goal and performs certain tasks along the way when it encounters a cue.
  • Talk about the "mosaic" pattern

    • A larger task is composed of smaller, iterated pieces
    • Ocean, ponds, soccer-fields
  • Talk about preparation

    • Sometimes Bit isn't in the right place for a pattern to start, so move him there first
      • Soccer-fields: move to corner first, then fill the field
      • Ponds: get inside the pond first, then fill it with water

Project 1 - Bit¶