[go: up one dir, main page]

DEV Community

Cover image for Hello World!
Andrew (he/him)
Andrew (he/him)

Posted on

Hello World!

Hello world! program is a bit of code that prints the string "Hello world!" to the terminal / output / etc. In most languages, this is a straightforward and boring task:

C

#include <stdio.h>
int main() {
  printf("Hello world!\n");
  return EXIT_SUCCESS;
}
Enter fullscreen mode Exit fullscreen mode

C++

#include <iostream>
int main() {
  std::cout << "Hello world!\n";
}
Enter fullscreen mode Exit fullscreen mode

Java

class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello world!");
  }
}
Enter fullscreen mode Exit fullscreen mode

Scala

object HelloWorld {
  def main(args: Array[String]): Unit = {
    println("Hello world!")
  }
}
Enter fullscreen mode Exit fullscreen mode

There are hundreds more examples at rosettacode.org. Some of my favourites (and I think the most interesting ones) include:

Beeswax

Beeswax is a 2-dimensional programming language in which "bees" (instruction pointers) move around a hexagonal grid of characters, picking up values from the global stack and manipulating them on their own "personal" (local) fixed-size (3 * UInt64) stack. Bees can pick up values from anywhere, modify them, and drop them anywhere in the source code, allowing for self-modifying code. A Hello world! program in Beeswax might look like:

 W o    l   `
  ``     e  H
  `*`r`#`l`_`ld!
   ``      \/
   , o
Enter fullscreen mode Exit fullscreen mode

