Most programmers these days use an Integrated Development Environment or IDE for short. This is a program that combines a program editor, compiler, language reference, and debugging tools all in one package. They take a bit of time to set up and get used to, but over the long term that investment pays off in increased productivity. In this course we won't be spending too long with any one language, so it doesn't really make sense to learn how to use and IDE we'll only be sticking with for a week or two. Instead we will adopt a more lightweight (and old-school) method: we will write our programs in a general-purpose editor, and compile them by typing commands using an interactive utility variously known as a shell (Linux), the terminal (Mac), or the command line (Windows). This page will go through the information you need to successfully navigate this process.
Finding the Command Line
To get a command line interface, you will either run an appropriate program, or open a remote connection to the computer science Linux teaching server, called aurora.
On Mac, the program is called Terminal. It comes installed by default, and you should be able to find it by searching the apps.
On Windows, we won't be using Microsoft's command prompt program. Instead we will rely on a package called Cygwin, which provides a unix-like interface more similar to the other two platforms. Instructions on installing Cygwin are on another page. During the OCaml portion of the course, we will be using a special-purpose installation of Cygwin that is created by the OCaml graphical installer for Windows. It will appear on the desktop after installation with the name OCaml64.
To connect to aurora you can either use the ssh program from your local command line, or follow the instructions to connect remotely using a graphical interface.
Navigating the File System
Files in most modern operating systems are organized hierarchically, with individual files organized into folders (or directories), those in turn grouped into higher-level directories, and so on. At the top level, everything resides within a folder called the root directory. On Unix and Mac this is denoted simply by a / (forward slash). On Windows it is usually called C: but in Cygwin it is also denoted as /cygdrive/c/. Subfolders and files within the file system are denoted by specifying a path from the root directory to the file or folder in question. For example, on aurora my home directory is designated by /Users/nhowe/ which means it is a folder canned nhowe within a folder called Users that is within the root directory. (Note that I am using "folder" and "directory" interchangeably.)
Since file paths can get quite long and therefore tedious to type, most command shells employ the concept of a working directory, similar to an open folder. Items within the present working directory (command: pwd) may be referred to by name, without giving their entire path. Think of the working directory as your current location in the file structure, and changing it (command: cd) as moving around within that structure. You can always list (command: ls) the files to see what's there.
When you are first getting started you should first try to locate and move to your home directory. (On Mac, it may be the place you start by default. On Windows, you may have to actively move to it -- try cd /cygdrive/c/Users/your_account_name.) From there you can browse the available folders and move into and out of them. For example:
$ cd /cygdrive/c/Users/nhowe $ pwd /cygdrive/c/Users/nhowe $ cd Documents $ pwd /cygdrive/c/Users/nhowe/Documents $ cd ../ $
Here we began by moving to the home directory (this step Windows only). We then moved to a subdirectory (cd Documents), confirmed where we were, then moved back up a level to the original directory (cd ..), and confirmed our location once again. The pwd command shows us where we are at any given time by printing the path.
From the command line, we can also create new directories (mkdir MyDir), rename files (mv OldName NewName), delete files (rm FileToRemove), and delete directories once they are empty (rmdir DirectoryToRemove). It is strongly recommended that you use a separate folder for each project, homework, lab, etc. A table of useful commands is here.
Compiling From the Command Line
Let's assume that you have written a program, and it is sitting in the directory that your command shell is currently working with. How do you run it? The answer depends on the language. If it is a compiled language, like C or OCaml, you will need to compile it first. This creates a brand-new file called an executable that can be run directly. (Technically for projects involving multiple files there are two steps, compiling and linking, but they can be done with a single command in most cases so we won't worry much about the distinction.)
Let's use the program caesar.c as an example. If you want to follow along, download the program and put it in your working directory. You can use gcc to compile it:
arbok:~> ls caesar.c arbok:~> gcc caesar.c arbok:~> ls a.out* caesar.c arbok:~>
Notice that a new file has been created called a.out. (On Windows it will be called a.exe instead.) We can run this program by typing ./a.out at the command line.
Of course, this example shows an ideal situation where our program has no bugs. Often the first attempt at compiling will produce a lot of error messages which must be fixed before the executable file can be produced.
The situation is much the same in other languages. In OCaml, for example, we will use the compiler ocamlopt. We can also specify a more desciptive name than a.out using a -o flag. Finally, for projects split into several modules we list all the files that need compilation, in the order they should be processed.
arbok:~> ls assert.ml tickets.ml arbok:~> ocamlopt -o tickets assert.ml tickets.ml arbok:~> ls assert.ml tickets tickets.ml arbok:~>