# What program follows “hello, world”?

You've just demoed your first bit of code in whatever language you're teaching. The requisite "hello, world" has been said. The program has been compiled (or interpreted) and run. Now what?

There has to be a program that follows "hello, world" that builds upon the basics of printing one line on the screen.

What is the logical next step in an introduction to a new language and possibly to programming as a discipline in general? We all know program #0; what's program #1 and why?

Note: I know this is subjective, but I'm hoping it leans the good way. I'm trying to ascertain the scaffolding at an introductory level. Once the cliched example is complete (not that it doesn't have a lot to teach in and of itself), what makes sense as the next curricular step? I think the need for justification based on experience, expertise, and facts helps it from being too broad, but I'm happy to revise if necessary.

• FYI: The traditional meaning of "hello world," has nothing to do with learning a new language (or a first language). It always was about learning a new toolchain. It was not a program that you wrote for yourself; It was a program that somebody gave to you. As in, "Here, when you can get this known-good source code to compile and run, then you will be ready to compile and run something of your own." – Solomon Slow Mar 31 '19 at 19:51
• P.S., I am not an educator, I'm a software developer. Been working almost forty years, and still go through the "Hello World" experience--proving that I can install, configure, and use the build tools for a new project--on a pretty regular basis. – Solomon Slow Mar 31 '19 at 20:02

When I was teaching and mentoring first-time students, what got them really excited for the first time was seeing their name in lights. Write a program that allows a student to enter their name, then print it on the screen 10 times (or 10,000).

• It introduces the concept of variables and variable types
• It shows how computers interact with the outside word by accepting input from the students
• It introduces basic looping and conditional statements in a really simple example
• It shows how math and computation works in a computer without simply spitting out basic algebra.

The best part is the students don't have to understand 100% of the program to start picking out the individual parts. The basic program flow is somewhat intuitive. You can start without the loop and add it in later as you introduce the concepts. This simple exercise is straightforward enough to teach the underlying concepts of how programming works in a somewhat entertaining, interactive application.

• This is potentially #1, #2, #3, #4... – Sean Houlihane Jun 2 '17 at 15:48

I did a (rather unscientific) study of a few popular tutorials for Python to see what they did after "Hello, world":

• Learn Python the Hard Way introduces expressions (25 + 30, 5 + 7 > 3 + 1), and implicitly hints at types (although never mentions them by name in the chapter after "Hello, world").

• Codecademy introduces variables (assignment), then types, then reassigning variables.

• Automate the Boring Stuff with Python introduces expressions and types.

• Google's Python introduction introduces assignment, expressions, and very quickly moves on to functions. The pace of their tutorial seems a lot faster than the others I checked.

So, purely from what other tutorials and resources do, it seems that expressions are the most important next step. Notably, none of the resources I tested introduce input() in the next step—clearly, it's more important to learn about variables and how to store values from functions first.

If these resources are to be trusted, the best second program would look a little like this:

print('5 + 2 is', 5 + 2)
print('5 is less than 4?', 5 < 4)
eight = 2 * 4
print("2 * 4 is eight?", eight == 8)


Note that in this example, you subtly introduce the fact that comparing values is done with ==, not =, and there's a link to bool values, int types, etc. Whether you explicitly mention them at first is up to you—some resources do recommend it, and some don't.

After "Hello World" it becomes "Hello \$name" where \$name is provided by user. After basic I/O and "it compiles and runs", then it is time for loops and logic. I typically like a variation on fizzbuzz:

Print the numbers 1 through 100, if the number is evenly divisible by 3 print "fizz" next to the number, if evenly divisible by 5 print "buzz" next to the number, if evenly divisible by both 3 and 5 then print "wahoo!" next to the number.

I've always used Hello name" as part of Hello World. It's easy enough for most students and makes the program more fun. After Hello World I use a conversion program. For example Fahrenheit to Celsius. That makes a lot of sense in the US but might not in other countries. But there are many conversions that make local sense in other parts of the world. Pounds Sterling to Euros perhaps. Students often like money problems.

Conversion programs involve both input and output but add the introduction of assignment statements and calculations. More involved calculations allow for a review of the order of operations (one reason I use Fahrenheit to Celsius). Students get interesting results if they don't set up the formula correctly.

Conversion programs also let one introduce testing early in the game. Sure the program compiled, ran, and gave you an answer but how to you know it is the right answer?

There's absolutely no reason your first program needs to be "hello world" in the first place.

You can start with values of various kinds, and show how to combine them to create more interesting values. For instance, in How to Design Programs, we start out with numbers, strings, and images.

Pretty quickly students can start to create interesting pictures: e.g., flags of various countries, or a scene (imagine a beach with a tree and a sun). Now they can start to change the size of that flag or parts of that scene (e.g., the sun is at different positions).

Next they can make a function that given a parameter, produces the flag or scene at that time (by using the parameter to calculate the position of the sun). Now they supply this to a function called animate and they have their first animation. From there they can go on to much more sophisticated animations.

In short, we think a rocket launching off a pad — a good metaphor for their education — is a pretty nice follow-up, and not that hard to do. The book's prologue (http://www.ccs.neu.edu/home/matthias/HtDP2e/part_prologue.html) shows this progression.

You program with images, create the flags of several countries, then lay them over backgrounds, then animate them, and build up to a game. You can do all that in the first week or so of your course if you have the right curriculum. See, for instance, the prologue of How to Design Programs (second edition).

• +1 for DrRacket which I love as an environment and would love to teach with some day. – Peter Jun 3 '17 at 1:19
• If you're at the middle-/high-school levels, take a look at the Bootstrap family of curricula. There's something in there for everyone, and cut from the same cloth. – Shriram Krishnamurthi Jun 3 '17 at 11:52
• This does not seem like a program that would come right after "Hello World", it seems more complex than that. – thesecretmaster Jun 29 '17 at 12:12

I was taught that there were three main aspects of programming:

1. input-output,
2. computation, and
3. logic/control

"Hello world" is an "input-output" function, specifically a "print" command. The next thing I would teach is a simple computation, even something like 1+1=2.

For example:

X=1
Y=X+X
Print Y

• TBH logic/control should come first - but in order to see it happen and make sure it works, you need the I/O too (well, at least the O) – ivanivan Jun 22 '17 at 23:43

The next step is to introduce the type system. Students need to know what kinds of data are "understood" by a language. The "Hello World" program gets the ball rolling because you can ask, "How is text stored? Are there other types of data that can be stored as well?"

I think that a reasonable next step is showing them variables with an I/O basis. Things like:

• using "Hello, world!" or something similar as a string and printing it

• using integers and showing students the different operators for the language (add/subtract/multiply/divide/modulus division/integer division)

I very much like "The Devil and Daniel Webster", as introduced to me by Devika Subramanian. It connects programming to mathematics, and introduces lists, loops, and if conditions in a fairly simple wait, with an interesting story.

The lecture notes I've found for them are below, but the problem is:

The devil made a proposition to Daniel Webster. The devil proposed paying Daniel for services in the following way:"On the first day, I will pay you \$1,000 early in the morning. At the end of the day, you must pay me a commission of$100. At the end of the day, we will both determine your next day's salary and my commission. I will double what you have earned at the end of the day, but you must double the amount that you pay me. Will you work for me for a month?""

• I don't entirely understand the problem. Do we have some way of determining what D.W. will earn? I'm any case, welcome to Computer Science Educators! – Ben I. Jun 30 '17 at 12:25
• It's just the payout minus the commission: so 900 for the first day. – sfogarty Jul 1 '17 at 21:23
• So, on the second day, he would earn \$1,800, but have to pay \$200? – Ben I. Jul 1 '17 at 21:25
• Exactly. Have them turn it into a pair of formulas for each day with subscripted variables. Then we start writing code, and see that we'd end up with 60-odd variables. Introduce lists as a way of having variables with subscripts. Then build up lists manually a few times, and introduce them to for loops. Then at the end you can use an if, outside the loop, to check the final values. Lists, for loops, and if statements. For my non-majors class it takes three 70-minute classes to get through, but it presents a coherent (if fanciful) problem to motivate them. – sfogarty Jul 2 '17 at 22:06

I found 'FizzBuzz' really helpful as the next exercise, it has conditions, loops and it also allows you to explain some coding practices, especially DRY (Don't Repeat Yourself).

"Write a short program that will simulate playing FizzBuzz. The rules are simple:

• Count from 1 to 100 and print the numbers on screen
• If the number is divisible by three, print Fizz instead of the number
• If the number is divisible by five, print Buzz
• If the number is divisible by both three and five, print FizzBuzz

Write as few lines of code as possible."

This is also an exercise that was used a lot on job interviews to determine if someone could actually code and apply good practices.

And for an in-depth explanation on what constitutes a good result: Tom Scott: FizzBuzz

I agree with the answer proposing Hello name, and the answer that proposes students inputting their name and then repeating it x times. Then a conditional can be introduced that does or does not print their name depending on some boolean expression or similar. At this point, we would have introduced: types, input (and output), repetition, conditionals, and possibly some mathematics.

## Consider also going the other way.

We often think of teaching from small to big. However it is often possible and beneficial to go from big to small. Bertrand Meyer does this in his course “Touch of Class”.

Provide the students with a working program, have them read the program, make some predictions on what it does, then run it, determine what some of the key grammar/vocabulary does, make predictions on what changes will do, then make changes and re-run.

• I think this is an important answer. – Ben I. Aug 23 '17 at 14:11

You might find some more ideas here:

My approach is designed for Processing, but hopefully it generalizes to other languages.

Hello World is really a lesson in how to call functions. After they understand the basics, I'd show them how to lookup other functions in either the language reference or in a beginner-friendly list that you give them. In Processing, I'd have them draw a circle or a rectangle, or an entire scene using basic function calls. If your hello world is a console application, then maybe have them display a popup box, or display a message in a window. The specifics of this depend on the language you're using, but the idea is to get them looking stuff up in a reference and playing around with their own code.

From there I'd go to using variables. This is different than creating variables. Instead of having students create variables, have them look up whatever predefined variables your language offers. Processing has width and height variables, so I'd have them make their scene scale to the size of the window. But you would use whatever variables your language exposes. Again, have them look stuff up in the reference or in a list you provide them.

From there I'd have them create their own variables and their own functions, which I've explained in more detail in the above questions. But if you're just looking for a follow-up to Hello World, I'd use the above approach of revealing more of the reference and asking them to do their own projects based on what they just learned.

Historically, Hello, <name>, but I think I'm going to go with something like hangman, snake, guess the number... I'm leaning more and more to "hacking" existing programs rather than learning bit by bit.