
Simon Peyton Jones 
284
bugs. So for me I suppose beautiful code is code that is obviously right. It’s 
kind of limpidly transparent. 
Seibel: What about those little jewels of code that you almost have to 
puzzle out how they work but once you do, it’s amazing. Are those also 
beautiful?
Peyton Jones: Sometimes to say that it’s obviously right doesn’t mean that 
you can see that it’s right without any mental scaffolding. It may be that you 
need to be told an insight to figure out why it’s right. If you look at the code 
for an AVL tree, if you didn’t know what it was trying to achieve, you really 
wouldn’t have a clue why those rotations were taking place. But once you 
know the invariant that it’s maintaining, you can see, ah, if we maintain that 
invariant then we’ll get log lookup time. And then you look at each line of 
code and you say, “Ah, yes, it maintains the invariant.” So the invariant is the 
thing that gave you the insight to say, “Oh, it’s obviously right.” 
I agree completely that just looking at the bare code may not be enough. 
And it’s not a characteristic, I think, of beautiful code, that you should be 
able to just look at the bare code and see why it’s right. You may need to 
be told why. But after you have that, now with that viewpoint, that 
invariant, that understanding of what’s going on, you can see, oh yeah, that’s 
right. 
Seibel: Does that put an upper bound on how big a piece of software can 
be and still be beautiful? 
Peyton Jones: I don’t know if it’s a bound on its size. The insights that you 
need in order to reassure yourself that it’s right, or at least right-ish, are 
along the lines of being more confident that it’s correct. Any really, really big 
piece of software is bound to have shortcomings or indeed outright things 
that you just know are wrong with it. But it’s not economic to fix them at 
the moment. It’s certainly true of GHC and it’s definitely true of Microsoft’s 
software.
But what makes big software manageable is having some global invariants or 
big-picture statements about what it’s supposed to do and what things are 
supposed to be true. So, to take GHC as another example, having this 
invariant that each of these intermediate programs should be well typed.