← Back to course
Code Crew G3 / Week 08 / Wednesday
3/6
Week 08 Β· Abstraction

Wednesday

// Big idea, small details

Wednesday: Naming Things

Rocket wrote a function named x. "What does x do?" Raven asks. Rocket thinks hard. "I forgot!"

Raven smiles. "What do you notice? A good name tells you what is inside."

Nova says, "A name hides the steps but shows the big idea. Big ideas can stack in layers too." Let's help them pick good names and build layers.

When we name a function (like make_toast()), we hide all the steps inside the name. That's abstraction at work.

Pick the better abstraction

For each, circle the better function name.

do_it_now() OR pour_water()
x() OR greet_friend()
step_a_then_b() OR wash_hands()

Hide the details

These steps are getting ready for bed. Group them under one good function name.

    put on pajamas
    brush teeth
    pick a book
    turn off the big light

function name: __________________

Layered Abstractions

Abstractions can stack. Read the layered plan.

MAKE PIZZA                    (top, big idea)
  └─ make_dough()
       └─ mix(flour, water, yeast)
            └─ stir(20 times)
  └─ add_sauce()
  └─ add_toppings()
  └─ bake(oven_temp=400, minutes=15)

Your turn

Make a layered plan for: WALKING THE DOG. Add at least 3 layers.

Layered plan

Name It to Hide It

NAMES AND LAYERS
  • Read the question.
  • Tap your answer.
Which name is the best abstraction for: get bowl, pour oats, add water?
In the pizza plan, which layer is the biggest idea?
Which layer has the most detail?
Why hide steps inside a name?
A function name that hides details is an ____.
The top layer of a plan shows the ____ idea.
The bottom layer shows the small ____.
StatementTrue or false?
A good function name tells the big idea.?
Layers can stack, one inside another.?
The top layer has the most detail.?
walk_the_dog() could hide put on leash and open door.?
WHY THIS EXERCISEBig programs are built from layers of named steps.

Quick Check

ORDER THE PIZZA PLAN LAYERS: BIGGEST IDEA FIRST
  • ?make_dough()
  • ?stir(20 times)
  • ?MAKE PIZZA
  • ?mix(flour, water, yeast)
WHY THIS EXERCISEPrograms are built in layers of functions. Each name hides the smaller steps under it.
← Tuesday