The computational salon

Elegant scientific programming for fun and profit

A personal introduction

"It was said that physicists could be divided into two groups, those who had played with chemistry sets and those who had played with radios" (Gleick 1992). I suppose that I belong to a third kind that could not have occurred before the last part of the twentieth century: my fascination with mathematics and the physical sciences came through computer programming, and in particular through Scientific American's "Computer recreations" column, run by A. K. Dewdney and Brian Hayes.

It was 1987, I was 14, and just learning how to program (as it turns out, in Microsoft Basic, on a 16-bit Commodore Amiga), and I was engrossed by the discovery that computer simulations could be used as a microscope, zooming into the exotic mathematical geography of the Mandelbrot set; as a telescope, looking out to the trajectories of stars in a galaxies (or more interestingly of warring spacecraft orbiting a star); as a substitute to fieldwork in understanding how simple rules can give rise to oscillating populations of fish and sharks in a toroidal ocean, or even to reproduce evolution itself through the mutation and selection of simple insect-like biomorphs (Dawkins 1986).

M. C. Escher's Contrast (Order and Chaos), 1950

M. C. Escher's Contrast (Order and Chaos), 1950

At a deeper level, I was fascinated by the power-through-simplicity of algorithms---I would discover the great abstractions of mathematics only later, through James Newman's "World of Mathematics." It seemed to me that by programming I could create perfect little crystals that would then spring into life and display complex, unpredictable behavior. (Even if some of the unpredictability surely must have arisen from my immature programming skills, but still.) It seemed to me that by programming I could play with the very rules and constituents of the mathematical Universe.

A few decades later, I look back and contemplate how computation has been an important theme throughout my training and career as a theoretical physicist, and that a lot of my effort and motivation must have come from the desire of recreating that early fascination. However, it is unfortunately the case that scientific programming, as practiced by researchers in the early 21st century, can be a discomfiting, tiresome activity. We're plagued by restrictive and arbitrary programming environments; unreadable and undocumented legacy code; unmaintainable and temperamental home-grown tools; and above all by a culture of sloppiness and approximation, fed by the poor community recognition of virtuous programming, and enabled by the custom of not requiring scientific code to be published alongside formulas and experimental results. Needless to say, all of this hurts the young awed programmer that lives inside me.

We can – and we must – do better! I wrote this book to show you that there are simple changes that you can make today that will minimize our frustration, maximize our enjoyment, and improve the accuracy and reliability of our scientific results. (If you're now at the beginning of your career, so much the better! You will never have to suffer what we did.) There is no magic recipe, of course, but we can achieve a lot:

  • by choosing our tools carefully, without running after the latest fad, but valuing robustness and good design;
  • by practicing mindful (I will not say "zen-like") programming, as enabled by modern, expressive languages such as Python, and their ecosystems (think communities and libraries);
  • by seeking beauty and elegance at every step, as a cure to complexity and obscurity.

This is not an introduction to programming, or even to basic computing skills, for which you should go to the excellent Software Carpentry, although we will touch on both. Instead, the point of this book is to make you reflect about the most expedient and transparent way to turn scientific ideas and constructs into code; to make you design (rather than grow or cobble together) your scientific applications; and to always make you understand your choices and be responsible for them. To this end, I will eschew canned recipes and insist on the basic concepts—it's my version of giving you a fishing pole rather than a (canned) fish.

(COMPLETE: more about the structure and content of the book.)

This book grew out of my experiences and wanderings in computational science, but more concretely out of a series of computational salons (aut delectare aut prodesse) held in 2012 within the theoretical astrophysics laboratory (Tapir) at the California Institute of Technology. I am indebted to my colleagues there for their patience, insight, and suggestions.

Chapter bibliography

Dawkins, Richard. 1986. The Blind Watchmaker. Norton and co.

Gleick, J. 1992. Genius: The Life and Science of Richard Feynman. Random House.