If You Can Dance, You Can Code

Education GeekMom Science Technology
Image by N. Engineer
Image by N. Engineer

Can you shimmy? Can you shake?
Can you step-clap-twirl to the right then the left?
Can you do the Hokey Pokey and turn yourself around?
Because that’s what it’s all about.

Coding, that is. Behind the intimidating circuitry hidden inside the impersonal hardshell exterior known as computers is an elegant simplicity that can unlock countless possibilities limited only by your imagination. The beauty of it is that it is so fundamentally easy to understand, yet capable of doing so, so much. Much like dancing.

As a nation, we need more coders. That is the message being drummed out these days–that there will be a plethora of coding jobs to fill and a dearth of coders. So if programming is the future, why not be a part of it, right?

Of course, knowing how to write a line of code is quite different from being able to build a complex computer system, just as the doing the Twist is nowhere near as complicated as a performance of the Nutcracker or a Dance Team competition, but it starts with the same first step.

But what does this have to do with learning to program? Everything. If you have ever tried to learn the dance to a favorite song (“Uptown Funk”, “Thriller”, something by Paula Abdul, Taylor Swift, or LMFAO) by watching and imitating a video, then you have been programming.

For the purposes of this article, let’s look at the following routine:

Rightfoot step forward right - Leftfoot tap forward right
Leftfoot step back left - Rightfoot step back left
Rightfoot step forward right - Leftfoot tap forward right
Rightfoot step forward right - Leftfoot tap forward right

Leftfoot step forward left - Rightfoot tap forward left
Rightfoot step back right - Leftfoot step back right
Leftfoot step forward left - Rightfoot tap forward left
Leftfoot step forward left - Rightfoot tap forward left

Rightfoot step right - Leftfoot step right
Leftfoot step left - Rightfoot step left
Rightfoot step back - Leftfoot step back
Rightfoot step back - Leftfoot step back

Rightfoot tap heel forward right and clap -
Rightfoot back to neutral
Leftfoot tap heel forward left and clap -
Leftfoot back to neutral
Rightfoot tap heel forward right and clap -
Rightfoot back to neutral
Leftfoot tap heel forward left and clap -
Leftfoot back to neutral

Now, if you were trying to explain these steps to someone, you might adopt a bit of shorthand, perhaps write these steps down on a notecard for someone to keep on hand while on the dance floor or while practicing. (This, of course, is after you send a link to the YouTube video of the dance for them to practice at home.) So let’s substitute RF for Rightfoot, LF for Leftfoot, R for Right, and L for Left. Here’s what you get:

RF step forward R - LF tap forward R
LF step back L - RF step back L
RF step forward R - LF tap forward R
RF step forward R - LF tap forward R

LF step forward L - RF tap forward L
RF step back R - LF step back R
LF step forward L - RF tap forward L
LF step forward L - RF tap forward L

RF step right - LF step right
LF step left - RF step left
RF step back
LF step back
RF step back
LF step back

RF tap heel forward right and clap -
RF back to neutral
LF tap heel forward left and clap -
LF back to neutral
RF tap heel forward right and clap -
RF back to neutral
LF tap heel forward left and clap -
LF back to neutral

Okay, that’s a little easier to read, but do you notice all the repetition? We could group certain details together into a named Dance Step. There are certain patterns that dancers are familiar with (Grapevine, Shimmy, Sashay, Shuffle) that demonstrate exactly what I’m talking about. I’m just looking at grouping individual steps into repeatable processes. The first two sets of four lines above can be grouped.

FrontBackFrontFront(Right):
RF step forward R - LF tap forward R
LF step back L - RF step back L
RF step forward R - LF tap forward R
RF step forward R - LF tap forward R
FrontBackFrontFront(Left):
LF step forward L - RF tap forward L
RF step back R - LF step back R
LF step forward L - RF tap forward L
LF step forward L - RF tap forward L

All I did was group them and name them, but the steps are still the same, right? So let’s move forward. The next couple of lines do the same pair of steps in opposite directions, so let’s do some more grouping:

StepTap(R):
RF step right - LF step right
StepTap(L):
LF step left - RF step left
BackStep(R):
RF step back
BackStep(L):
LF step back
BackStep(R):
RF step back
BackStep(L):
LF step back
TapClap(R):
RF tap heel forward right and clap
RF back to neutral
TapClap(L):
LF tap heel forward left and clap
LF back to neutral
TapClap(R):
RF tap heel forward right and clap
RF back to neutral
TapClap(L):
LF tap heel forward left and clap
LF back to neutral

