Abstraction Contraption

9/20

Agenda

1) Parrot Sprite - Inputs

2) Variable Cup Demonstration

3) Counting

4) Abstraction is your friend

5) Fun Fun Functions

Individual Meeting Link: https://meet.lync.com/teals/davidburgess/GMNG2P7J


Abstraction is a fancy word in Computer Science that means hiding complexity. Your brain like a computer (remember we are computers) has a limited amount of memory and it works fastest when it is less cluttered. Abstraction is the tool we will practice using today in order to clean up some of that clutter.

BRAIN WARM UP

For today's coding warm up create a parrot sprite. Using the "ask and wait block" and the "answer" block have the sprite repeat anything the user types to the parrot... forever.

If you are unsure about these blocks drag them into your editor and click them or turn on the checkbox beside answer to get an idea of what is going on.

Submit this to the teals email with the subject WU7.

Swapping Cups

This demonstration will be done as a class. For this demo we will not need the computers. Gather a piece of a paper and writing utensil and be ready to answer questions we present you.

Counting Exercise

Variables are an incredibly powerful part of Computer Science and are needed to do more and more complex things (our favorite) in easier and easier ways. Recall our Numbers example from 8/30. In order to create a counter that went to a high number we had to create a lot of sprites and manage a lot of "state" of our program.

Variables make solving things like this much easier. Use the "make a variable" in your solution to the following exercise.

For this next exercise:

  • Create a sprite
  • The sprite should ask the user for a number
  • Like the parrot above, have the sprite repeat this number
  • HERES THE TWIST whenever the sprite is clicked have the sprite count to the next number. This should continue in a way that each click of the sprite advances the number by 1.

While solving this think about how to break this problem down into smaller more manageable problems. Think about how to advance a counter variable by 1. Think about how you receive input from a user. Try to separate these "concerns" in your code.


Maybe even begin by having the sprite not take in input but instead just count. Once this is handled focus on input.

Variables & You

For today's "exit ticket" brain storm ideas for how you could use variables in your Project 2. Come up with at least 3 ways you could add a variable into your Project and write them down to be submitted by the end of class to the teals@mcpsweb.org email.

Abstraction = Your Friend

http://snap.berkeley.edu/snapsource/snap.html#present:Username=mrburgess&ProjectName=Abstraction

As a group we will review how to use variables to make your code dumber.... dumb code is often the smartest code. By having your code be blissfully unaware of minute details it can focus on what is important at any given point in time.

Building Blocks

Variables hold on to values and serve as containers for numbers or letters. Blocks are the same as variables but for scripts instead of values.

http://snap.berkeley.edu/snapsource/snap.html#present:Username=MrBurgess&ProjectName=Schwifty

Above is a link to some code that has a lot of repetition. Try to find the places where the code is identical. Look for collections of blocks that look exactly same.

Press the left arrow, press the right arrow, press down. Take note of similarities but do not worry about understanding the code. Your goal is to look for patterns. Think less about the overall program and focus on just the repeated parts. This is a form of abstract thought. Thinking about less at any given time so you can solve smaller, more focused problems.


In the same way you created variables to store values try to create blocks to contain the repeated code.

Use the "make a block" button to create a "dance" block with the code that is shared from both the left and right key presses.

Use this same block in both the left and right key press sections.

This removes the duplication that exists in the current code.

Change the down key press code so that it uses the new block as well.

This allows us to hide code so that we do not have to be thinking about it when we are solving other problems. This also keeps us from repeating ourselves, which can be tedious and prone to errors.

If you need a non coding break or finish everything, try these boolean brain teasers

http://puzzlewocky.com/brain-teasers/knights-and-knaves/

http://philosophy.hku.hk/think/logic/knights.php

If you need more to code

Try implementing variables and custom blocks in your Project 2 or try implementing the Pong project from the Projects page.