Existing answers have great suggestions...
There are many wonderful answers here, and I agree that, in general, "hello ${name}"
to introduce dynamic input/output and string concatenation (a natural lead-in to if
/else
and something like a small quiz app), currency/temperature convertors to introduce mathematical operations and types are great second tasks. A temperature converter with hardcoded values is a refactor away from collecting input, introducing functions, conditions (prompt for Fahrenheit to Celsius or vice-versa) and loops (prompt for multiple temperature conversions).
I also like the idea of prematurely showing students code from a larger project they aren't expected to understand, with the idea of making a few small modifications and exposing them to the look and feel of the sort of applications they'll soon be creating. There's a risk of intimidation, so care would need to be taken, and eventually you'll have to pull back to a "next hello world"-sized step anyway.
... but what about audience, context and goals?
However, these answers seem to assume an audience of entry-level programming students. As pointed out in the comments, plenty of advanced tutorials and courses might begin with a "hello world"-style task.
For example, in back end web development, any first-time Ruby on Rails tutorial will begin with getting the "Congratulations! You're on Rails!" screen up on localhost. For machine learning libraries, a classifier using the iris dataset is a canonical first order of business.
The point here is that audience, language, framework and context matters in choosing a second task, and "hello world" isn't exclusive to beginning programmers or console-based contexts.
With that in mind, a few answers recommend FizzBuzz after "hello world". Initially, this struck me as rushing in too many fresh concepts that can take time for beginners to grasp: loops, booleans, branching and string manipulation. But if the audience has prior programming experience, FizzBuzz might be a reasonable difficulty for them. And if not, you can always build up, adding the conditions slowly, then the loop.
I recently began learning Haskell from "hello world", and found that I wrote a dozen or so smaller programs before I was able to write a FizzBuzz that accepted input, to cite an example of the language factor.
Working backward from the goals of the course, the next step.
I'll continue onward assuming beginners, though, since follow-ups to "hello world"s for experienced developers looking to learn the latest framework would be a case-by-case basis.
In any situation, working backward from the goals of the course, the next step after "hello world" might become obvious.
A "10 PRINT" approach
Answers so far mostly offer a command-line style, general-purpose task that would work in basically any language. But many languages (particularly educational ones like Racket, Scratch and BASIC) offer interesting features that make it easy to do relatively engaging and powerful things without much effort. One suggestion is to try to find and exploit these in whatever environment you're working in. In particular, I find that graphical programs, and particularly animations, are a great way to engage students, even if only ASCII.
A classic example is 10 PRINT, a simple BASIC program that produces a cool animation
10 PRINT CHR$(205.5+RND(1)); : GOTO 10
10 PRINT is not always as easy to achieve in other languages and environments (it exploits aesthetics of the environment's screen, native text wrapping, an easy-to-write infinite loop, and an easy-to-call random number generator), but there's often some other "hack" that happens to create a disproportionately cool effect of some sort in your language.
For most scripting languages, it's pretty easy to provide boilerplate to do animations. In Python:
from time import sleep
while True:
print("hello world!")
sleep(1)
Working with this basic framework, you can introduce numbers, math operations and string manipulation to add dynamism to the animation (and later on, explain the loop and import in more detail; it's good early exposure):
from time import sleep
i = 0
while True:
print(i % 10 * "@")
i += 1
sleep(0.1)
The *
operator in Ruby and Python and x
in Perl shows another easy trick for one-upping "hello world". String repeat functions, when available, are fantastic: "Na" * 10 + " Batman!"
. This works great with the print your name suggestion elsewhere in the thread.
We can try 10 PRINT in Python (although the results won't be too impressive without the C64 monitor; consider adjusting terminal color and typeface prior to the session):
from time import sleep
from random import choice
while True:
print(choice(r"\/"), flush=True, end="")
sleep(0.01)
or print the "\b"
character to make a little animation in-place:
from itertools import cycle
from time import sleep
for c in cycle("what's up?"):
print(c, flush=True, end="")
sleep(0.5)
print("\b", end="")
or:
for s in cycle(("hello", "world")):
print(s, flush=True, end="")
sleep(1)
print("\b" * len(s), end="")
Even if students won't understand the code out of the box, they can play around with the string contents and speed, building intuition for what the shape of the code looks like and how it can create something dynamic and interesting with just a few lines.
Al Sweigart has a repository of scroll art scripts for further inspiration, although most are more than a step after "hello world".
Other ideas
Many languages have turtle or another minimal graphics library that lets you draw a circle with 2-3 lines of code and might be a great next step after "hello world". This is a great choice for students coming from a Scratch background who may be prone to frustration at the relative difficulty of doing anything "fun" with text-based languages.
In HTML, I find that a <pre>
tag can open a world of creative options for ASCII art without having to learn coding concepts immediately, similar to stacking a bunch of print
statements or a multiline string to create an ASCII banner.
The nonstandard <marquee>
tags, although technically horrible, helped turn my generation on to web development, and are a great way to jazz up "hello world" (when supported). Sure, HTML is probably not relevant for most curricula here, but concepts like this can often inspire ideas for other languages.
CSS offers powerful animation and transition techniques with just a line or two of code. For example, providing something like
<style>
body {
transition: all 2s;
}
body:hover {
background: black;
}
</style>
can get students interacting with their app and provides a foundation for adding CSS properties, creating new elements and designs.
For front-end JS, students can easily use the browser's development tools to manipulate content on Wikipedia or another popular website. For example, without writing code, they can change text to humorous effect while being exposed to the syntax and structure of HTML.
If you don't mind sharing code students might not understand at first but will surely get a kick out of, you can try something like:
document.querySelectorAll("*").forEach(e => {
e.style.background = "#" + Math.random().toString(16).slice(-6);
});
which sets all element backgrounds to random colors on a page, creating a glitchy art effect and hopefully giving students an idea of what's possible in the spirit of 10 PRINT. Snippets like these can open up conversations about creative coding, computer art and history (even if those aren't the focus of the course).
It's OK to make a mess
Following the <marquee>
principle, in most cases, it should be fine at this stage to let students make a mess and have fun, duplicate code everywhere, then enforce better software engineering principles later. Ugly and outside-the-box is encouraged. For web programming, grabbing snippets from w3schools is OK.
For example, I've seen students push a few of their laptops together in a row and sync up the timing of their animations to make it look like text is scrolling between monitors! Encouraging creative, emergent collaboration among students and the tools in the environment enables students to create interesting experiences even with small amounts of code, as 10 PRINT does by exploiting aesthetic qualities of typeface and monitor.