The letter in parentheses is just clarifying which foot is moving. So let’s look at this again, only let’s just list the dance steps without the details, okay?

FrontBackFrontFront(Right)
FrontBackFrontFront(Left)
StepTap(R)
StepTap(L)
BackStep(R)
BackStep(L)
BackStep(R)
BackStep(L)
TapClap(R)
TapClap(L)
TapClap(R)
TapClap(L)

Now, you may have noticed that there’s still some repetition here, and if you’re handing your friend a notecard, this is the next good place to cut down:

FrontBackFrontFront(Right)
FrontBackFrontFront(Left)
StepTap(R)
StepTap(L)
Repeat x2:
BackStep(R)
BackStep(L)
Repeat x2:
TapClap(R)
TapClap(L)

That’s it. Let’s name this whole program you wrote, enclose it in {} and call it code, shall we?

Program HonkyTonkLineDance
{
FrontBackFrontFront(Right)
FrontBackFrontFront(Left)
StepTap(Right)
StepTap(Left)
Repeat x2
{
BackStep(Right)
BackStep(Left)
}
Repeat x2
{
TapClap(Right)
TapClap(Left)
}
}

Now, follow that program, and notice the steps, as you watch this video. See if you can follow along with the code. Now why don’t you give “coding” the steps a try? Go ahead. I’ll wait.

Your program may have better word choices, and may be written differently, but as long as it gets the outcome desired (someone learning the dance), how you approach it is irrelevant. Similarly, when you write a program, what you want is a particular, very specific, outcome. Certain approaches work better than others in teaching dance, just as certain programming languages may be better suited for particular programs. But let’s not carry the metaphor too far right now.

Conditionals

Now, one thing to note in programming is that you can’t name two procedures the same name, because the computer can’t tell which one to use. Similarly, if you tell someone to SlideClap but one time you mean forward and another time you mean sideways, you’ll face confusion.

But you recognize that FrontBackFrontFront(Right) and FrontBackFrontFront(Left) are the exact same steps just leading with a different foot, right? So when you go in and write the steps for that particular dance step (or, subroutine), just clarify the steps for that particular foot. And be precise. For example:

Subroutine FrontBackFrontFront(foot)
/* This subroutine spells out the steps for the FrontBackFrontFront dance step. Note: this is by no means the best way to write this subroutine, as much of this could be further simplified, but let's leave it as is. */
{
if (foot == right)
{
RF step forward R - LF tap forward R
LF step back L - RF step back L
RF step forward R - LF tap forward R
RF step forward R - LF tap forward R
}
else /*if foot is left */
{
LF step forward L - RF tap forward L
RF step back R - LF step back R
LF step forward L - RF tap forward L
LF step forward L - RF tap forward L
}
}

Okay, I threw in a couple little coding features in this method. In most languages, there is a way to make comments for those people reading the code that the computer will simply ignore. If and when you program, you should use these, for yourself and anyone else who may look at the code. Also, the {} can be nested, and proper indenting helps keep your thoughts well organized. Well-written code can be easy to read and follow.

Order

But I digress. When teaching someone this dance, you would start off by teaching them the individual steps, right? Same thing goes with code. Before you call a subroutine, you tell the computer what that subroutine is. So the beginning of the code will include a list of subroutines, and below that will be the main dance. So, if you created a subroutine where the dancer needs to:

WaWaMaMa() {
shimmy(right)
shimmy(left)
grapevine(right)
ClapAndTwirl(right)
}

Then you would first make sure shimmy(), grapevine(), and ClapAndTwirl() have been mastered. then you would move on to teaching the WaWaMaMa, right? Same thing. There are some basic knowledge you can assume, both for a dancer and a computer language. Different programming languages have certain keywords, certain predefined functions, that can be utilized to create more complex programs, just as the most basic dance steps can be combined in an infinite number of ways to choreograph dynamic, awe-inspiring dance routines.

Final note. The “code” in this article is not written in any particular programming language, so don’t try to enter this into a computer and run it. It is written in pseudocode (namely, fake code, written in the structure of programs but with English words and descriptions, kind of a rough draft). But if it helps you to understand the thinking behind computer programming, that it really is very similar to learning to dance, then maybe we can get more of those great creative minds that have been apprehensive of computers to give programming a try. And that should really help computers dance.

Liked it? Take a second to support GeekDad and GeekMom on Patreon!
Become a patron at Patreon!