Charles Petzold



Ten Steps to “Code” — A Kind of Memoir

November 17, 2022
New York, N.Y.

Life experiences are liberating and at the same time limiting. As a writer, I feel these limitations quite acutely. I desire to write many different types of books, but I feel condemned by my life experiences to write only certain kinds. Of course that makes sense: We are the sum total of our pasts. Every book is regulated by the author’s background, education, and sensibility, and that’s why every book is unique to the author who wrote it, for better or for worse.

The second edition of my book Code: The Hidden Language of Computer Hardware and Software was recently published, and I’ve already discussed the changes for the second edition. But sometimes people are curious about how books come to be written in the first place.

Here is that story.

(I owe the idea and title of this blog entry to the great Australian comedian Hannah Gadsby, who described how she came to write and perform her award-winning show Nanette in her illuminating book Ten Steps to Nanette: A Memoir Situation.)

1. The Electrically Inquisitive Kid

I was the type of kid who built things and took things apart to see how they worked. Maybe I inherited a proclivity towards engineering from my father and grandfather. Or perhaps my mother recognized something in me and helped nurture that. I read books and magazines about science and electricity, including excessively sanitized biographies of Samuel Morse and Thomas Edison. I had the big Erector Set with the motor. I wired up batteries and lightbulbs, and I knew how to solder at an early age.

I remember a toy kit to build a telegraph key and sounder. A little web search turned up these images from the Telegraph Toys page of the TelegraphKeys.com website:

Telegraph Toy

It even came with a bust of Samuel Morse! Here’s what it looks like assembled:

Telegraph Toy

The batteries go in the rectangular case at the rear. I thought I had remembered winding the wire in the electromagnets, but apparently not. I’m sure I wired electromagnets at some other time, though.

This toy telegraph was part of the Lionel Famous Inventors Series, which came out in 1961 (when I was 8 years old) and cost $5.95. I also had the telephone from the series. (An extensive presentation of the series can be found on the Cornucopia of Toy Trains site.)

This toy telegraph and sounder doesn’t seem like much, but considering the early chapters of Code, I think it might have had some kind of influence on my life.

Healthkits were also a big part of my electronic life. These were electronics that you built yourself, mostly involving (in my day) a lot of resistors, capacitors, and tubes or transistors. Lots of soldering was involved. In my teenage years, I built a HealthKit shortwave receiver. Later on, in my 20s, I built a Heathkit stereo amplifier, an atomic clock that set itself to the correct time based on WWV broadcasts, a multimeter, a frequency counter, and an oscilloscope.

I got into ham radio as well, and in 1968 I got a novice license, WN2FVF. (I’m in the Winter 1968–69 issue of the Radio Amateur Callbook Magazine.) But being a rather shy kid, I was more interested in the radio part and less interested in communicating with other ham radio operators. The novice license expired in two years and I never went beyond that.

As I’ve written before in a blog entry entitled My White Privilege, it’s likely that none of this would have happened had my father not attended the college on a socialist program known as the G.I. Bill that provided college and housing benefits for veterans of WW II. It was at the University of Missouri (which was whites-only at the time) that my father met my mother, and where they developed friendships that later became important to my life and interests.

One example: Our family friends including Bob and Sylvia Beason. She was a sorority sister of my mother’s, and in 1961 he became editor of Mechanix Illustrated and Electronics Illustrated, the latter of which often featured projects that I would try building. The personal connection with this magazine was very important, and my ham radio exam was administered by one of their columnists in the magazine offices.

2. Reading and Writing

I also enjoyed reading from an early age, and somehow I recognized that the name on the cover of a book was the person responsible for writing the book. (Interestingly, for certain favorite childhood series such as The Hardy Boys and Tom Swift Jr., this wasn’t exactly the case. Franklin W. Dixon and Victor Appleton II did not exist, and the books were written by a collective of authors.)

I wanted to be a writer since I was about 10 years old, but I for a long time I thought I would write novels and screenplays. Non-fiction writing or technical writing never seemed to occur to me, even though I had met such writers at the offices of Mechanix Illustrated and Electronics Illustrated.

