Software developers talk a lot about a piece of code being "beautiful" or "ugly". Mathematicians do something similar: "Beauty is the first test: there is no permanent place in the world for ugly mathematics", wrote the great number theorist G. H. Hardy. Scientists, too, use the language of beauty to describe their work. And many people (myself among them) think that engineering designs and engineered objects can be beautiful in their own right--there's even a "movement", sometimes called Machine Art or Precisionism, to that effect.
Suspended Power, Charles Sheeler. Image from the Dallas Museum of Art
On the other hand, it's a commonplace to observe that there is a deep cultural divide between humanists and scientists (and engineers). Vikram Chandra, who's both a software developer and an award-winning novelist, wrote this book to try to explore whether and how these ideas of beauty cross that divide.
As you'd expect, the book is wide-ranging. It's got some (largely non-technical) discussion of software and the software writing process in it, but it also has a good chunk of fascinating autobiography, and a deep dive into Sanskrit language and classical Indian aesthetic theory. The latter is particularly novel to a western reader, and in some ways quite extraordinary.
As you'd also expect, it's beautifully written. In fact, it's so beautifully written that it took me a while to realize that its various parts don't always cohere very well. The discussion of the lowest level of the computer (the logic gate) is very clear, for example, but it's not clear what it has to do with the rest of the book. Similarly, the dearth of women in U.S. computer science compared to India is a very interesting topic; I'm just not sure what it's doing in this book.
But if we're talking about "the beauty of code", cohesion is vital. So, ultimately, Geek Sublime left me a little unsatisfied; I'm not entirely sure what conclusion Chandra really reaches, if any.
So I'll favor you with my own conclusions instead. For reference, I am a practicing software engineer. Although I'm not an award-winning novelist, I write both fiction and non-fiction for pleasure. I do artwork and illustration (they're not the same, although they're related). I've composed and performed music, to my own satisfaction and occasionally to others'.
In my subjective experience, there is certainly a connection between beautiful code and good writing—a connection which I can only describe as a shape. Good code and good prose both have a definable structure, a sense of which is almost a kinesthetic experience; I find myself waving my hands around in the air, as if molding invisible clay words, when I'm trying to describe it. In a work with a good shape, everything relates to everything else. Nothing is missing. Nothing is wasted.
The difference, thought, is that in engineering a lovely shape is never enough. An engineered design, like an equation or a scientific theory, has to work. No code can be beautiful if it doesn't do anything, or if it does something wrong. For a book or a poem or a painting, beauty does not serve function; to be beautiful is the function.