If You Can Dance, You Can Code: Workshop Guide

I recently had the great fortune to go into a local school and run a couple workshops (with the Technology and Dance teachers) during an afternoon of STEAM Inspiration. Two groups came in for forty minutes each to learn about how dancing and coding are related. How dance code (a.k.a. a routine) is just like a computer program.

I thought it went rather well, but the real test will be whether any of the kids make that shift and decide to explore coding. I thought I’d share my notes about the connection between dancing and coding, and how knowledge of the former can help understanding the latter.

If You Can Dance, You Can Code

When you dance, you perform steps in a particular way. The steps are done the same way each time. When you want to teach someone else a dance, you need to explain it in a way that they’ll understand, so that everyone doing the dance does it the exact same way. If you were to write out the steps to a particular dance, you would likely write it in a way that made it easy to read and follow. You would, in essence, be writing a program. A dance code, if you will.

Before we begin, I want to cover a few programming concepts, namely Loops, Reserved Words, and Pseudocode.

Loops

Many dances call for repeating steps. For example:

```Turn around and clap three times
Turn around and clap three times
Turn around and clap three times
Turn around and clap three times
Turn around and clap three times```

To make the ‘code’ easier to read, it could be written as:

```Repeat 5 times {
Turn around and clap three times
}```

This is a loop. There are three main types of loops (for, while, and repeat) that have slight differences, but the main difference I’ll use in the dancing programs below are the for and repeat (a fixed number of times) and while (as long as a particular condition is met).

Reserved Words

Suppose I were teaching some people a dance. Only, I told them that when I said the word ‘clap,’ I wanted the dancers to jump up. As you can imagine, this would be rather confusing for the dancers. The word ‘clap’ already has a meaning, and expecting dancers to do something completely different is not going to lead to a very reliable performance.

Similarly, there are certain words that already have specific meanings in programming. As you learn a programming language, you learn what these words are and what they mean. Some of these words will appear in the programming examples I have included.

Pseudocode

The final concept I want to introduce is pseudocode, which translates literally to fake code. This is, to me, a necessary first step in any programming project. Basically, while figuring out what you want your program to do, it’s helpful to write it out in a way that’s organized like programming code but using words that you can understand. As you read the dance code examples below, you’ll notice that the directions are written in this way.

I mention pseudocode is organized like programming code. The final point I want to make before we delve into the dance code is that, if you’re teaching someone a complicated routine, you’re going to first teach them individual steps, right? If I tell you to start doing swizzle hands, I’ll first need to explain what I mean by swizzle hands for you to know what to do during the dance.

Similarly, subroutines (also called functions) are defined before they are called, before they are needed. The computer needs to be told what to do ahead of time, so that when a function is called, it already has the knowledge ready.

Example 1: The Chicken Dance

Below is the dance code for the chicken dance. Take some time to practice each of the steps. If you already know the dance, evaluate whether the subroutines adequately describe the dance steps. This is, of course, not the only way to write pseudocode; what’s important is that it is a way to communicate what you want your computer (a.k.a. your dancer) to do.

```class chicken_dance {
function gobble() {
put hands, palms forward, on sides of head
repeat 4 times {
open palms
bend 4 fingers down
bend thumb up to touch fingers
}
}

function chicken_arms() {
tuck hands under same side armpits
repeat 4 times {
lift elbows up
lower elbows
}
}

function wiggle() {
Repeat 2 times {
move hip to one side
move hip to other side
}
}

function dosido (side) {
lift side arm and bend at elbow
turn to opposite(side)
step to person facing you
lock elbows(side)
walk_in_circle(opposite(side))
}

function chicken_dance() {
while (music_playing) {
face front
gobble()
chicken_arms()
wiggle()
Repeat 4 times {
clap hands
}
dosido(right)
dosido(left)
}
}

>> chicken_dance()```

Debugging Dance Code

An important part of programming is testing. Running through your program, seeing how it works, fixing any problems. So, how did it work? If you were to do the dance following these steps, do they work? Or did you notice a problem?

Look at the code for the dosido. First of all, as you do the dance, you may have noticed that when dancing, you have time to dosido twice in each direction. This bit of dance code should be fixed to add a Repeat loop around it. Also, to be more precise, we could specify how quickly the dancers should be moving as they turn in a circle. All these details are missing in the pseudocode, but should be resolved—through rounds of trial and error—until you’ve got an error-free program. Just as you would do when choreographing a dance.

```class Hokey_Pokey() {
function put (side, bodypart, direction) {
if (direction==in)
move side bodypart forward
else /* if (direction == out) */
move side bodypart behind you
}

function shakeItAllAbout ( side, bodypart )

function turnYourselfAround() {
wiggle hands on sides of head
turn in circle
}

function Hokey_Pokey() {
Body = Array {‘foot’, ’arm’, ‘elbow’, ‘head’, ‘hip’}
for each part in Body {
put (right, part, in)
put (right, part, out)
put (right, part, in)
turnYourselfAround()
clap 3 times
}
}

>> Hokey_Pokey()```

Challenge:

1. Find the error in the code. Can you suggest a way to fix it?
2. How would you modify the program to add whole self? backside? Hokey Pokey at the end

Programming Exercise

Now try writing your own program. Play some music, write out dance steps as specifically as possible. Then give your ‘program’ to someone else and see if they can perform the steps exactly as you meant them to be done. If not, make the necessary changes. Try to do this without explaining what you meant. Try to do this without knowing who will be doing your steps. Once you can do this, you’re well on your way to thinking like a programmer.