beanz Magazine

Hello World! in 100 Programming Languages

Hello World Toast by oskay on Flickr

When you learn a new programming language, one of the first programs you learn is how to code, "Hello World!" Here's the phrase in four programming languages, as well as links to 100 plus examples.

For the first issue of this magazine, and to introduce a regular feature called Snippets, here is a single task written in different programming languages. But this task is special and ideally suited for the launch issue of this magazine. The program outputs the phrase Hello World! in multiple languages.

Before we begin, the Snippets feature demonstrates how a single task is handled in different programming languages. The goal is to help you feel more comfortable reading unfamiliar code, as well as explore differences between languages. The word red in English sounds and looks similar to rouge in French and rojo in Spanish. Programming languages often have similarities that provide insights into the languages and computing history.

Let’s dive in.

When most people learn a software language, one of their first tasks is to learn how to output the phrase, “Hello World!” It might seem silly and pointless. But it teaches you how to output data in the simplest way possible. The first example of a Hello World! program dates back to 1978 and a book, The C Programming Language, by Kernighan and Ritchie.

Action!

For the first example, we’ll start with the letter A and the Action! language used for Atari programs around 1983:

Note some things in this code, common to many programming languages:

  • The semi-colon in the first line tells the programming language the text that follows is a comment and is not to be processed.
  • The PROC bit stands for “process” and in this case the process is called Main(). Presumably, as in many coding languages, Main() is a process called by default when a program runs. Any actions that must run when the program is started are placed in this initial type of process or function.
  • PrintE(“Hello World!”) tells the programming language to print the phrase Hello World!
  • RETURN tells the language to return the value of PrintE, specifically, the phrase Hello World! The word return in computing used to mean literally return to the start of the next line of text on a computer screen. Today, return in a programming language means return the results of any commands.

ColdFusion

This code in the ColdFusion language generates the same result as the Action! code above:

Here is a brief explanation of the ColdFusion code which is similar to the Action! code:

  • The first line, the <— and —> characters tell ColdFusion not to process this line. It’s a comment to describe the purpose of the code that follows. Often code includes comments to explain code that follows which, in turn, makes it easier to maintain code in the future when people might have forgotten the purpose or unique features of a chunk of code.
  • The <cfset > line sets (defines) a variable called message to hold the value “Hello World!”
  • The <cfoutput> open tag and </cfoutput> close tag tell the ColdFusion language to output the variable message. If you recall, this variable stores the text value, “Hello World” The # sign before and after the message variable on this line simply tell ColdFusion the location for the start and end of the variable name.

Scala

The next example highlights features common in several modern languages. Here’s the program “Hello World! in the Scala language, an excellent first language for beginner coders:

This code has a taste of both old time coding and modern coding. Here’s a quick explanation of the code:

  • As with the other examples, the first line is a comment to tell the Scala language interpreter to not process this line of code. In Scala, comments are preceded by a double forward-slash. This also applies to other languages, for example, PHP.
  • Remember how Action! above defines a process with PROC? With Scala, the language creates an object called HelloWorld and the with Application direction tells the language to call this object and run it when the application starts.
  • See the { and } on the object HelloWorld line and the last line? These are called curly quotes. If you look closely, you’ll notice the first curly quote is a left bracket which opens (starts) the definition of the object. And the last curly quote is a right bracket to close (end) the definition.
  • Perhaps the most interesting part of this code is the line, Console.println(“Hello world!”); Console and println are ancient terms in computer languages. Years ago, software programs wrote to computer screens, called consoles, that acted as front end terminals to control a computer. Output was generated line by line. So this line, Console.println, tells the Scala interpreter to print out the specified text in the brackets and double quotes, using older terms like console and print line.
  • Finally, on the Console.println line, notice the line ends with a semi-colon. This conveys to Scala the end of the specific line and any command on the given line. Many languages use both curly quotes to mark the start and end of a process or object and semi-colons to mark the end of lines of code within these process or object containers.