During my college years in the early 1970s, I was working on a novel about two best friends faced with the prospect of the Vietnam War. One of them registers as a conscientious objector (that would be the autobiographical figure) and the other goes off to war. I didn’t know how it would all end up but I was sure that lessons of great moral and political import were involved.

My first published writing was a series of about 30 reviews of classical music concerts, recordings, plays, movies, and books in my college newspaper. After college, I wrote a novel loosely based on the Satyricon of Petronius (or perhaps Fellini?) but set in Atlanta and New York City. I also wrote a bunch of short stories clearly derivative of the works of Donald Barthelme. None of this was published, nor should it have been. But it was all practice.

3. Becoming a Programmer

I went to college at Stevens Institute of Technology, a small engineering and science school in Hoboken, New Jersey, about a 45-minute drive from where I grew up.

Stevens Tech was the first college to require all incoming freshmen to take a course in programming. (Later it became the first college to require all freshmen to have a laptop.) Consequently, in the fall of 1971, I took a course called E-11, which taught us how to program in FORTRAN using punch cards on a DEC PDP-10 located in the basement of the library.

I didn’t much like programming then. I didn’t like handing the card deck to the gurus behind the counter who would riffle through the cards and say “Well, I see a few syntax errors in there but let’s run it through anyway” and I didn’t like picking up the stack of paper that was clearly too short or (horror upon horror!) much too thick.

Nor did I take to programming in two other courses during my four years at Stevens Tech. One course involved using FORTRAN programming to solve problems in numerical analysis, and the other was an assembly language course where we used a self-published book by the instructor called Meet MACRO-10. It was incomprehensible to me why anyone would want to program in this language; in retrospect, perhaps it wasn’t adequately explained that this was how one used the native machine code of the PDP-10.

When I graduated in 1975 with bachelor and master degrees in mathematics, I moved to New York City and got a job at New York Life Insurance Company. I started out as an actuarial student in the Individual Health Insurance Department. After I dropped out of the actuarial program, I gravitated towards product development, claims analysis, and premium calculations. I first did some punch-card FORTRAN programming on an IBM 1130, but within a few years graduated to using PL/I on an 1130 terminal connected via TSO (time-sharing option) to an IBM/370.

It was only then — coding more interactively on a terminal and using a powerful structured language — that I started getting good at programming. I became comfortable writing large programs and creating useful printouts. I got very good at PL/I and for many decades would cite it as my favorite programming language. One of my favorite constructions in PL/I was its versatile DO loop:

DO A = 5, 10, 15 TO 51 BY 3, 100, 200

It was great for testing code because you could select precisely the cases you wanted.

Later on, we were treated to some APL, which had some array functions quite useful for actuarial calculations. We’d write tiny powerful programs that were incomprehensible to anyone who later had to look at the code.

Still later, we got some IBM PCs in the office. This was before I had an IBM PC at home, but I knew enough to become the local expert, not only in showing people how to use word processing and spreadsheets, but also coding some useful programs in MASM.

I spent exactly 10 years at New York Life Insurance Company, leaving just as I became vested in the company’s pension program. When I turned 65 a few years ago, I began receiving a pension payout of $230 a month.

4. A Deep Dive into Digital Electronics

I always loved New York City. Starting when I was 15 or so, my mother let me take the bus into New York City by myself, a 45-minute trip to the Port Authority Bus Terminal. The famous Book Row on 4th Avenue still existed at the time, and I’d go to the Strand Book Store on Broadway and 12th Street as well. Sometimes I’d see a play such as The Great White Hope.

When I went to college in Hoboken, New Jersey, I was even closer to the city. From Hoboken you could get into the city via bus or the PATH train that travelled under the Hudson and had several stops in the city. We’d often take the PATH into the city to see movies. Clockwork Orange opened during my freshman year. I remember a big group of us going to see The Exorcist, and I remember being blown away by Chinatown. Pierre Boulez was music director of the New York Philharmonic during my college years. He became my musical hero and I’d see lots of the concerts he conducted, including the Prospective Encounters of new music at venues in Greenwich Village, and the Rug Concerts, where the orchestra was moved down in front of the stage allowing some of the audience to sit on cushions on the stage.

