My suggested Hello World for introducing programming to non-programmersPosted on April 1, 2018
In accordance with the ancient traditions of our people, we must first build an app that does nothing except say "Hello world".
> -- React Native's tutorial
"Hello world" is very useful as an introduction to a library or a programming language. The reasons for this are:
- Almost all programs need to output to screen.
- It tests that the library or programming language is working. (this simple test is called a black triangle)
- By focusing on one thing, you can have a simple understand of how the code is written, what tools are needed to execute, and satisfaction that you've completed the first tutorial.
This are great reasons to use "Hello world". ....but not as an introduction to non-programmers.
As a developer, you already have the intuitive foundation on how programming works. You've done this before. This isn't your first dance. Not so for non-programmers.
# Non-programmer mindset
I've taught programming to 1st year college students. I've also taught programming to young adults and older people. They all have something in common: they are naturally intimidated. They think they could break the computer or accidentally hack someone. Programming is scary to non-programmers.
To make programming less intimidating, teachers should make the student confident. Build up their confidence that they have the ability to understand programming.
So instead of starting with hello world, let's start with something simpler: variables and operators.
# First lesson for non-programmer
I teach Python to teach programmers. Other languages are fine and can be used (except Java, but that's another blog post; nothing's wrong with Java the language, but its not really a good first programming language). Just adjust accordingly.
First thing I tell my students is to open the Python shell. From here, I ask them to type the following:
> a = 1
> b = 1
I then type the following command and ask the students NOT to press the enter key. I'll ask them to tell me what they think the answer will be.
> print(a + b)
No surprise, it's 2. As a joke, I'll tell them to now press the enter key. If it isn't 2, then their computer failed to compute. I usually get laughs at this point, but it does release some tension.
I then ask the room why they thought the output is 2. Different audience have different answers, but it establishes early on that this is the basics of programming. I'll clarify that a and b are what we call variables (I'll write this on the whiteboard) and the right side of the equal sign is the value.
I then point to the = and + symbols. I ask them what symbols they are. I know its pedantic, but if someone said plus or equal to, I tell them that I asked for the symbol and not the operation (this distinction is important later).
To reinforce the difference between symbols and operations, I'll write on the board "= assignment operator" and under a header of "numeric operators", I'll write "+ addition". It is at this point that I'll introduce the other numeric operations such as -, , and /.
This is also how I introduce functions as I point to the print command (admittedly, this is what Hello World does). I'll tell the audience that it is obvious, but I need them to tell me what the function does.
A function is basically an instruction to the computer and it is obvious. But by letting the non-programmer figure it out themselves, it invokes the sense of understanding and makes them think that they can do programming. It also makes non-programmer feel smart, which is an important point in learning something new.
## Introducing data types
Next, I'll ask them to type these:
> c = "1"
> d = "1"
> print(c + d)
After executing, I'll ask them all, what is "one plus one"? Of course, the classic homonym pun is invoke... "one plus one is... one one...? are you kidding me?"
This where I introduce a new header for "string operators" with "+ string concatenate". I then introduce data types and that computers operate differently depending on the types.
## Introducing errors
The last part of this first lesson uses the following code:
> print(a + c)
This would introduce an error. Specifically, a "Type Error". I'll tell the students this story:
> Computers are exact and precise. But they are stupid. You need to tell them exactly what you want and how to do it. If you give them an instruction that they don't understand, they will give what is called an error*.
> This makes sense - it is better for a computer to stop working... because the alternative is that the computer will guess on what you want to do. And this will be very bad.
> Errors are normal. I've been programming for over 20 years and every time I code, I'll get an error. There is nothing to be afraid of errors.
# The first introduction to programming shouldn't be "Hello World", but the fundamentals.
With this lesson, I was able to introduce:
- Data types
- The idea that a programmer is someone who think of what code is written and how it affects the program.