ZIM

The last example will be in the ZIM language:

In ZIM, comments are preceded by a percent (%) symbol and the command to output text is as simple as out followed by the text to output in double quotes.

 

These examples are from an exhaustive list of example programs to output “Hello World!” in over 400 languages. The list is maintained by Wolfram Roesler in Germany but much of it was crowd-sourced by programmers intrigued by the project. Wikipedia also has a page with examples, if you want to learn more about these examples.

The most beautiful code I’ve ever read was in a content management system, an early version of Expression Engine, written by Rick Ellis around 2005 or 2006. Reading his code was like standing in a vast Gothic cathedral, the code was so clean, simple, and tightly integrated with the other code and files. Even his file names and folder structure was clean.

While code can look frightening to read, you quickly become used to it. Look for common patterns, comments, and descriptive names of functions and objects as you read. Reading code can be educational and enjoyable, especially when you come across beautiful well-written code.

Learn More

Wolfram Roesler’s Hello World Examples

http://www.roesler-ac.de/wolfram/hello.htm

List of Hello Word Program Examples (Wikipedia)

http://en.wikipedia.org/wiki/List_of_Hello_world_program_examples

Action!

http://en.wikipedia.org/wiki/Action!_%28programming_language%29
http://joyfulcoder.net/atari/action/language/
http://retrobits.net/atari/action.shtml

ColdFusion

http://en.wikipedia.org/wiki/Adobe_ColdFusion
http://www.adobe.com/products/coldfusion-family.html

Scala

http://en.wikipedia.org/wiki/Scala_%28programming_language%29
http://www.scala-lang.org/

ZIM

http://www.zim.biz/zim-821-ide

Text File with Code Samples

Hello World! code samples in a text file

Also In The August 2013 Issue

Hello World! in 100 Programming Languages

When you learn a new programming language, one of the first programs you learn is how to code, "Hello World!" Here's the phrase in four programming languages, as well as links to 100 plus examples.

Online Guidelines for Student Blogging, Commenting, and Personal Safety

These guidelines are collected from the internet, with links for more ideas to help teachers and students.

An Interview with Patrice Gans

A university trained programmer, with a masters in computer science and a full professional career, Patrice teaches technology and computer science to kids in kindergarten through eighth grade.

Codea, Hopscotch, Tynker

These three applications make it fairly easy to learn basic software programming concepts, from block building (Hopscotch and Tynker) to the more sophisticated (but easy to understand) approach for the Codea iPad application.

How to Choose Your First Programming Language

There are so many programming languages, how do you choose one? Here are 18 options for all ages.

Owls and Super Bugs

Here are two programmers who use their coding skills to solve complex problems, from tracking endangered owls in Yosemite to tracking and isolating a deadly virus in a hospital isolation ward.

Computer programming is an art, because it applies accumulated knowledge to the world, because it requires skill and ingenuity, and especially because it produces objects of beauty.

Learn More Links for August 2013

Links from the bottom of all the August 2013 articles, collected in one place for you to print, share, or bookmark.

Website Design Patterns

In the software world, patterns provide a useful way to critique, discuss, and build screens to help people do things online.

News Wire Stories for August 2013

3D game design tech, a guitar that does email, what wi-fi would look like if we could see it, golf ball technology, women in tech, and other stories from the past month or so from around the internet.

HTML Coding for Beginners

Creating content in an online publishing tool often requires zero knowledge of HTML. When hand coded HTML is required, however, you only need to know five tags. Seriously.

How to Teach WordPress Basics to Students

It's easy to teach students how to create and publish content with WordPress because the software rewards clicking links to find what you need to do.

Tools to Create and Develop Software

These tools make it easy to create and develop software with the ability to validate code, connect to web servers, store code snippets, and other useful features.

PHP

From a simple website activity application written in the C language in 1994, the PHP programming language has evolved into a robust language optimized for web servers and web applications.