When we write a program,
we're figuring out a way to turn
the brilliant ideas in our head
into actual code.
Here I want to talk about a technique
that many programmers use to do that,
and it's what we call "pseudocode."
Now, "pseudocode" is probably a word
you never heard before,
but basically it's code
that looks a lot like English
or really whatever language
you like to talk in.
Well, okay, that may not make sense,
so let's talk through an actual example.
So let's say that I want to draw
a nice symmetrical face.
So I might start by looking at myself
in the mirror and maybe sketching it out
and seeing, okay, well I have this oval face.
I have two eyes,
and they're about at this level.
And this is what
the center of the face is
and now I have an idea for what
I want my face to look like.
So I'll start writing it in pseudocode.
So let's see, the first thing
we'd want to do is draw the face,
which is an oval, in the center.
Then we'd want to draw the two eyes,
which are two ovals,
about two thirds up the face,
and one fifth the size of the face.
Not exact math there
just looking at my own face.
And then we draw the mouth, which is
a line going halfway across the face,
and maybe one third of the way up.
So notice how I write
my pseudocode as comments
by starting each line
with the two slashes here.
That way I can write my pseudocode
in the program itself
and not have to worry about
getting any syntax errors
because the program will ignore comments.
Now that I've written this in pseudocode,
I can spend the time to turn
each of these lines of pseudocode
into actual bits of code
Right? So let's see, for the face
I need an oval in the center.
For that I'll use the ellipse function for,
and I'll, you know, figure out
the center of the screen here,
and figure out an eye size.
Okay?
That looks good.
For the eyes once again
those are ellipses.
Everything on my face is an ellipse.
I'm very round.
And it's going to be, let's see,
we'll do some math here to get the eyes
at a nice place, and make them
about a fifth the size.
Okay, that looks good for the first eye.
I'll just copy paste, make the next eye.
Great!
Now I can even leave my pseudocode
for a friend to implement,
and they probably could,
because they can, you know,
I have given this really nice description.
So I'm going to do that here,
because, you know, we're friends, right?
So, you might think this is silly.
Why are we going through the effort
to write our program twice?
First in human language
and then in program language.
Well, this example was pretty simple,
but pretty soon you'll be building
more complex programs,
and it may be hard for you to keep
the whole program in your head
before coding it.
So what I usually do is write the general
idea in pseudocode first,
and then I'll spend more time on
the details of each part of that idea,
converting each line
of pseudocode into real code.
I think you'll find that once you start
using pseudocode
you'll do it more and more.
Try it in your next program and see.