When I moved to New York City in 1975, I found an apartment just three blocks south of The Strand. Book Row was gone by that time, but several bookstores adorned 8th Street and St. Mark’s Place.

Soon after I moved to New York City in June 1975, I started seeing a lot of movies. New York City had several revival theaters at the time, such as the Elgin, the Bleeker Street Cinema, and the Carnegie Hall Cinema. They would run double features every day, changing every day, generally showing classics of the American and European cinema. For at least a year, I’d see an average of about 10 movies a week, educating myself in the films of Ingmar Bergman, Federico Fellini, Francois Truffaut, Jean Luc Godard, Éric Rohmer, and others.

I was also writing fiction (as I said), so you wouldn’t think I had time for much else. But I was also getting deeper into a little hobby involving electronic music. I already had an analog synthesizer (the ElectroComp 101) and a Teac four-channel tape deck that I had purchased when I came into a little money when I turned 21 in 1974.

Around 1977, I began wondering if I could build a music sequencer, which is an instrument that repetitively plays a series of programmed notes. In September I bought books by Don Lancaster entitled CMOS Cookbook and TTL Cookbook and allowed him to teach me the fundamentals of digital logic. By 1978 I had a sequencer that let me code patterns of notes in memory using DIP switches, and using other DIP switches to control how the sequences were played back.

Four Channel Sequencer

I remember a particular evening when I began pondering how codes could be stored in memory to control the playback hardware, and I realized I was reinventing the computer. This was a crucial revelation! (I tried to reproduce this experience in Chapter 17 of the 1st edition of Code, which became Chapter 20 in the 2nd edition.)

I had also discovered a magazine called Computer Music Journal whose second issue (April 1977) included a block diagram of a digital electronic music synthesizer — an assemblage of digital hardware that generates sine curves digitally in real time. Such a thing would have to be controlled by a computer, and for that part of the project I selected the Zilog Z80, which implemented a superset of the Intel 8080 instruction set.

By 1981, I had it all working. The computer part was quite primitive. The video display was only capable of displaying 16 rows of 32 characters each, and all the code was hand-assembled. Code for some primitive keyboard and display input/output handling was entered via hex switches; after that, I could enter and display bytes via the keyboard.

But the peripherals were impressive: The computer could read notes pressed and released from a five-octave polyphonic music keyboard, and could also read values from an array of 32 potentiometers and four joysticks through analog-to-digital converters. The computer functioned as an intermediary between these peripherals and the synthesizer, but it could also interpret a primitive Music Programming Language that I devised.

Computer Controlled Digital Synthesizer

The synthesizer part digitally generated 80 audio sine waves in real time combined in pairs for simple FM synthesis. The synthesizer hardware also handled envelope segments. In other words, rather than have the computer load a frequency and amplitude into the synthesizer, it loaded values to define ramps between two frequencies and two amplitudes. When the segment of the envelope completed, the computer would be informed via an interrupt and then load the next segment.

I discuss these projects in much more detail in the document Adventures in Electronic Music, which also includes more pictures and (if you’re particularly courageous or masochistic) music files.

This was just — I hasten to add — a hobby. It never occurred to me that I might develop and market something. (I seem to lack the entrepreneur gene.) But without the experience of building this thing, I doubt that Code would ever have been written.

In 1983 I got my first store-bought computer, which was an Osborne 1. Although I toyed around with the idea of having the Osborne control the synthesizer, I primarily thought of it as a word-processing machine for my short stories. Of course, I explored CP/M and 8080 assembly language, which was a step up from the machine-code programming of my homebrew machine.

5. Writing Professionally

The insurance company where I worked had acquitted some IBM PCs, and that was my first introduction to MS-DOS and MASM. But it was obvious that the IBM PC was the future, and in January 1984, I wiped out three credit cards buying my own two-floppy IBM PC with a green-screen character-mode monitor.