This could much more easily be written as

 _`Hello, World!
Enter fullscreen mode Exit fullscreen mode

But what's the fun in that?

Chef

Chef is a programming language designed to look like a recipe. Programs consist of "wet" and "dry" "ingredients" that can be mixed, stirred, liquefied, and combined together. Mike Worth has developed a recipe for a Hello world! chocolate cake, written in Chef, which also is a decent recipe for IRL chocolate cake:

Hello World Cake with Chocolate sauce.

This prints hello world, while being tastier than Hello World Souffle. The main
chef makes a " world!" cake, which he puts in the baking dish. When he gets the
sous chef to make the "Hello" chocolate sauce, it gets put into the baking dish
and then the whole thing is printed when he refrigerates the sauce. When
actually cooking, I'm interpreting the chocolate sauce baking dish to be
separate from the cake one and Liquify to mean either melt or blend depending on context.

Ingredients.
33 g chocolate chips
100 g butter
54 ml double cream
2 pinches baking powder
114 g sugar
111 ml beaten eggs
119 g flour
32 g cocoa powder
0 g cake mixture

Cooking time: 25 minutes.

Pre-heat oven to 180 degrees Celsius.

Method.
Put chocolate chips into the mixing bowl.
Put butter into the mixing bowl.
Put sugar into the mixing bowl.
Put beaten eggs into the mixing bowl.
Put flour into the mixing bowl.
Put baking powder into the mixing bowl.
Put cocoa  powder into the mixing bowl.
Stir the mixing bowl for 1 minute.
Combine double cream into the mixing bowl.
Stir the mixing bowl for 4 minutes.
Liquify the contents of the mixing bowl.
Pour contents of the mixing bowl into the baking dish.
bake the cake mixture.
Wait until baked.
Serve with chocolate sauce.

chocolate sauce.

Ingredients.
111 g sugar
108 ml hot water
108 ml heated double cream
101 g dark chocolate
72 g milk chocolate

Method.
Clean the mixing bowl.
Put sugar into the mixing bowl.
Put hot water into the mixing bowl.
Put heated double cream into the mixing bowl.
dissolve the sugar.
agitate the sugar until dissolved.
Liquify the dark chocolate.
Put dark chocolate into the mixing bowl.
Liquify the milk chocolate.
Put milk chocolate into the mixing bowl.
Liquify contents of the mixing bowl.
Pour contents of the mixing bowl into the baking dish.
Refrigerate for 1 hour.
Enter fullscreen mode Exit fullscreen mode

HQ9+

HQ9+ (as mentioned in this previous post) is an esoteric programming language with only four commands:

  • H: prints "Hello, world!"
  • Q: prints the source code of the program (a quine)
  • 9: prints the lyrics of the song "99 bottles of beer"
  • +: increments an inaccessible accumulator (essentially does nothing)

The language is not Turing complete, and an interpreter for it can be written in less than 300 bytes of Haskell code.

Jacquard Loom

Charles Babbage's Analytical Engine, proposed (though never built, unfortunately) in 1837 would have been the first general-purpose, Turing-complete computer. It was designed to work with base-10 (decimal) numbers, unlike modern binary computers, and it would have been entirely mechanical -- the "memory" of the computer is encoded in the physical state of wheels in their axes. The Analytical Engine was designed to be programmed with punch cards, inspired by Joseph Marie Jacquard's machine for automating weaving patterns in looms. In an entirely mechanical process, these punch cards can be used to "program" the weave pattern on a loom. The following sequence of cards weaves the string "Hello world!" on a Jacquard-style loom:

+---------------+
|               |
|    *    *     |
|*   *    *  *  |
|*           * *|
|*           * *|
|*  *         * |
|   *     *   * |
|         *     |
+---------------+

+---------------+
|               |
|*   *    *     |
|*   *    *     |
|            * *|
|            * *|
|*  *         * |
|*  *     *   * |
|         *     |
+---------------+

+---------------+
|               |
|*   **   * *   |
|*******  *** * |
| **** *   * ***|
| **** *  ******|
| ******   ** * |
|   * *   *   * |
|         *     |
+---------------+

+---------------+
|               |
|*******  *** * |
|*******  *** * |
|           ** *|
|*        *  * *|
|*******   ** * |
|*******  *** * |
|         *     |
+---------------+

+---------------+
|               |
|*******  *** * |
|*******  *** * |
|      *  *  * *|
|      *  *  * *|
|*******  **  * |
|*******  **  * |
|         *     |
+---------------+

+---------------+
|               |
|***** *  *** * |
|*******  *** * |
|     * * *  *  |
|     * *    *  |
|******   **  * |
|******   **  * |
|         *     |
+---------------+

+---------------+
|               |
|    *    * *   |
|***** *  ***** |
|***** **  * ***|
|***** **  * ***|
|*******   * ** |
|   * *   *   * |
|         *     |
+---------------+

+---------------+
|               |
|               |
|     * *       |
|     * *       |
|     *         |
|     *         |
|               |
|               |
+---------------+
Enter fullscreen mode Exit fullscreen mode

LOLCODE

Inspired by the LOLcats memes of the mid-00s, LOLCODE is a programming language with keywords like KTHX and BTW. A Hello world! LOLCODE program could be written as:

HAI 1.2
CAN HAS STDIO?
VISIBLE "HAI WORLD!"
KTHXBYE
Enter fullscreen mode Exit fullscreen mode

Despite the fact that LOLCODE interpreters and compilers have been written in languages like .NET, JavaScript, and Python, and that a version of the language has been written for distributed / parallelised computing, it is still a joke language, and bugs and redundancies exist. For example, in the code above, the version (1.2) is unnecessary and mostly ignored, as is the second line, which is meant to import an IO library. A LOLCODE interpreter is available at https://repl.it/repls/ExtrasmallWastefulFolders.

உயிர் / Uyir

உயிர் (Uyir) is the Tamil word for "life force", "soul", or "vitality" (according to Google translate), and is currently under development. Its goal is to be the first omniglot programming language, where keywords, commands, etc. can be written and understood by the interpreter / compiler in any human language. At the moment, it seems to work only in Tamil, though. Note that there are many programming languages with keywords based on languages other than English, some with non-ASCII character sets (丙正正, ΓΛΩΣΣΑ, قلب ), and several that have no language-specific keywords at all (APL, Brainfuck, Piet, Whitespace, etc.).

This post originally appeared in a slightly different form on my (now defunct) Wordpress blog.

Top comments (1)