A modern ‘Hello, World’ program needs more than just code
Not too long ago, a client called on me to write a program in RPG on an AS/400. To quote the Great Lobachevsky, “боже мой!”
I don’t want to admit how long it had been since I last wrote RPG other than to note it was probably before most of my readers were born. Building the program required me to remember how to use a KEDIT-like editor, learn how to use the AS/400 Software Development Facility, build a testing library, edit the actual program, then compile it and figure out how to run it.
The client’s program was relatively simple, but I didn’t want to just dive in. So I created a “Hello, World”.
A tradition with a purpose
This notion of a “Hello, World” program goes back to Brian Kernighan and Dennis M. Ritchie’s The C Programming Language (First Edition)— writing a small program in order to confirm that you understand the language and environment enough to try more complicated things. The first program most C programmers write is something like:
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}
Type that text into a file named ‘hello.c’, then (on any UNIX-like system) enter the commands
$ cc hello.c
$ ./a.out
and you should see the cheery result
Hello, world!
which demonstrates that you have indeed written, compiled, and executed a program in the C language.
As Kernighan and Ritchie note, building the program for C means that you’ve mastered the basic steps to start a C project.
This is the big hurdle; to leap over it you have to be able to create the program text somewhere, compile it successfully, load it, run it, and find out where your output went. With these mechanical details mastered, everything else is comparatively easy.
Okay, I’ll admit that the statement “everything else is comparatively easy” is wry humor, but it’s still true that this is a significant step in learning any programming language.
This has become a programming tradition, and like many traditions, it’s often followed without recognizing its purpose or value. So we now have an online Hello World Collection that has nearly 600 examples of “Hello, World” in languages from Ada to ZIM. Many IDEs will write a basic “Hello, World” program for you, and in many interpreted languages like Python, “Hello, World” is simply print("Hello, world!")
typed into the REPL of the interpreter.
Unfortunately, this doesn’t provide much actual insight, and to paraphrase Richard Hamming, the purpose of computing is insight, not literal strings.
What is “Hello, World” really for?
The point of K&R’s original “Hello, World” was not to see “Hello, world” on the terminal. It was instead to make sure that you have all the tools, and the basic understanding of the C language and UNIX programming environment needed in order to write a C program, and having the tools and understanding to build programs is an important first step—maybe the most important first step—in starting every project.
Often, it’s also more complicated than it first seems. A realistic project now requires not just an editor and a compiler, but an understanding of how programs are packaged, how the build environment should be structured, how you plan to maintain version control, how to actually build the program, and what the desired product of the programming project needs to deliver. So while a basic “Hello, World” program might still be only five lines of code, building the initial, ready-to-develop “Hello, World” can be much more complicated.
Starting a new project inevitably means solving a number of development problems before “everything else is comparatively easy.”
“Hello, World” for projects
Building an appropriate “Hello, World” for a project is more complicated, but the payoff is greater as well. Consider a project that is supposed to deliver—for example—a web application. As well as choosing a language, you generally need to choose your frameworks, both for the front and back ends. You need to identify how first application will be hosted and how the code will be managed and delivered.
This appropriate “Hello, World” for a project isn’t just to show you can display some output. You need to show that you’re ready to start adding features—user stories if you’re doing something like SCRUM—and pushing them out to a version of the application that can be demonstrated and tested. An appropriate “Hello, World” for a product is the most minimal version of a minimum viable product, a demonstration that with further development, you expect to be able to deliver a useful product to test and to use.
What makes an appropriate “Hello, World” project
Obviously, this appropriate “Hello, World” project is going to differ depending on the project and the environment. I teach a lot of beginners, and for any class project, I suggest they should always start with:
- A separate project directory—for you young whippersnappers, that may be a “folder”—into which the actual code will go.
- An initialized git repository in that folder. Yes, I do start even beginners using git. The basics are easy to learn, and I’ve seen a prodigious number of students collapse in despair because they made a small change where the results weren’t what was expected, and now they don’t remember what they changed well enough to revert to their old version.
- A choice of the development tools they will be using—editors or IDEs, build tools, and so forth.
- A repeatable build process more robust than typing an invocation of a compiler at a command line.
- And only then the actual first code.
When they have that, and can edit, commit, build, and demonstrate that very minimal program, they’re prepared to build something to be happy with while avoiding a lot of mistakes that can make the actual process much less happy.
Starting a professional project “Hello, World”
It’s easy to imagine that a “Hello, World” program is just for beginners, but most every project starts with that intimidating empty directory. Often a realistic project “Hello, World” requires a suspiciously difficult and complicated process with lots of moving parts. For example, creating the very basic scaffolding for a Java program in Maven constructs ten directories and subdirectories to build a literal “Hello, World” program in Java, while the Maven build and dependency manager program downloads 1350 files into more than 550 directories.
This is hardly just a property of Java or Maven. Building a new React app with create-react-app
requires 4304 directories and 28678 files.
Obviously, doing this by hand leads to madness. This complexity has forced developers to build scripts to create “Hello, World” level apps, but even these won’t be complete—you still must add source code control and possibly configure containers or continuous integration pipelines or deployment scripts.
While this is certainly immensely more complicated than the original five-line “Hello, World”, it’s still serving the same purpose: building a trivial application but ensuring that the requirements to continue development are satisfied.
Getting a good start
Any software project of any size is confronted from the beginning with some variant of the same problem: how can you contrive to master the mechanical details of starting your project, building the code, and even deploying the code so that you can concentrate on actually building code that satisfies the customer’s needs?
No matter how complicated the project will be, you can ensure that you have a good start by building a demonstration program that has the absolute minimum functionality but that exercises the whole process of building, testing, and even deploying. This is what the original “Hello, World!” was meant for, and it’s still the best start today.
Tags: beginner, bulletin, hello world, stackoverflow
68 Comments
I am glad I read this article today. You write a technical article so very well.
— building a trivial application but ensuring that the requirements to continue development are satisfied
You are welcome, hope to write many more.
Oh my God……..Well done
It’s true that in many languages the “hello word” no longer really serves much purpose apart to make the student coder proud of him
So what did the RPG “Hello world” look like? I haven’t used RPG since 1973.
Not sure if I would say yes or no if someone asked me to work in RPG again but I think it’s pretty cool that you were asked and did it. Nice job on the article. Thank you for writing it.
Don’t hijack hello world for your purpose. It already has a defined purpose and people know its range.
You want more? Find a new name and promote that.
I haven’t coded in years, but now I want to teach my children to code.
So this article was both nostalgic and useful.
Thank you.
Check out Beginning Programming with Retro Programming. It’s a book to teach kids BASIC on a Commodore 64 emulator. Picked it up the other day and felt like I was in Junior High again.
I worked in a university data center terminal room back in the mid-70s. Too many students from the Basic language class would come in after the first lesson, sit at a printing terminal and type “Hello World” then wonder why the instructor gave their printout an F.
Never could handle “Hello World”
Damned thing drove me crazy because it should be Hello, World.
😛
That said, interesting article. Thanks.
The original K&R example output “hello, world” (lower case).
I was formerly an AS/400 programming manager, and I had to chuckle at the idea of writing “Hello World” in RPG, a language once designed to be used on punch cards.
Which is, in fact, how I first used it
Using Git right from the start is a very good idea. This is important not just so that beginners can figure out what changes they made the broke things (which may not even work; they’re not always going to be committing at the appropriate points), but even more so to get beginners used to the process of using Git through practice with it. Like learning an editor, learning Git is not something you do once and it’s done but something that takes a lot of use over time to learn, and experience and practice to use well.
I tell my students that got commits should be like voting in Chicago: early and often. To which many of my students say “what?”
> Using Git right from the start is a very good idea.
Too bad git is such a horrible choice for beginners. Not that there are many good choices for beginners. Maybe someone needs to write a set of beginner-aliases for single-developer, local-only usage?
I guess IDEs and TortoiseGit make it a little easier…?
Thats is so true..They can create more problems without it and companies like Microsoft must not know about GIT yet or it seems that way..Just my Opinion
Core specs in RPG I, II, and III: H, F, I, C, and O. SEU is the acronym for “most sucky editor”. Did you write in a 5250 emulator? Did you use the free-form version of RPG? Did you create a command to execute your program? I haven’t seen an AS/400 for about 6 years and very little exposure after 2008. At one time I could make one or several of them dance, sing, speak among themselves, and do real work. I could do “Hello World” in RPG, COBOL, PL/I, C, CL, MI, and probably some other that I have long forgot. Them days ‘r gone.
I was working with someones web app a while back – recording and playing back their requests. An early page contained a 10,000 LOC pretty obscure javascript that enciphered some log-on info before sending it to the server. The developer assured me that it was bullet-proof, I couldn’t figure it out. But the code was downloaded to the browser! One of my team guys made it into a function call, I took some inputs from the user, passed them into the function call and voila! it worked. The person who told me that it couldn’t be cracked was serious and reputed to be smart. Where do these experts get these ideas? I see little actual invention. I see mucho bloat. I suppose that is what old farts see.
Meanwhile, languages like C and C++ *still* only require a compiler toolchain and the basic 5-10 lines of a “hello world” program. A pre-built compiler toolchain from GCC or Clang is a download away, requiring only that it be unzipped before using it.
For a real project, you’ll want to write a Makefile, or maybe even use something more advanced like CMake, but those tools are generally included with your compiler toolchain, and if they’re not, they can be easily downloaded and unzipped as well.
No complex setup procedure is required, and your code runs more efficiently to boot.
Certain corners of the software development profession have a serious bloat problem.
All that bloat is still present in C/C++, just preinstalled as system-level libraries.
Yes. Charley and I worked together so long ago that C was not yet in existence. Figuring out hello, world in almost any modern language and environment is actually pretty good test of whether you have eve a clue of how to do it.
LoL so true!
Build Gradle “Hello World”
Almost I feel nostalgic for Cobol in the high school.
🙂
Getting back into the business after being out for 23 years raising and homeschooling children. I am confident in my coding skills, but it’s all the rest of it that I am finding to be a challenge. Specifically, I get the basic idea of git, but I need a good tutorial to really master it.
Did you use any type of version control like CVS RCS 23 years ago?
Really you only need the basics at the beginning.
Specifically you need to know how to commit, (basically save a snapshot)
How to branch (think create a local fork from a snapshot)
How to merge (apply the changes you made in your fork to a different fork)
How to push (Sending your changes to somewhere else)
How to pull (Recieve changes from somewhere else)
90% or more of your day to day git tasks will be covered by just doing that. The other things you may need to do you will probably just lookup as and when you need them. Eventually some of these will be second nature.
Having an idea whats possible is a good idea too, so that you know what you need to lookup when you do need to look it up.
Once upon a time, I coded RPG on a 360/20 and a S/3
I did BAL on 360/30. Years later in graduate school I studied under Fred Brooks and learned why that was such an amazing computer
Nice one! Got me thinking:
How about a convention where the first commit message of a project is “Greet the world”.
The commit would contain everything that we already put in commits like “Initial commit” (e.g. installing frameworks, running setup commands etc), and print out “Hello, world!” in whatever is the most natural interface for the project in question.
A nice byproduct would be the fact that following git messaging convention where you phrase your messages like sentences becomes actually possible (at least in all my projects it’s always broken by the very first commit message). Compare:
If applied, this commit will “initial commit”
vs
If applied, this commit will “greet the world”
I like it, but the “greet the world” commit should come *after* the “initial commit”.
at least 15 years ago i started writing up my thoughts on how to solve problems using computers. i have this annoying habit of making sure that all of the bases are covered.
what i found was that after writing about 30 pages or so (didn’t really count) i still hadn’t gotten past the basic steps to just write, compile and run the thing.
so … this is not a new problem? situation? state of the art?
ever since IDE’s came into being, (though react doesn’t need an IDE) this has pretty much been the case
Great article. I still remember writing my first “Hello, World” in C (though it wasn’t that long ago). The feeling of seeing your first program run for the first time is amazing.
A technical article well-written in a developer’s point of view!!
You can add an issue management tool / bug tracker.
Personally, I’d love to see projects starting with requirements, even before coding the first line.
How I wish someone can make this part of introduction to coding and/or programming. It will reduce the pitfalls encountered my many students of programming at that stage. Even me at a fairly advanced level of programming I have learnt a lot i.e. git repository to manage versions.
Well, keep your eyes open for my upcoming book on Linux and C system programming from pragmatic bookshelf later in the year.
Next, after learning how to write a Hello, World C program, we must learn how to write a Hello, Wold GUI program, with windows not dialog boxes. That will probably use 200 source lines of code using C++ Qt. I’m trying to imagine how many SLOC a GTK hello world program would take.
Back in the days of X before X11, I wrote an X hello world in only 700 lines of C.
Guessing that you did not use git on your first RPG “Hello, World”
Not even the one in the article — the AS/400 has its own version control scheme. And not in my first RPG program, because version control was keeping the source deck in a locked card file.
You can use git on IBM i (the OS previously known as OS/400) these days, It can even be managed by yum. SEU was stabilized 4 releases ago in favor of Eclipse based RDi.
Personally I don´t like “Hello World”. In a world where we are reaching to other planets and undersea creatures, I prefer other expression:
“Hello Universe”
I don´t know, I just feel like it´s time to use a more open expression to reflect on our progress as a society! 🙂
#include
int main() {
printf(“Hello, Universe!\n”);
return 0;
}
There’s always one.
Thanks for including the code Bruno. I was struggling to modify my version 😉
I must acknowledge that getting the “Hello world” started has frustrated me badly sometimes with modern frameworks/Languages –I recall bitter experiences trying to learn PHP, for example. On the other hand, languages/frameworks which provide a working Hello world out of the box (I’m recalling lately Rust and its cargo build system), have encouraged me to keep learning. Good post.
A proper “Hello, world” program should also include the infrastructure for:
– i18n – internationalization
– l10n – localization
If it does not, then it is not a “Hello, world” program. It is a “Hello, my language only” program.
Okay, so I guess “there’s always one” was an under-estimate.
非常好!
I think that should be in Hello World 2.0, not in 1.0
How timely for me! Thank you! Just today I found this post as I arrived back on SO in a mystifyingly overly difficult task. After a little playing around with a tutorial, I’m trying to solve what I’m certain is a monumentally simply answered question that ultimately will take more time than the tutorial and experiments to date. I can’t estimate how many tutorials over the years seem to have left out some phrase like “as long as your environment has the 14 other perquisite components” that should have followed, “And that’s all there is to it!”
It makes getting a toehold in a new language one of the most dreaded aspects of a new language for me.
I really the idea of modern hello world. Even with the famous and simplest example you provide we can still elaborate a lot from it (not limit to just one language).
#include
int main() {
printf(“Hello, world!\n”);
return 0;
}
why user `int main()` instead of `void main()`, what’s the purpose of “return 0”. why “use include”. Indeed newbie can search this by themselves. And there is no obligation for educators to explicitly taught them or overwhelm them. A good side note is still helpful (though it could be boring) for them and possibly raise them interests about the design of language besides something like “hey, it prints out something, amazing?” then keep using the same pattern everywhere at the really beginning.
This can be beneficial in the future when it extends to a “simple” hello world from a framework like you say “create-react-app” and accelerate your learning speed because you also want to know why and how it works instead of “hey it works”.
I always wish someone could at taught me that when I was a newbie in college. Because at the moment, I don’t even realize and how to search those ideas on the website.
it has to be ‘int main()’ because the environment expects an integer return code — 0 for success or ≠ for a failure. It uses ‘#include” because that’s the way the language works. Use a different language, you get a different convention — ‘import foo.bar.bltech;’ in Java, ‘import goo” in Pyth9on.
Stackoverflow, is it possible that you publish your podcasts on Spotify? Thanks!
Oops, you have it, sorry, false alarm 😀
Hello World was the first program I wrote back in the early 80’s. I have a feeling I’ll be writing Goodbye World soon.
Hey, I’m older than you — probably way older — and I’m still writing “Hello, world”
I miss the concept of declarative language? In all comments too? seriously?
The value of “hello world” lies in the fact that everything you will ever do with C is encapsulated in that code (with the exception of abusing the C preprocessor.) Git will go the way of all source code control systems. The mess that’s internationalization or localization won’t always be there. C will be there because it’s a “higher-level” language that still gives hardware-level access. The first program that you’ll probably try as a compiler writer for a new machine will be “hello world” — if it works, you know that you can bootstrap your compiler (because you have the basics) and you or your employer will have a path to commercial success even if you abandon C in favor of whatever you think is the right way to abstract your and your users’ view of the world.
Hello.c also has another purpose beyond demonstrating that you are ready to start with the language, it is a good verification that the operating system is ready to roll. For a.out to run in a Unix world, you need to have a kernel that can do fork() and exec(). You need to have a file system that you can load a process image from. You need to have a shell of some sort with output capabilities. Hello World is the program that demonstrates that an OS is ready for users.
>Building a new React app with create-react-app requires 4304 directories and 28678 files.
This demonstrates why modern code is so fragile. In order that my trivial little app works, I have to trust that tweny-eight thousand code modules have no problems. The chances of that are zero.
“Building a new React app with create-react-app requires 4304 directories and 28678 files.”
Just so sad, on so many levels.
– You have a copy of all that baggage for every project.
– Every update to every included module means you get another copy for every project.
Every thing I read about javascript makes me want to avoid it like the plague it is.
Javascript is actually a lovely language that honestly shares only the first four letters with Java.
The libraries are a bit of a mess though.
There is tooling that reduces that mess.
Javascript is an incredibly ugly language that has only gotten uglier since it was invented back in 1995. It took all the ugliness of C style languages, and copied every mistake made in PHP, then added its own idiocies on top of all of that.
Java is long winded, but not especially ugly or nasty. Javascript is ugly, and nasty.
Unfortunately this happens with too many languages. I think that perhaps this is why python seems to be winning out in colleges and industry. This language allows one to get to solving a problem with a minimal of plumbing code.
…and thus we prove that beauty is in the eye of the beholder 😉
As a matter of fact, it’s been quite a while that I’ve created my own template repos on github. Along side build tools and test tools I write two files:
helloWorld.(whatever ext)
helloWorld.test.(whatever ext)
My build tools build the first and my test environment checks that I am greeting the world with the second.
New projects are seeded from those templates and everything I need to start is there and working.
I got sick of “Hello World!”… so I started using “Hail Cthulhu!” instead. It somehow feels much more appropriate.
First off, I did not steal the code, I downloaded the app and with out logging into GIthub I simply updated the app for an easy integration for the cell phones new langue. A child could have done it.
Thank you so much for sharing this wonderful post with us.