I realized I’d need to pay off the credit cards somehow, so I wrote an article about the MS-DOS Prompt command and sent it to PC Magazine. They paid me $650 for it.

More importantly, I got on a list of PC Magazine writers who lived in the New York City area. In the summer of 1984, John Dickinson was put in charge of a project to review every printer available for the IBM PC, and I received an invitation to come into the magazine. The offices of PC Magazine were at 1 Park Avenue, just a couple blocks north of New York Life Insurance Company at 51 Madison Avenue, which was about a 20-minute walk from my apartment.

That’s how I met the editors of PC Magazine (at the time headed by the brilliant Bill Machrone) and a bunch of other freelancers. That first printer project was published in the November 27, 1984, issue:

PC Magazine Vol 3 No 23

Writing for PC Magazine was an extraordinary experience, heightened by the proximity of the magazine’s office to my home. It was easy to take vacation days from my job at New York Life and go into the magazine offices to review hardware, to chat with the editors, and to go out to lunch.

This is really where I learned to write professionally. If editors weren’t entirely happy with what you’d done, you’d hear back from them, and you’d be able to read the edited copy. My writing still tends to be a little flabby, and it was illuminating to see how a good editor could tighten up my prose and still maintain my voice. I never really graduated from being primarily a magazine writer. Even in my books, my paragraphs tend to be quite short.

I showed John Dickinson some little assembly language programs I had written for the PC, and he steered me into the offices of Paul Somerson, and that’s how I came to write little programs for PC Magazine’s “back of the book” which was more geared towards power users and programmers.

By the middle of 1985, I had used up all my vacation days at New York Life Insurance Company, and I was also making money from PC Magazine that rivaled my salary. I decided to quit my insurance job and become a fulltime freelancer. I am inherently a very conservative person who values stability and security in my life, so quitting my job and essentially becoming unemployed was the scariest thing I ever did.

6. A Certain “PC Tutor” Column

Shortly after I quit my job at New York Life Insurance in the summer of 1985, PC Magazine Executive Editor Paul Somerson called me into his office and offered me the “PC Tutor” column. This column featured queries from readers and my job would be to answer them. I took over the “PC Tutor” column starting in the October 1, 1985, issue, and continued for about two years. During that time, I handled a variety of questions across the technical spectrum.

Towards the end of my stint with “PC Tutor,” I found one question so intriguing that I spent the whole column answering it. It appeared in the August 1987 issue under the title “Chomping at the Bits.” Here it is in Google Books:

PC Tutor Vol 6 No 14

Most language mavens contend that the correct expression is “champ at the bits,” but I didn’t write that part. Instead, I showed from a strictly mathematical perspective without any symbolic drawings of logic gates how a computer adds binary numbers.

My editor (Craig Stark) was quite impressed. He didn’t know how computers added numbers together and I suspect a lot of other readers didn’t either.

I’m not sure when it occurred to me that this explanation of bits and logical operations might be expanded into a book. In 1987 I was realistic enough to know that no publisher would have contracted with me to write such a book. Books about digital logic design were written by engineers and professors for college courses. I had no qualifications to write a book like that, and no track record. In 1987 I had never written a book.

But one was in the works.

7. Establishing a Track Record

Over the course of 1985, the offices of PC Magazine were occasionally visited by a contingent from Microsoft showing off beta versions of a new application environment known as Windows. I remember in particular Steve Ballmer and Tandy Trower heading this contingent. They would convey their excitement about Windows and leave the latest build for us to play around with.

Windows wasn’t the only programming environment being developed for DOS. There were at least three others, and I was very honored to write the introduction to the cover story for PC Magazine showdown of these four major windowing environments. This is the February 15, 1986 issue with a link to the complete issue in Google Books:

PC Magazine Vol 5 No 4

Besides the introduction, I also wrote about IBM’s TopView (page 118) and the SDKs for TopView and Windows (page 127). By this time, the SDK came in a box, but I remember my introduction to the SDK:

