 Hi everybody, how's my hair? Is it okay? I really liked the lightning talk we saw by Elizabeth earlier today and I did want to point out and prove that this presentation actually has 102 slides that we're gonna cover in 30 minutes. Last year at this time that guy was on stage and he gave a talk about smashing monoliths and I'm really happy that this year I'm back I'm in full color and I'm fucking awesome. Thank you all for the support. Last thing before we get started, I win. So we're captive to the notion of elegance but what do we really mean by elegance? I'm reminded this book that I read when I was a kid called Alice's Adventures in Wonderland and Alice gets in an argument with Humpty Dumpty about what the word glory means and Humpty Dumpty says something that always stuck with me. When I use a word it means exactly what I intended to mean, neither more nor less. It's a question of who's to be master, that's all. So does that mean that when we use the word elegance we can't really define it? That it means something different to every person? Well just so happens that there's an entire science devoted to understanding our appreciation of beauty and elegance and I'd like to share with you some things that I learned about it today. So it's called Aesthetics and we're gonna talk a bit about Aesthetic Theory to start with. Aesthetics is experiential. It's about the experience of beauty and that experience can be sensory in nature through our five senses. It can also be a cognitive appreciation of beauty. There are four main schools of thought when it comes to aesthetics. The first is pluralism. In pluralism it states that every person perceives things in a different way. Every person arrives at their own truth in their own way. A sort of a common example of pluralism is you probably heard someone say what if when we look at something blue and you look at something blue we don't see the same thing. How do we know that blue is really blue? Well that's a pluralist perspective. The second approach is called hybridism. In hybridism we say when we look at something blue you might see it a little differently than I do but we're all seeing basically the same thing so this common experience that we share is sort of truthiness. Then there's absolutism. Absolutism derives from the notion that beauty comes from perfection, from provability. Because the wavelengths of light are vibrating at a particular frequency and hitting our retina at a certain angle we all see the same blue. This school of thought emerged from something called applied aesthetics and its application to computer science is not a new idea that I came up with actually. There's a guy named Ezger Deekstra that we're gonna be talking about a little later who thought a lot about this. Finally there's eclecticism. Eclecticism says it depends. There's not one single way to define what beauty is or a relationship with beauty. It's contextual. So let's say they're multiple paths to the truth essentially. So the effects of our appreciation of beauty can be applied in a very practical way. Consider a structure. Consider a building. A building is designed for a single utility. It's created for materials that have a fixed cost. But if those were the only four attributes we cared about we would build a lot of concrete boxes. Through applied aesthetics, deliberately injecting aesthetic attributes, buildings can be elevated to a new level of perception and experience of beauty and give us a new thing to appreciate as we use the building for the intention for the purpose it was designed for. This makes our interactions more pleasing. So these two buildings both serve a function. They both are important to people. The one on the left has aesthetic characteristics that the one on the right obviously does not. This is Bacon's Castle. It is Virginia's oldest certified brick building. It's in Surrey County where I grew up. It was built in 1665. It got its name from the fact that soldiers during Bacon's rebellion in 1676 stayed there and were garrisoned and it's been perfectly preserved for about 350 years. This is a Soviet era building in the style of brutalism. Brutalism emerged after World War II when nations had to very quickly rebuild their infrastructure and their buildings and their housing so they really had no time for injecting aesthetics at all. Do you think this building is likely to be preserved for 350 years? No. Code is the same way. We don't want to work on legacy code that has a brutal architecture. That's ugly. That's unesthetic. We want to work on small agile nimble apps that interact in pleasing and aesthetically interesting ways. So elegance is an aesthetic experience. It's perfectly conforming to a set of imperfect standards. Elegance and code is a result of a mysterious process that we don't really wrap our heads around very well. Elegance and nature is a result of a mysterious process we call evolution. So it's really important that we define our terms here. So I'm going to briefly divert into evolution. Now, if you grew up in the south like I did, this may not be a refresher course on evolution. This may be your first introduction to the topic. Four main terms I want to cover. Genotypes. Genotypes are the genetic information that code a particular characteristic of an organism. These genetic information is expressed as a phenotype. This is the physical manifestation of genetic information. There's the concept of natural selection. In natural selection, characteristics that express themselves and have an influence on reproduction of an organism and therefore determine which characteristics become dominant or not dominant in a population. And the sort of canonical example of this is the moth. Moths like to sit on tree trunks and they like to blend in with tree trunks so they don't get eaten very often or very easily. So during the industrial revolution, when factories suddenly started cranking out lots of soot, light colored moths became easier prey for predators and dark colored moths survived more. So the population actually shifted to darker colors. So even though this was a human intervention, it was an environmental effect that had an influence on how genotypes were expressed as phenotypes. And finally there's artificial selection. This is when we deliberately breed for certain characteristics. So can aesthetics be a factor in evolution? I want to tell you the story about John Chapman. He's better known as Johnny Appleseed. He lived in the 1700s. He famously wore a shirt made out of a coffee sack. He traveled with a Bible and bushels and bushels of Apple seeds. It's important to understand that in the 1700s, the notion of sweetness, the concept of sweetness was very unique and sweetness was actually a luxury. Sugar was not plentiful in the New World and there were no honeybees except the ones that were imported from Europe. So the average person only got sweetness from rare fruit. And you see in stories like of Christmases in the 1800s, kids get an orange and they're excited. That's because fruit was really rare. It was hard to preserve. So when we think of fruit, we think of apples. We think of apples. We think of a red delicious, perhaps. Little known fact about apples. Most of them have about five seeds inside. If you took a red delicious apple and it's five seeds and planted them, you would not get five red delicious apple trees. You would get five different varieties of apple tree, none of which probably produced edible fruit. This is the kind of apple that you get when you plant apples from seed. Not very delicious. Just sour and soft. Now I said that John Chapman and Johnny Appleseed went across the country planting apple seeds. So was he stupid? No. He was actually pretty smart. He would go to where settlers were going to be, plant apple orchards and then turn around and sell them when the settlers actually arrived. But he was selling them apples like that, which are really great for making hard cider. Hard cider preserves much better than fresh fruit does and added bonus. It gets you drunk. How awesome is that? Right? So these ugly orchards were really, really valuable. They were an investment. But then in the 1830s, there was this movement called temperance. People decided that alcohol was evil. And apples as a source of hard cider were part of that evil. That goes back to the Bible, right? So apple orchards were in danger of losing their value. So the apple growers came up with a great concept that we actually hear today. It's apple grower propaganda from the 1800s. And apple a day keeps the doctor away. The health benefits of apples were pretty much invented in the 1800s and propagated as an idea to preserve those apple orchards, which were quickly reconfigured to produce edible apples as opposed to cider apples. So the genetic expression of apples over the last 300 years has been in response to our aesthetic demands. We didn't care about how shiny, how red, how perfect looking it was. We cared about its alcoholic qualities and its sweetness. And later we came to value those other visual aesthetic characteristics. And we got apples like we recognize today. So what do we guide evolutionary changes through deliberate crossbreeding? Or by environmental effects? Our aesthetic preferences are having an effect on the world around us and how it expresses itself. So is aesthetics an integral part of evolution? Or is it something that we just impose? There was a book that came out maybe 20 years ago called the selfish gene, which asked the question, what do genes want? The idea actually came from a man called George Williams who wrote this book. He posited that since genetic expressions are essentially competing for attention, competing for survival in the world, that it was more useful to look at evolution from the perspective of a gene than the perspective of a species. One of the interesting things that came out of this is the green beard effect. With the green beard effect, it posits that if there were a gene that created green beards and men, and the tendency for men with green beards to treat other men with green beards nicely, this would be a way that the green beard gene expressed itself, self-recognized itself and benefited itself without really any impact on the survival of an individual organism or of a species at large. So in Ruby, we have in our world here, we have the green beard effect. Our green beard effect means that when we write Ruby code, we look for other Ruby code that we use. We look for libraries and apps that are in the language that we are familiar with. We build entire communities around our language. Technology wins in this scenario just like we do. It's a symbiotic relationship. But if we look at it from the perspective of the code, code is playing a very different game than we are. So let's ask ourselves what does code want? First, it wants ubiquity. Code wants to be everywhere. It wants to be in every device, in every aspect of our lives. It wants to be universally applied to every problem. Think of the API paradigm. It's been around for years and years and years. The genotype has been consistent. The expression of that genotype as an actual physical API is the only thing that's changed from RPC to XML to JSON. Code will do anything in its power to live as long as possible. Think of Unix. Unix is probably the most successful program ever written. It's because of its modular nature and how flexible it is in adapting to new protocols and new technologies. So how does code get what it wants from us? It starts by being flexible. Flexible languages are long lived, and that means that they encourage specialization. Specialization means we don't want to change languages very frequently. Languages are extensible. They adapt to new protocols, new methodologies. We don't have to learn a new language when a new version of Agile emerges. Languages have to be novel to keep us constantly engaged. They have to bring new things to our attention, otherwise the bright shiny of Haskell will draw us away from Ruby. And finally, on a darker note, technologies survive by being entrenched. Think of IE6. The reason IE6 lives so long is that a lot of intranets were built to support IE6 features. The Microsoft technologies were so entrenched that they were too expensive to remove. This is like a gambler who's lost $1,000 and keeps gambling because of the fallacy of sunk money. My luck has got to change. I've got so much invested in this, I can't afford to change it. Is it fair to compare evolution in the natural world to programming languages and technology? I think that underlying languages are like the genotype. They contain the universe of possibilities of the way that ideas of the language can be expressed. And therefore the applications that we write are the phenotypes. These are the physical expressions of the language. They're environmental pressures that bring about natural selection. How fast is it? Does it operate on the hardware that's popular? Does it compete well with other technologies? These are forces in the natural world of a technology of a language. And then there's refactoring with our own code, a cycle of attention from when code is first conceived to when it's written to when it's refactored is a generation. And iterations of a language are like generations as well. By being actively maintained, it's like cross breeding for traits that we want. Can we measure the aesthetics of languages? There are five ways that we interact with a language. The first is a user interface. This is where most people interact with a language, the UI that's built using that language. As developers, we have a few other ways that we interact as well. Through the API, through the way that the language is actually constructed, the objects and methods that are available to us, the underlying paradigm of the language, the command line, the way we interact with executables in the language, the documentation that we read, is it clear or not clear? And the readability of the code. Is it easy for a developer to parse and understand? So in September, I ran a very I'm a college dropout. I ran a very unscientific poll about the aesthetics of languages. For those five characteristics, six languages, I asked people to rank each of those characteristics for those languages. And I used the data to plug into an algorithm I designed called the aesthetic index. Python came out to be the most aesthetically pleasing language to its users. Ruby was a very close second. It was a very close second. And I noticed that JavaScript and C Sharper are a very distant third. So Ruby is a language that was designed to make us happy. And I think this chart proves that to some degree, to a very large degree, it succeeds in that realm. And then I wondered, does that really have an influence on how popular a language is? All of the six languages, with the exception of JavaScript that I ran the last year, the ones that are losing the less are at the top. JavaScript is actually gaining probably because it's the only language that we can use client side in a browser currently. But Ruby and Python are losing less than a percent a year. PHP is losing three and a half percent of its developers a year. So there seems to be some sort of relationship between how aesthetically pleasing a language is and how well it's surviving in the wild. So that's languages. Can we also consider the aesthetics of code? And we get into a very dangerous realm here, where we're again trying to define this notion, the slippery notion of elegance. I think there are four characteristics that we can use to measure the aesthetics of code. There may be more, but these are the four that I sort of focused on. The first is correctness. And this sort of ties back to that absolutist perspective on aesthetics, right? Correct code is beautiful code. That's what Ezger Degstra wrote. He believed that programming languages are an extension of applied mathematics and that therefore provability was the measure, the only measure that mattered for the beauty of code. I'm going to tell you a story. A couple of years ago I found this book called Clever Algorithms. I was dabbling in AI again at the time for maybe the third or fourth time in my career. And this book promised to be a catalog of algorithms inspired by nature. Perfect. Natural systems, algorithms expressed in Ruby. Even more perfect. The only way it could be more perfect is if Douglas Hofstadter personally delivered it on the back of a giant raven and dropped it in my lap. I made the mistake of opening the book. I found methods like DRAND1BEN with arguments that were 15 arguments long. Yuck. I found methods like this which go on for 118 lines. Procedural code, no objects at all. Yuck. There are two places where code like this can be considered beautiful regardless of how correct it is. In the eyes of its creator that actually said game over but I said the whole thing on the slide. And in bizarro world. So that's correctness. Correctness alone is not enough to make code beautiful. There's performance. And I consider performance to be a relative thing. Even though we can actually measure it, we can measure how fast our code operates, the experience of performance is a very subjective one. What is fast to one person will be slow to someone else. There's brevity. I was reminded of this great line by blaze Pascal summarized it said I wrote to a long letter because I didn't have time to write to a short one. Brief code, code that embodies brevity is very hard to write, especially when you take into consider readability. Readability is how easy it is for other people to parse the code that you have written. Readability is absolutely subjective. These four measures taken together I think define elegance for me. And I was asked by someone out in the hallway during one of the breaks today. He said it's a shame we can't actually measure elegance. We can't quantify it. I think we can approach it. Using a grid like this with the four characteristics that I talked about as four axes. We can map how readable, how concise, how performant, how correct a piece of code is and strive to make the shape in the graph as large as possible. Why does all this matter? Einstein said that when a certain level of expertise is reached, science and art coalesce in aesthetics and that the greatest scientists are also artists. Consider the world we live in today. Entrepreneurs and technical co-founders. We make deals with the devil. Business people spend time dreaming up applications that they want built. And they engage us to make what are called MVPs, which are most evil products. Their contract signed in blood, the software must be delivered by insert arbitrary date here or the world will collapse. If we don't get another Twitter for Goldfish, we're doomed. What results is really ugly, monolithic, brutalist code that no one wants to work on. We'll fix it in the next iteration. That's a lie. We want to build this. What we end up building is more like that. We've all been there. Or we all will be. I would ask you not to write code for the devil. Ask yourself why we write code. Is it for money? Is it for job security? Or is it because it's something that we would do for free otherwise and getting paid for it is pretty fucking awesome? Creating something out of nothing, solving problems. We like those things. Who do we write the code for? Do we write it for an interpreter? Compiler? Do we write it for stakeholders or users? I would argue that we write code for other developers. The people that will interact with our code later, at the level that really matters, we have to make sure that our code is not only performant, correct, concise, but also readable and understandable. We care about code quality for lots of different reasons. Maintainability and extensibility I talked about. But I think the most important reason we care about quality is that our names are on those commits. We don't want, a year later, some other developer doing git blame, finding our name and cursing us. The code that we write is an expression of ourselves and our capabilities and our intellects. And that's a scary thing. Think about what code you're putting your name on. Is that something you want to be part of your legacy? Aesthetic appeal is a measure of quality. I think it's one of the most important measures of quality to the people who really own the code, who are people like us. Architecture without aesthetics is brutalism. And code without aesthetics is a commodity. I don't think we want to be producing commodity code. Maybe some people are comfortable getting paid to write crappy code. I don't think those people are here today. I don't think those people are very active in the Ruby community. So don't do it. Care about your code. Recognize your code's needs. Respond to them. Create a symbiotic relationship with your code as it evolves. Guide its evolution and evolve yourself in the process. Consider the experience of writing and reading your own code. Is it creating a beautiful experience for someone else? We increasingly prefer to call ourselves craftsmen or artisans. But if we're just cranking out anonymous code for non-technical co-founders, our code is a commodity. This reminds me of a theory that Marx called the theory of alienation, where artisans have control over the process of creating their product. The materials that are used, the techniques that are used, their professional standards, the quality of the finished product. In a factory setting like capitalism produces, we become alienated from the products of our work. Artisans do not work in code factories. Think about that. We have the power to decide the form that our code will take. Code wants to be ubiquitous. It wants to be universal. It's willing to give us flexibility in exchange for our ongoing attention. We can blindly participate in this process, like the moths, allowing certain moths, certain of us to succeed while others fail for reasons we don't fully understand, or we can actively and intentionally engage with this process. We can create experiences of pleasure for ourselves and others. In the end, it's our responsibility to attend to our orchards of code and to produce something that is beautiful and delicious. Go build something beautiful. Thank you.