Geek Sublime Read online




  geek sublime

  Also by Vikram Chandra

  Red Earth and Pouring Rain

  Love and Longing in Bombay

  Sacred Games

  geek

  sublime

  the beauty of code,

  the code of beauty

  vikram chandra

  GRAYWOLF PRESS

  Copyright © 2014 by Vikram Chandra

  Copyright Acknowledgments are an extension of the copyright page.

  This publication is made possible, in part, by the voters of Minnesota through a Minnesota State Arts Board Operating Support grant, thanks to a legislative appropriation from the arts and cultural heritage fund, and through a grant from the Wells Fargo Foundation Minnesota. Significant support has also been provided by Target, the McKnight Foundation, Amazon.com, and other generous contributions from foundations, corporations, and individuals. To these organizations and individuals we offer our heartfelt thanks.

  Published by Graywolf Press

  250 Third Avenue North, Suite 600

  Minneapolis, Minnesota 55401

  All rights reserved.

  www.graywolfpress.org

  Published in the United States of America

  ISBN 978-1-55597-685-9

  Ebook ISBN 978-1-55597-326-1

  2 4 6 8 9 7 5 3 1

  First Graywolf Printing, 2014

  Library of Congress Control Number: 2014935698

  Cover design: Kapo Ng

  Cover art: Svetlana Lukienko, Shutterstock

  For Melanie,

  Sri Sri Sri

  CONTENTS

  List of Figures

  Acknowledgments

  Note on Transliteration

  1. Hello, World!

  2. Learning to Write

  3. The Language of Logic

  4. Histories and Mythologies

  5. The Code of Beauty: Anandavardhana

  6. The Beauty of Code

  7. The Code of Beauty: Abhinavagupta

  8. Mythologies and Histories

  9. The Language of Literature

  10. Application.Restart()

  Notes

  Bibliography

  Copyright Acknowledgments

  LIST OF FIGURES

  Figure 3.1: CIL for “Hello, world!” program in C#

  Figure 3.2: Machine code for “Hello, world!” program in C#

  Figure 3.3: Addition operator

  Figure 3.4: Addition operator with inputs “3” and “2”

  Figure 3.5: Subtraction operator

  Figure 3.6: Subtraction operator with inputs “4.2” and “2.2”

  Figure 3.7: AND operator

  Figure 3.8: AND operator with inputs “false” and “true”

  Figure 3.9: AND operator with inputs “true” and “true”

  Figure 3.10: OR operator with inputs “false” and “true”

  Figure 3.11: OR operator with inputs “0” and “1”

  Figure 3.12: XOR operator with inputs “1” and “1”

  Figure 3.13: LEGO AND logic gate with inputs “0” and “0” (Martin Howard)

  Figure 3.14: LEGO AND logic gate with inputs “1” and “1” (Martin Howard)

  Figure 3.15: LEGO XOR logic gate with inputs “0” and “0” (Martin Howard)

  Figure 3.16: LEGO XOR logic gate with inputs “0” and “1” (Martin Howard)

  Figure 3.17: Schematic for half adder

  Figure 3.18: LEGO half adder (Martin Howard)

  Figure 3.19: “Hello, world!” in assembly language

  Figure 3.20: “Hello, world!” in FORTRAN

  Figure 4.1: Programming the ENIAC (US Army photo)

  Figure 4.2: Programming the ENIAC (US Army photo)

  Figure 4.3: “Installing IBM 1620 computer in 1963 when first laboratory building was under construction.” Photographer unknown. Tech Engineering News Vol. XLIX, no. 3, April 1967. Institute Archives and Special Collections, MIT Libraries, Cambridge, MA

  Figure 5.1: Rules from the Ashtadhyayi (Vedic Literature Collection, Maharishi University of Management)

  Figure 6.1: Dependency diagram (TheDailyWTF, www.thedailywtf.com)

  Figure 6.2: “Hello, world!” in brainfuck

  Figure 6.3: “Hello, world!” in Malbolge

  Figure 6.4: Gartner, Inc.’s Hype Cycle (Jeremy Kemp, Wikimedia Commons)

  ACKNOWLEDGMENTS

  This project has been supported by the University of California, Berkeley.

  Thanks to Martin Howard for the images of the LEGO logic gates (http://www.randomwraith.com/logic.html); and to Alex Papadimoulis of TheDailyWTF.com for the dependency diagram.

  For inspiration, aid, and insight, I’m grateful to Jennie Durant; Janet Miller; Maura Finklestein; Wendy James, for the loan of that PCjr; Margo True; David Harvey, with fond memories of “the rapture of the freeways” and AH&AJ Computing; Balaji Venkateswaran; Jeff Kowalski; Sumeet Shetty; S. Sadagopan; Eric Simonoff; Julian Loose; Ethan Nosowsky; Alok Aggarwal; Telle Whitney; Maria Klawe; Roli Varma; Dominik Wujastyk; Arati Gerdes; Ida Mayer; Avnish Bhatnagar; Balajee Vamanan; Dipankar Bajpai; Raka Ray; and Kapil Kapoor, for his help and his invaluable books about the Indian literary tradition.

  Luther Obrock translated all the poems from the Dhvanyaloka, and was unstintingly generous with his knowledge and ideas. He provided essential guidance through the subtleties of the dhvanikaras.

  The translation of “I will tell you a funny story” from the Bhaver Gita was a collaborative effort: thanks to Dilip Misra, Rakesh Mishra, and Monidipa Mondal for their help.

  Thanks to Chiki Sarkar for helping me discover the shape of this book; and to Tanvi Kapoor and her team at Penguin India for their heroic efforts at bringing the project to fruition.

  As always, I couldn’t have started or finished the book without support from my parents, Navin and Kamna; my sisters, Tanuja and Anupama; Vidhu Vinod Chopra; Anuradha Tandon; S. Hussain Zaidi.

  I’m especially grateful to the two irrepressible shaktis, Leela and Darshana, for their timely interruptions and revivifying hugs.

  NOTE ON TRANSLITERATION

  Sanskrit words in this book have been rendered phonetically, without the use of diacritical marks: “Shakti,” not “Śakti.” Diacritics have been retained in direct quotations and the titles of cited works.

  1 HELLO, WORLD!

  class Program

  {

  public static void Main()

  {

  System.Console.WriteLine(“Hello, world!”);

  }

  }

  Even if you’re the kind of person who tells new acquaintances at dinner parties that you hate e-mail and e-books, you probably recognize the words above as being some kind of computer code. You may even be able to work out, more or less, what this little “Program” does: it writes to the console of some system the line “Hello, world!”

  A geek hunched over a laptop tapping frantically at the keyboard, neon-bright lines of green code sliding up the screen—the programmer at work is now a familiar staple of popular entertainment. The clipped shorthand and digits of programming languages are familiar even to civilians, if only as runic incantations charged with world-changing power. Computing has transformed all our lives, but the processes and cultures that produce software remain largely opaque, alien, unknown. This is certainly true within my own professional community of fiction writers—whenever I tell one of my fellow authors that I supported myself through the writing of my first novel by working as a programmer and a computer consultant, I evoke a response that mixes bemusement, bafflement, and a touch of awe, as if I’d just said that I could levitate. Most of the artists I know—painters, filmmakers, actors, poets—seem to regard programming as an esoteric scientific discipline; they are keenly aware of its cultural mysti
que, envious of its potential profitability, and eager to extract metaphors, imagery, and dramatic possibility from its history, but coding may as well be nuclear physics as far as relevance to their own daily practice is concerned.

  Many programmers, on the other hand, regard themselves as artists. Since programmers create complex objects, and care not just about function but also about beauty, they are just like painters or sculptors. The best-known assertion of this notion is the essay “Hackers and Painters” by programmer and venture capitalist Paul Graham. “Of all the different types of people I’ve known, hackers and painters are among the most alike,” writes Graham. “What hackers and painters have in common is that they’re both makers. Along with composers, architects, and writers, what hackers and painters are trying to do is make good things.”1

  According to Graham, the iterative processes of programming—write, debug (discover and remove bugs, which are coding errors, mistakes), rewrite, experiment, debug, rewrite—exactly duplicate the methods of artists: “The way to create something beautiful is often to make subtle tweaks to something that already exists, or to combine existing ideas in a slightly new way … You should figure out programs as you’re writing them, just as writers and painters and architects do.”2 Attention to detail further marks good hackers with artist-like passion:

  All those unseen details [in a Leonardo da Vinci painting] combine to produce something that’s just stunning, like a thousand barely audible voices all singing in tune.

  Great software, likewise, requires a fanatical devotion to beauty. If you look inside good software, you find that parts no one is ever supposed to see are beautiful too.3

  This desire to equate art and programming has a lengthy pedigree. In 1972, the famed computer scientist Butler Lampson published an editorial titled “Programmers as Authors” that began:

  Creative endeavour varies greatly in the amount of overhead (i.e. money, manpower and organization) associated with a project which calls for a given amount of creative work. At one extreme is the activity of an aircraft designer, at the other that of a poet. The art of programming currently falls much closer to the former than the latter. I believe, however, that this situation is likely to change considerably in the next decade.4

  Lampson’s argument was that hardware would become so cheap that “almost everyone who uses a pencil will use a computer,” and that these users would be able to use “reliable software components” to put together complex programs. “As a result, millions of people will write non-trivial programs, and hundreds of thousands will try to sell them.”5

  A poet, however, might wonder why Lampson would place poetry making on the same spectrum of complexity as aircraft design, how the two disciplines—besides being “creative”—are in any way similar. After all, if Lampson’s intent is to point toward the future reduction of technological overhead and the democratization of programming, there are plenty of other technical and scientific fields in which the employment of pencil and paper by individuals might produce substantial results. Architecture, perhaps, or carpentry, or mathematics. One thinks of Einstein in the patent office at Bern. But even the title of Lampson’s essay hints at a desire for kinship with writers, an identification that aligns what programmers and authors do and makes them—somehow, eventually—the same.

  Both writers and programmers struggle with language. The code at the beginning of this chapter is in Microsoft’s C#, one of thousands of high-level programming languages invented over the last century. Each of these is a “formal language,” a language “with explicit and precise rules for its syntax and semantics,” as the Oxford Dictionary of Computing puts it. Formal languages “contrast with natural languages such as English whose rules, evolving as they do with use, fall short of being either a complete or a precise definition of the syntax, much less the semantics, of the language.”6 So these formal dialects may be less flexible and less forgiving of ambiguity than natural languages, but coders—like poets—manipulate linguistic structures and tropes, search for expressivity and clarity. While a piece of code may pass instructions to a computer, its real audience, its readers, are the programmers who will add features and remove bugs in the days and years after the code is first created. Donald Knuth is the author of the revered magnum opus on computer algorithms and data structures, The Art of Computer Programming. Volume 3 of the Art was published in 1973; the first part of Volume 4 appeared in 2011, the next part is “under preparation.” If ever there was a person who fluently spoke the native idiom of machines, it is Knuth, computing’s great living sage. More than anyone else, he understands the paradox that programmers write code for other humans, not for machines: “Let us change our traditional attitude to the construction of programs: Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do.”7 In 1984, therefore, he famously formalized the notion of “literate programming”:

  The practitioner of literate programming can be regarded as an essayist, whose main concern is with exposition and excellence of style. Such an author, with thesaurus in hand, chooses the names of variables carefully and explains what each variable means. He or she strives for a program that is comprehensible because its concepts have been introduced in an order that is best for human understanding, using a mixture of formal and informal methods that reinforce each other.8

  Good code, then, is marked by qualities that go beyond the purely practical; like equations in physics or mathematics, code can aspire to elegance. Knuth remarked about the code of a compiler that it was “plodding and excruciating to read, because it just didn’t possess any wit whatsoever. It got the job done, but its use of the computer was very disappointing.”9

  To get the job done—a novice may imagine that this is what code is supposed to do. Code is, after all, a series of commands issued to a dumb hunk of metal and silicon and plastic animated by electricity. What more could you want it to do, to be? Knuth answers: code must be “absolutely beautiful.”10 He once said about a program called SOAP (Symbolic Optimal Assembly Program) that “reading it was just like hearing a symphony, because every instruction was sort of doing two things and everything came together gracefully.”11

  We are now unmistakably in the realm of human perception, taste, and pleasure, and therefore of aesthetics. Can code itself—as opposed to the programs that are constructed with code—be beautiful? Programmers certainly think so. Greg Wilson, the editor of Beautiful Code, an anthology of essays by programmers about “the most beautiful piece of code they knew,”12 writes in his foreword to that book:

  I got my first job as a programmer in the summer of 1982. Two weeks after I started, one of the system administrators loaned me Kernighan and Plauger’s The Elements of Programming Style … and Wirth’s Algorithms + Data Structures = Programs … [These books] were a revelation—for the first time, I saw that programs could be more than just instructions for computers. They could be as elegant as well-made kitchen cabinets, as graceful as a suspension bridge, or as eloquent as one of George Orwell’s essays.13

  Knuth himself is careful to limit the scope of his aesthetic claims: “I do think issues of style do come through and make certain programs a genuine pleasure to read. Probably not, however, to the extent that they would give me any transcendental emotions.”14 But in the many discussions that programmers have about craftsmanship, elegance, and beauty, there is an unmistakable tendency to assert—as Wilson does—that code is as “eloquent” as literature.

  “Hackers and Painters” provoked an equally famous takedown titled “Dabblers and Blowhards” by the painter and programmer Maciej Ceglowski:

  It is true that both painters and programmers make things, just like a pastry chef makes a wedding cake, or a chicken makes an egg. But nothing about what they make, the purposes it serves, or how they go about doing it is in any way similar …

  With the exception of art software projects (which I don’t believe Grah
am has in mind here) all computer programs are designed to accomplish some kind of task. Even the most elegant of computer programs, in order to be considered a program, has to compile and run. So just like mechanical engineers and architects, computer programmers create artefacts that have to stand up to an objective reality. No one cares how pretty the code is if the program won’t work. The only objective constraint a painter has is making sure the paint physically stays on the canvas (something that has proven surprisingly challenging). Everything beyond that is aesthetics—arranging coloured blobs in a way that best tickles the mind of the viewer.15

  Paul Graham has been hugely successful as a programmer and venture capitalist, and his essays about technology and business are sometimes thought-provoking and insightful. But his writings about art are full of majestically fatuous statements delivered with oracular certainty: “One of the reasons Jane Austen’s novels are so good is that she read them out loud to her family. That’s why she never sinks into self-indulgently arty descriptions of landscapes, or pretentious philosophizing.”16 And, “The paintings made between 1430 and 1500 are still unsurpassed.”17 But for Graham’s primary readership of programmers, these pronouncements are the foundational caissons on which his grand art-hacking equivalence rests. Ceglowski the painter is skeptical:

  You can safely replace “painters”… with “poets,” “composers,” “pastry chefs” or “auto mechanics” with no loss of meaning or insight … The reason Graham’s essay isn’t entitled “Hackers and Pastry Chefs” is not because there is something that unites painters and programmers into a secret brotherhood, but because Paul Graham likes to cultivate the arty aura that comes from working in the visual arts.18