One day in 1985 when Windows was still in beta, I asked John Dickinson how one writes programs for the envrionment. He pulled from his desk a big pile of printed pages and a stack of 5-inch floppy diskettes all held together with a rubber band, and he told me to take them, please, and not bring them back. It was a beta Windows SDK and a C compiler, and apparently I was the first person at PC Magazine to express an interest in Windows from a programming perspective.

I took the bundle home and installed the SDK and C compiler on a Bernoulli Box with two large 10-megabyte drives that I had recently purchased. After studying the five sample Windows programs and the API, about six months later I was able to write my first Windows programs.

At this time, PC Magazine was not interested in running Windows programs in the back of the book. But at some point, I showed a couple little Windows programs I was writing to Jon Lazarus, who was an executive at Ziff-Davis, the company that owned PC Magazine. He soon left that job to start up a new magazine.

Microsoft Systems Journal was originally supposed to focus entirely on Windows but it was later believed safer to expand that coverage to all Microsoft operating systems. Jon recruited me as a writer. For the first issue (dated October 1986) I wrote about a new dialog editor. (It “can be downloaded from the Microsoft SIG on CompuServe.”) For the second issue (December 1986) I wrote the very first magazine article about programming applications for Windows. Over succeeding issues, I presented several other little Windows programs.

I think that there must have been some gap between writing these program and their appearance in the magazine. I remember some kind of industry event where I ran into Tandy Trower and told him how much I was enjoying writing Windows applications for Microsoft Systems Journal. That conversation was fortuitous because when Microsoft Press Editor-in-Chief Susan Lammers asked Tandy Trower who would be a good person to write a book about Windows, he gave her my name, and she gave me a phone call at my home.

As I recall, I told Susan that writing a book about Windows was a big job and “Let me think about it” and then 10 minutes later called her back to beg her to let me write this book. I met with Microsoft Press Acquisitions Editor Claudette Moore at the Fall 1986 Comdex in Las Vegas where we talked about contracts and schedules. The contract for Windows for Programmers and Other Advanced Users is dated December 1986 and was signed by me and Microsoft President Jon Shirley in January 1987.

As I was writing this book, the focus changed somewhat. I began using Windows 1.0, but as I was writing it, betas of Windows 2.0 became available. The big change was a switch from tiled windows to overlapping windows. Originally the book was supposed to be for both programmers and power users, but it soon became obvious that we couldn’t please everyone. The focus of the book narrowed to programmers who already knew C, and the title became Programming Windows.

I had found a niche for myself that defined my professional life for nearly three decades — from the first edition of Programming Windows to Creating Mobile Apps with Xamarin Forms in 2016. It was a comfortable niche. I don’t think of myself as a good writer, but I’m a better writer than most programmers. I don’t think I’m a particularly good programmer either, but I’m a much better programmer than most writers. I believe that my greatest skill was in organizing the material in my books so that the narrative proceeds progressively from beginning to end in a reasonable manner. What I tried to avoid at all costs was asking the reader to believe something on faith that would be explained more fully in a later chapter.

The first edition of Programming Windows was published in February 1988. The second edition on Windows 3.0 was published in 1990 and the third edition (Windows 3.1) in 1992. I wrote another book on OS/2 Presentation Manager Programming published in 1994, and the 4th edition of Programming Windows (focusing on Windows 95) in 1996.

Demonstrating that I was capable of organizing and writing a book was a necessary prerequisite for a project that I, the author, would initiate— a book that had nothing to do with any Microsoft product.

8. Letting it Slow-Cook

During the entire time that I was writing books on Windows and the OS/2 Presentation Manager, I was also thinking about quite a different book, a book that showed how computers work starting from very basic ideas. I knew that writing this book would be challenging, but it kept rattling around in my head and I couldn’t shake it free. I understood what Vladimir Nabokov meant when he said that he wrote a book to get rid of it. I had to get rid of this book or it would haunt me forever.

