2.1. The Most Basic Program: “Hello World”

A common practice when learning programming is to always start with a simple application called a “hello world” application. The purpose of this application is simple: print “Hello, World!” to the console. In Dao, the hello world application is about as simple as it can get:

io.writeln("Hello, world!");

To execute this, put this in a file called helloworld.dao, then execute it by typing:

dao helloworld.dao
note:To execute dao in this way, the dao executable must exist somewhere in your PATH environment variable. If this example doesn’t run as specified, try replacing the first “dao” with the full path to your dao executable.
Breaking this apart, we have a few basic components here:

io in this example is what we call a namespace. Namespaces keep objects with the same name from interfering with each other when defined in separate modules. Every module you create has its own namespace, and they can further specify nested namespaces within themselves. As you can see in this example, accessing an object in a namespace is performed by suffixing the namespace with a period (”.”) and then the name of the object. In Dao, however, there is actually a second way to work with namespaces - instead of a period, you can use two colons between the namespace and the object, such as:

io::writeln("Hello, world!");

These two blocks of code are, for all intents and purposes, entirely identical. There’s no difference between the two methods of interacting with namespaces, aside from personal preference.

The second component in our example is writeln(). This, in Dao, is referred to as a routine. In other languages, this is sometimes referred to as a function, but Dao uses the language “routine” to refer to these sorts of objects; as such, the documentation will refer to these objects as routines.

A routine is a saved block of code that can be called multiple times, with slight variants that are dictated by the objects that get passed into them. The use of routines enables programmers to avoid having to rewrite (and, later, re-modify) the same code over and over again.

The third basic element here is our “Hello, world!”. This is what’s called a string literal, and in Dao, represents an object of type string. By placing it within paired parentheses and attaching it to writeln, we are passing the value “Hello, world!” into the routine “writeln”. writeln then does the rest of what we want for us, and writes “Hello, World!” to the console. We’re done!