One of the greatest virtues that a programmer should have is humility: it allows to be non-judgmental and prone to learn. Sometimes, because of pride and self confidence, it’s difficult or unnatural to feel humble in front of a fellow student, or a coworker, or your boss, or sometimes even your teacher. But if you don’t feel humble in front of Donald Knuth, you’re either arrogant or ignorant.
In the name of humility, one of the most religious ways to learn programming is by following Knuth’s examples, study his style and try to understand his way of thinking. His most famous work is The Art of Computer Programming, but he also makes available a series of sample programs on his personal site. These programs are written in CWEB, that is a programming language to write together code and documentation into a “
.w” file. For example, to check his Tic-tac-toe program:
$ wget http://www-cs-faculty.stanford.edu/~uno/programs/tictactoe.tgz $ tar xzf tictactoe.tgz $ cd tictactoe $ ls -1 tictactoe0.w tictactoe1.w tictactoe2.w tictactoe3.w tictactoe4.w tictactoe5.w tictactoe6.w tictactoe7.w
The files are all text files, but their format is unfamiliar to read. To create both code and documentation for all the files, I created a simple Makefile:
W_FILES := $(shell ls *.w) BASE_FILES = $(basename $(W_FILES)) OUT_FILES = $(foreach sfx,.pdf .c, $(addsuffix $(sfx), $(BASE_FILES))) INTERM_FILES = $(foreach sfx,.idx .log .scn .toc, $(addsuffix $(sfx), $(BASE_FILES))) all: $(OUT_FILES) clean: rm -f $(OUT_FILES) $(INTERM_FILES) %.pdf: %.tex pdftex $<
Then, running “
make” will create C source files and PDF documentation for all the “
.w” files; it needs the programs “
ctangle” and “
pdftex“. The Makefile works because GNU Make contains a series of implicit rules, including the ones to generate TeX documents and C sources from CWEB files.
If I have seen further it is only by standing on the shoulders of giants.
There is a high probability that I will never be able to climb on top of the shoulders of our highest Giants, but at least I hope I can be a climbing aid for other people, and make it easier for them to raise in knowledge with more efficiency.