The title came quickly: Code. Simple, elegant, and exactly what the book was going to be about. I knew there would also be a subtitle, but I didn’t have that yet, and I struggled with it for many years.

For about a decade, ideas connected with this book would bounce around in my head, and during that time the basic framework of the book became apparent to me:

I knew I wanted to build logic gates in the early chapters, but I didn’t want to even try to explain how a transistor works. Somehow I learned that early digital computers were built instead from relays. Relays had been invented in early telegraph systems and then used in telephone switching circuits. I thought that explaining how a relay works would be much simpler. It’s just an electromagnet that triggers a switch.

Once I started thinking about telegraphs, I started thinking about Morse code, and how Morse code is a binary code and hence has some relevance to binary numbers and digital computers. And then flashlights came to mind, which is the customary way that kids experiment with Morse code. And flashlights also provide a good introduction to electricity. Connections were being made for a progressive presentation.

In my head, the early chapters took shape: Flashlights, Morse code, electricity, telegraphs, relays, logic gates, a binary adder… Oh wait: Before the binary adder I would need to explain binary numbers. How do binary numbers fit into this presentation? (In an unavoidably disruptive manner, it turned out.) I also had the opening sentences.

Towards the end of this decade-long process, the concept of the book had jelled enough that I could begin trying to write it. But I wasn’t capable of putting fingers to keyboard just yet.

9. Getting Sober

Beginning in the early 1990s, I developed a drinking problem that gradually evolved into full-blown alcoholism. I think I started frequenting bars just for the social companionship that was missing in my personal life after I stopped frequenting the offices of PC Magazine to spend more time in isolation writing books. But there was also quite a lot of drinking with magazine and industry people as well. I had a certain reputation.

Many of my new best friends were regulars at the bar I hung out at the most on St. Mark’s Place, where I drank and shot pool until the wee hours, often when the bar closed at 4:00 AM. I would then stagger back home and sleep until about noon.

Eventually it became very difficult to work. I started drinking during the day and even right after I woke up to stop my hands from shaking. Hands that shake in the morning signal a physical addiction to alcohol.

In January of 1996, I was hospitalized for alcohol-induced gastrointestinal bleeding. I spent five days in the emergency room at St. Vincent’s Hospital in the West Village during which I was detoxed from alcohol with Librium.

For me, the hospitalization was a wakeup call, and I haven’t had a drink since. I attended an evening rehab for a couple months, and soon found some A.A. meetings in Manhattan that catered to people like myself with nonexistent religious beliefs. These meetings were essential to my recovery, and I made many friends in them, including (in 1997) my wife.

When I got sober, I discovered I had lots more energy. I finished the 5th edition of Programming Windows (1479 pages!) in 1998 including a 130-page chapter on “Sound and Music.” In one sense, getting this “final” edition of Programming Windows finished was a way to clear my desk for something quite different.

10. Selling the Concept

Getting sober was also an incentive to extract from my head the book that had been rattling around for about a decade.

I knew that Code was basically a book about how computers worked, but it was not your conventional “how computers work” book. My approach was unusual. At times I thought it was too unusual and that nobody would understand what I was trying to do. At other times, I thought my conception was so obvious that somebody else would beat me to market.

I realized that the best way to demonstrate what Code was all about was to write a large chunk of it. This would give people the flavor of the book and also serve as a type of feasibility study to establish to myself that such a book was possible.

As I recall, I wrote about a hundred pages, ending with what became Chapter 12, which shows how logic gates can be combined to add binary numbers. (In the 1st edition, that’s more like 140 pages, so much of this was later fleshed out.) I hand-drew all the diagrams using plastic RapiDesign templates for the logic gates. I then scanned these diagrams and copied them into the Word document.

I sent this to my agent, Claudette Moore (the former Acquisitions Editor of Microsoft Press). I don’t know if I sent the printed pages or the Word file. But she really liked it, and she sent it off to Microsoft Press, who also like the concept and execution. The contract for Code (no subtitle yet) is dated May 1998.

Then the hard work began. Then I had to write the rest of the book.