Structure diagrams

Fu Wei Hsu's Jojo​
Fu Wei Hsu's Jojo​

Structure diagrams

Often, variables are glue that sticks code chunks to together. Here's the code again:

  1. # Make a name tag.
  2. # Input is first and last name.
  3. # Written by Kieran Mathieson, June 11, Year of the Dragon
  4.  
  5. # Input
  6. first_name = input('What is your first name? ')
  7. last_name = input('What is your last name? ')
  8.  
  9. # Processing
  10. full_name = first_name + last_name
  11.  
  12. # Output
  13. print('Hello!')
  14. print('My name is')
  15. print(full_name)

Here's a structure diagram showing the variables that chunks pass to each other.

Structure diagram

You can start a programming task by drawing a structure diagram if you want. Makes it easier to see how chunks fit together. We'll work on that in the next course module.

A great big deal

Looking underneath the surface of a task for its patterns and deep structure is a Very Important Thing (VIT).

Reflect

You'll be more valuable to your employer if you can look underneath the surface of tasks. Why?

If you were logged in as a student, the lesson would pause here, and you'd be asked to type in a response. If you want to try that out, ask for an account on this site.
Ethan
Ethan

I'm just thinking here. Say you get a job, and the boss says, "Write a name tag program." You can do it because you learned how to write a name tag program in this course.

Next day, the boss says to write a program to write a mad lib program. You never learned that exact task. You say, "Sorry, I don't how to do that." Not great.

But really, you do know how to write the mad lib program, if you look beneath the surface. Take the IPO pattern for the name tag program, and adjust it for the mad lib program.

Great answer! If you can look under the surface, you know how to write hundreds of programs businesses want. Different tasks, but they all use the IPO pattern. And yes, the mad lib program would be IPO.

The most tasks someone can do, the more valuable they are, and the more money they'll be worth.

Money

​Hey, Ben!

Money is good. You can afford more dogs. And buy a house in a good neighborhood, and stuff like that, but it's the dog thing that matters.

The best way to be productive, and get more Benjamins, is to know common programming patterns.​

Let's make that a principle:

Principle

Think about program structure

When you get a new task, don't get hung up on all the deets. Look for the structure underneath.

Summary

Read summaries to reactivate memories for ideas, making them easier to recall.

  • A structure diagram shows the chunks and the variables linking them together.
  • Look under the surface to find a program's structure. You can use that structure for hundreds of tasks.