Archive for June, 2015

A very nice way to write applications

June 21, 2015

Recently I have been reading about the UNIX philosophy for writing programs and applications. [1]

Their approach is to create small, simple programs (exe files) that can be flexibly composed using a scripting language. Here’s an example: ls is a program that lists the content of your current folder, sort is a program that sorts its input. Most scripting languages have a pipe ( | ) operator. We can use pipe to send the output of the ls program into the sort program:

ls | sort

That results in outputting the content of your current folder, in sorted order.

The UNIX people have been following this kind of assemble-from-small-programs approach for decades and it has been phenomenally successful. Many of their programs were written in C. But today a lot of their programs are written in Python [2]. A really awesome thing is that C programs and Python programs can be mixed-and-matched. I wanted to see how this works so I wrote a simple Python program,, which outputs a message (Hello, World) and a simple C program, id.c, which reads input and outputs it. The two programs are completely independent (two exe files). Then I used a scripting language to compose the two programs:

mesg | id

That results in outputting the message.

In general, with this approach we can compose any number of programs:

A | B | C | …

Each program can be written in Python or C (increasingly programs are written in the Go programming language).

Interested in learning more about how I implemented my mesg-id application? See here [3].

[1] These are fantastic books: (1) The UNIX Philosophy by Mike Gancarz, and (2) The Art of UNIX Programming by Eric S. Raymond.

[2] See this Stack Overflow question: Modern-day Unix tools are written in what programming language? (

[3] I initially implemented both the mesg program and the id program in Python. I’m a Python newbie so I asked a question about this on Stack Overflow: How to compose Python exe programs using pipes? ( Later I implemented the id program in C and then used a scripting language to compose the Python mesg program to the C id program. This is a very nice way to write applications!