Programming

What exactly is programming? What can be programmed? What are programming languages? What does one need to know to get started programming?

Definitions

Programming, or scripting, is the act of creating instructions that an agent (someone or something) will carry out. You can program robots, computers, media players, consumer devices, factory machinery, etc.

A programming language is a formal medium for expressing ideas about methodology, as well as a formal specification for representing programs. An interpreter for a programming language runs programs written in that language. If a language lacks an interpreter, you may use a compiler to translate programs written in that language into another language that does have an interpreter.

An algorithm is the (abstract) set of instructions for solving a problem. Technically each instruction has to take (in principle) a finite time to carry out and the entire instruction set must always terminate. An algorithm doesn’t get carried out on a machine, but a program does.

The “Hello, World” Tradition

There’s a tradition that the first program you write when you are learning a new language is one that displays the message

hello, world

on some output device. You can’t always display messages in languages for programming robot arms or the brakes or suspension in your car, but you can do this for languages that let you write programs on a desktop or laptop computer. For example, here it is in Python:

print("hello, world")
and Ruby:
puts "hello, world"
Perl:
print "hello, world\n"
Lua:
print("hello, world")
JavaScript:
console.log("hello, world");
Scala:
println("hello, world")
Standard ML:
print("hello, world\n");
C:
#include <stdio.h>
int main() {
    printf("hello, world");
    return 0;
}
Objective C:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    printf("hello, world\n");
    [pool drain];
    return 0;
}
Swift:
print("hello, world")
C++:
#include <iostream>
int main() {
    std::cout << "hello, world";
    return 0;
}
C#:
using System;
class Greeter
{
   public static void Main()
   {
      Console.WriteLine("hello, world");
   }
}
Java:
class Greeter {
    public static void main(String[] args) {
        System.out.println("hello, world");
    }
}
ActionScript:
class Test {
    static function main(mc) {
        mc.createTextField("message", 1, 0, 0, 100, 100);
        mc.message.text = "hello, World";
    }
}
HTML:
hello, world
XHTML:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>A Greeting</title>
  </head>
  <body>
    <p>hello, world</p>
  </body>
</html>
Go:
package main
import "fmt"
func main() {
  fmt.Println("hello, world")
}
Rust:
fn main() {
    println!("hello, world");
}
D:
import std.stdio;
void main(string[] args) {
    writefln("hello, world");
}
Ada:
with Ada.Text_IO;
use Ada.Text_IO;

procedure Hello is
begin
  Put_Line ("hello, world");
end Hello;
Lisp:
(print "hello, world")
Racket:
(display "hello, world")
Clojure:
(println "hello, world")
Haskell:
main = putStrLn "hello, world"
Smalltalk:
Transcript show: 'hello, world'.
PHP:
echo("hello, world\n")
and in HQ9+:
H

You might also be interested in Wikipedia’s Hello World Program article as well as some on-line collections of Hello World programs, including:

It’s fun to study existing programming languages, but there is another part to what we call programming. Coming up with the insights needed to make a program do something you want is known as problem solving. It’s definitely an art, and takes time and practice.

Kinds of Programs

So how do you write, and run, programs? That depends on a lot of things.

Here are four kinds of programs (there are others—it all depends on what you mean by a “kind” of program):

TypeDescriptionExamples
Native Application A standalone program designed for user interaction. Runs directly on the user’s computer, tablet, or phone. iTunes, Firefox, Atom, Notepad, Chrome, Terminal, Cmd, Messages, OpenOffice, Word, Excel, Keynote, Node, javac, java, Photoshop, etc.
Daemon A program that is always running in the background. Device drivers, web servers, database servers, printer spoolers, that system updater thing, etc.
Web Application
(Webapp)
A full-fledged program designed that interacts with a user through a variety of web pages, within a browser. GMail, Google Sheets, Your bank’s web site, Slack, PROWL. (Note that it is common for many programs to have both a web and native version.)
Applet A small program running inside of another (usually a web browser). Java applets and Flash movies used to be pretty common, but JavaScript seems to rule this world today. A great source for JavaScript applets is Chrome Experiments and the WebGL Experiments.

The Programming Environment

Programmers need to be familiar with not only the programming language(s) they are working in, but also with the machines they are programming on and deploying onto, and with available tools.

Devices

Generally programs are written on desktop or laptop computers but can be deployed to run on all kinds of devices, such as:

The File System

On virtually every computer system in the planet, both data and programs are stored in files. A computer’s file system is its mechanism for storing and accessing these files. Ultimately more programmers learn the following:

Tools for Programmers

These include:

Web services for running (and sharing) programs

These services are enormously useful when you are trying things out:

Live Programming

Live Programming is a loosely defined term roughly meaning that the code is continuously executed while you write it (where writing usually means typing). We’ve seen this already with Khan Academy Computer Programming. JSFiddle (at least as of June 2017) isn’t live. CodePen.io has an “Auto-Updating Preview” mode that can be considered live.

A good deal of Bret Victor’s work is live. And here’s a great paper on the topic.

If you have to press a Run button, it’s not live.

Live Coding

Live Coding is programming as a performance art. From Wikipedia:

Live coding ... is a performing arts form and a creativity technique centred upon the writing of source code and the use of interactive programming in an improvised way. Live coding is often used to create sound and image based digital media, as well as light systems, improvised dance and poetry, though is particularly prevalent in computer music usually as improvisation, although it could be combined with algorithmic composition.
Exercise: Read the Wikipedia article on Live Coding.
Exercise: Explore Sonic Pi. Optionally, practice building some tracks. At the end of the course, consider giving a live coding performance to the class.

Here’s a little Sonic Pi performance:

The Big Idea in Programming

By now, you’ve seen a lot of programs that do lots of different things. These programs all ran on the same computer. You probably ran everything without even leaving CodePen. And that’s one cool thing about programming: You don’t need a separate machine for each of those different things!. You don’t need one machine for adding numbers, one for communicating by voice to other people, one for telling the current time, one for telling you how far away your destination is, one for finding the number of days between two dates, one for maintaining your TO-DO list, one for translating Irish poems into Swahili....

You just need one machine.

Exercise: What does that supercomputer in your pocket do that separate “single-function” devices used to (or still) do? Come up with a list of 20 things. Here are some things to get you started: set and activate alarms, make phone calls, tell the time, count your steps, navigate, manage your appointments). What things do they not currently do that you think they should do?

Quotes about Programming

Check out the Wikiquote page on programming. Then search for more. If you are acquainted with Zen Koans, you might like (or dislike) a form of humor called Hacker Koans, which you can find on Wikipedia and on ESR’s CATB site. Here’s one from CATB you might want to keep in mind:

On one occasion, as Master Foo was traveling to a conference with a few of his senior disciples, he was accosted by a hardware designer.

The hardware designer said: “It is rumored that you are a great programmer. How many lines of code do you write per year?”

Master Foo replied with a question: “How many square inches of silicon do you lay out per year?”

“Why...we hardware designers never measure our work in that way.”

“And why not?” Master Foo inquired.

“If we did so,” the hardware designer replied, “we would be tempted to design chips so large that they cannot be fabricated—and, if they were fabricated, their overwhelming complexity would make it be impossible to generate proper test vectors for them.”

Master Foo smiled, and bowed to the hardware designer.

In that moment, the hardware designer achieved enlightenment.