I have just started reading “Software tools in Pascal”, by Brian W. Kernighan and P.J. Plauger. Even better, I am “borrowing” it for free from Open Library.
My interest was prompted by my work on “neoleo”, my fork of the GNU oleo spreadsheet program. The program is a real rats nest of code, where simple modifications are difficult. I am interested in ripping most of the interface code from it, and creating a kind of “neoleo is to spreadsheets what ed is to text editors”.
Neoleo consists of ~55k of (mostly) C code. It would be great if I could reduce that code by 90%. I have already stripped out its Motif code. Taking out the X11 interface is high on my agenda. Neoleo has an “abstract interface” designed work with curses, Motif and X11. By reducing the code to only one interface, there would no longer be any need for this abstraction.
The interface code consists of a very large body of code, and it is complicated. It does keymap translations, window frame stacking, keymaps which are context-sensitive to the type of window frame, and so on. If I were to eliminate all this interfacing, thereby reducing neoleo to a program that processes stdin and outputs to stdout, I could eliminate a lot of code and complexity. It has yet to be determined if I could remove 90%, but it should be a high percentage. Migrating to C++ should also help reduce the code base, and memory leaks, too.
Modern computers are more accessible than they have ever been, what with office suites and so on. Whilst on the one hand that is good, I think we have lost the point of what computers are supposed to do: to automate tasks. With all this modernity, we have managed to regress the computer from an automatic processing machine to a device that has to be used manually.
That being the case, I think we need to roll back our thinking. Here is what the book’s authors said, even back in 1981 [emph mine]:
Suppose you have a 5000-line Pascal program and you need to find all references to the variable time … How would you do it?
One possibility is to get a listing and mark it up with a red pencil. But it doesn’t take much imagination to see what’s wrong with red-pencilling a hundred pages of computer paper. …
Far too many programmers are red pencillers. Some are literal red pencillers who do things by hand that should be done by machine. Others are figurative red pencillers whose use of the machine is so clumsy and awkward that it might as well be manual.
The book explains how UNIX programs could be constructed, by a guy who was instrumental in its creation.
I think it behooves us as programmers to read through this old material with a mind to see how the way we approach writing applications.
It is time to recount my XML anecdote: a few years ago, I was working on a Fortran program (not my own) that took a plain text file that had the daily oil production for a platform. It basically consisted of several arrays, of fixed size, with each value on a line.
Fortran is really good at reading array from files, you just use the read statement. Think about it: with just a few of these statements, you could load data, no parsing necessary. Fortran gave you that.
One day, I happened to pass by a meeting in which an outside programming consultant from a big IT firm was chatting with some of our oil and gas non-programming consultants. I overheard him say something along the lines of “and of course, if we think we need that output, we could always put it in the XML file”.
I was thinking to myself, great, now to read in data we will have to rely on third-party libraries and scan through a data hierarchy in order to find the data we need.
I should also point out that the Fortran program compiled without incident when I installed it on my machine. I was amazed that compiling programs could Just Work (TM). If this XML idea was introduced, then it would be very difficult to integrate into Fortran, and create many external dependencies.
That, my friends, is why we need to relearn the computing lessons from the 50’s, 60’s and 70’s in order to create high-quality programs. And why I am reading the book.