 What I want to talk about tonight is cool code. It's the kind of the observation that coding has a history and we are very bad at history in software development. We don't pay enough attention to it. We're also very bad at recognizing that there's kind of a vast work of literature in software by which I mean the code. There are lots of examples that we can learn from, lots of examples that amuse us, and we're not very good at collecting this and treating that as a community. So I'll start off with this little book that I edited. 97 Things Every Program Should Know. This is the Japanese translation, which I love dearly. I can't read it, but I love it dearly. Because the quality of production is fantastic. I remember my publisher saying, oh yeah, you've got to wait for the Japanese edition because it's so well produced. Quality of paper, different templates. It even has a dust cover. If you're going to kill trees, this is a great way to do it. Now in the preface I wrote, and I've conveniently translated it back into English for your benefit, but there is an art, craft and science to programming that extends far beyond the program. The act of programming marries the discrete world of computers with the fluid world of human affairs, which puts programmers in a rather curious position of mediating between the kind of the negotiated and uncertain truths that we find in the world of business and the very crisp uncompromising domain of bits and bytes and our constructed types. This is one of the challenges in software development. It's not so much just the code, and it's not so much just the humans. It's the fact that the very act of programming has to bridge these. That is one of the things that each one of its own is hard enough, but to try and bridge that is a challenge. It's also quite exciting. Now, when I say art, it's worth clarifying that software developers are the greatest producers of installation art on this planet. This is one of my favourite pieces from Copenhagen Airport about three years ago. I like the shade of blue. I think it's quite exciting. I also like the extended and rotated landscape. I think it's provocative. I think it says something about the post-modern condition. I was disappointed that when I returned back through Copenhagen Airport on that visit, they had replaced it with some advertising. But, you know, we do produce the largest amount and greatest amount of installation art. Now, Kariana Berg, in 97 Things, wrote a little piece, Read Code. And she observed, we programmers are weird creatures. You know what? I was prepared to accept this article just on the first sentence. But Read On. We love writing code, but when it comes to reading it, we usually shy away. After all, writing code is so much more fun and reading code is hard. And other people's code, particularly. We have a name for other people's code. It's called Legacy. But to be fair, not necessarily because other people's code is bad, but because they probably think and solve problems in a different way than you. But did you ever consider that reading someone else's code could improve your own? A lot of the time, people are thinking other people's code on my project. What I'm inviting you to do is think other people's code outside of your project and outside of anything that is directly relevant to what you're doing. Now, it is important to understand that you can't just read any old code and expect to learn from it. Well, maybe we can learn things, but not necessarily good things. Okay, let's just clarify what this is. Hello World. I love the fact that it is dignified as a Hello World app. All the rest is copyright. The copyright message. These are your rights and conditions. This is absolutely ridiculous. So let us clarify what we mean by cool code. The comment is great. It's great and magnificent in a negative sense. If you ever were... Remember, you should comment your code. Are you so sure? So we can learn something from it, but perhaps not the lesson that was intended. Here is how to do Hello World. We want code that is cool. I think we're reasonably okay with code. A system of words, figures or symbols used to represent other set of instructions for a computer. More importantly and more challenging, a set of conventions or principles governing behavior activity in a particular domain. We have codes of practice, spoken and unspoken, within teams, beyond teams and across a profession. A collection of writings. A code is a collection of writings, often referred to as a codex, but historically a code. But what do we mean by cool? Fashionably attractive or impressive. That sounds good. I want that in my code. Excellent. Used to express acceptance or agreement. I've got a tween age sum. I'm hearing a lot of that these days. I show him something cool. In fact, I email him YouTube links and pages, and I get these one-word replies. Cool. And cool includes an exclamation mark. It's not cool exclamation mark. I'm pretty sure the way he says it and thinks it is cool, including the exclamation mark. Used as an intensive. Yeah, he uses that one as well. And then there's the other one used when a conversation goes silent. Cool. Marked by deliberate effrontery or lack of due respect or discretion. I like the sound of that. We're going to look at some examples that fit that. I'm restrained or relaxed in style. I think we need to balance things out. So let's look at this. This was described as the greatest program ever written by a games program. It's a day as frogly. He blogged about it about 10 years ago. And it was written in 1983 by Jack called David Hall. This is Z80 assembler. It was for a ZX81, which was in the UK, one of the key home computers to really change the face of computing from the kind of hobbyist perspective. It made computing accessible or programming accessible. What is impressive about this? This is a game of chess. What is impressive about this, where it's part of the game of chess, there's actually another screen of this, is that the ZX81 out of the box comes with 1K of memory. I remember my older boy asking me what a kilobyte was. And I said, you know, it's like a thousandth of a megabyte. You know what a megabyte is? Yeah, it's a thousandth of a megabyte. What's the point of that, Dad? That doesn't make any sense. How can you have something so little? But you don't even get the full 1024 bytes because there's a runtime. This takes 672 bytes. That's 4.8 tweets. Can you describe chess in 4.8 tweets? I don't think so. This allows you to play the computer. It allows the computer to play you. And it recognizes a win or a draw. Somebody clearly didn't tell David Hallman this was not possible. Had they told him it was not possible, he might not have done it. This is quite profound. In that sense, we might say, well, you know, we don't have this problem anymore. Yes, we do. We're human. When somebody says we offer you this much bandwidth, we take it. When somebody says we give you this much memory, you have this much, now we have this much. Oh, but we now need this much. It will never be enough. We confront things, little things that it turns out that we can't change. Little things like, oh, I don't know, the speed of light. We had a go at trying to change that a couple of years ago, but neutrinos turned out to be surprisingly and boringly subluminal in their speed. So we don't get to change. There are certain things we are not going to change. Bandwidth is we're going to hit a wall. We've hit a wall with clock cycles. We're trying all kinds of other things, but we ultimately hit various walls. Whenever we think we've got enough, we will always want more. Now, while we're on the subject of assembler, this is quite a historic piece of code. This is some of the code for the lunar landing module, Apollo 11, the lunar landing module. It's available on Google Code. They released it on the 40th anniversary of the first lunar landing in July 1969. And this is really interesting. It's revealing in many, many ways. So we're talking about kind of slow clock speeds. The computer on the lunar lander, let me think, it was, get ready for the fast clock speed, around 40 kilohertz. So that's 0.0004 gigahertz to give you a sort of a real sense of comparison. 36K of memory, based on 14-bit words. Yeah, you can't port Java to it. And the code was written in a thing called MAC, MAC, the MIT Algebraic Compiler. The code was written in MAC, and it was compiled down to assembler by hand. So next time you're kind of complaining about, you know, God, this compiler's a bit slow. Well, the incremental compilation is not keeping up with my lightning typing. I want you to think back, hand-compiled. It's also why the comments are so good. But it was hand-compiled, and then hand-punched into another system. Hand-compiled, wow. But it does, there are some great comments here. You can't quite see it, but around the middle of the screen, there's a little thing there that says, temporary, I hope, hope, hope. It also turns out that there was a little bug in the system. But it wasn't really revealed until a little bit later, because it was counteracted by another bug. It's one of those terrible cases of a sympathetic bug. And it was to do with the throttle and latency in the hardware, which got fixed. But there was a bug in the code that actually allowed the whole thing to work. Neil Armstrong replied, that it's a little bit shaky on the way down. We tend to remember, if you follow things like spaceflight and the history of spaceflight, Apollo 11's landing, the Eagle's landing on the moon, was fairly dramatic. Neil Armstrong switched to manual when he realized that the original landing site was inappropriate, would not be good for the lander. So he switched to manual and moved over. Landed with something like 30 seconds of fuel left. The whole thing could have just gone completely pear-shaped at that point. But the funny thing is, it could have been much worse. It could have actually been something far more disastrous. Apollo 12 flew with the same bug. They fixed it for Apollo 13, but they had other issues with that. Actually, if you've ever seen the film of Apollo 13, I read there's a beautiful thing. They tend to do screenings against sample audiences to get a feeling for the film. What's it like? One guy actually commented, this is such a ridiculous Hollywood ending. Had this happened for real, the astronauts would have died in space. They'd never have made it back to Earth. Again, maybe it's not just software developers that aren't very good with their history. We also have other examples a little closer to home. Things that have had a profound effect on the way that we work. This is something that has direct relevance in the world of test-driven development. This is an early draft of J-Moc. I got Nat Price to send me the coat, and this is kind of the beating heart. Obviously, there's an awful lot more to it, but this is the essence. This is what makes the whole thing tick. He made a comment. He kind of laments a little bit the loss of simplicity that has happened as J-Moc has grown, but there's a simple beating heart. It's interesting because there's a couple of things here that are stylistically not regular Java, but the thing that I love most is something you don't see enough. It's over there. He respects the fact that humans can't scan more than about 60 columns. 80 columns is the upper limit of what you can scan properly. And yes, when you write 120 column line, it's not readable. So whenever I go hard on the 80 columns, people think I'm being really retro. I am being retro because I'm human. We have not had a chance to evolve to deal with wide-screen capacities. I would like you, if you're working for a web company, to go to the people who prepare the content and go to the web designers and you know what? I think all the columns on the front page should be 120-plus characters. They will march you out of the room. And if you're in the same team, they'll say we don't want to be on the same team as them because they're stupid. Humans have a particular way of reading and it turns out it's not the way programmers think. Anyway, while we're talking about test-driven development, here's another one. It's an early version of JUnit 3. I'm still trying to get out of Kent Beck some of the JUnit 2 code. But again, this is the beating heart. Without this, there is nothing else. And yet it's surprisingly simple. There's a certain simplicity and elegance to it. It's not hard to produce a testing framework. It's just presumptuous to do so. And this was very presumptuous at the time. And this is really important. It's changed things. Whilst we're on the subject of small pieces of code and whilst we're talking about Kent Beck, programming buddy, Ward Cunningham, wrote a little thing in 1995 in Pearl of all things. Pearl, as a friend described to me and I'm fond of repeating, executable line noise. This is 200 lines of executable line noise. I've shown the top and the tail. It's the first wiki. That's kind of important. I can't impress my kids with anything else. And the people that I might know in software development they're unimpressed until you say, oh, yeah, Dad knows the guy that invented the wiki. Oh, okay, that's worth talking about, Dad. 200 lines. It's a beautiful example of what Dick Gabriel referred to as the worst is better principle. In fact, Dick really got the name wrong on that. It's completely not what it's about. It's nothing to do with something being worse. It is simply a particular way of framing simplicity. Let's just do a first draft, something really simple. It's so simple that if it doesn't work out we can throw it away. Let's just try it out, see what people do with it. Turns out they do a lot. Also, you don't have to make a mess. People often assume that when you're writing Pearl you have to abandon all hope and all style. I mean, I'm presuming that because that's what I see. People often assume that when they're doing web programming and programming either ASPs or JSPs or whatever that they have to abandon all style. Because, you know, it's the web. We do things differently there, not at all. What you see here, and the reason I chose the tail end is that the bit in the middle sets up all of the processing logic in appropriate subroutines. And then at the end we have everything brought together. Very, very simple, very effective. In other words, we can actually understand this top-down design. This is almost a Pascal program in some senses that you can actually describe what's going on. You don't have to write crap just because you're writing Pearl stuff for the web. So, history is filled with little lessons and lots of little pieces of code. This little book came out in 1999, Practice of Programming, T-POP for short. Brian Kernighan and Rob Pike. Two other people who've been busy inventing the future. I think that's for you. Who've been busy inventing the future. I don't have any phone code. I feel I ought to have some phone code. There's a lovely example in this book. I remember reading it, and I flicked over the page and thought, you're kidding, that's it. This is a really stripped-down, simplified version of grep. It covers many of the common cases that people will use regular expressions for. It's really simple. It's embarrassingly simple. And yet, it's also very intricate. To be able to write that kind of thing in that little space is quite profound. It's been for a long time one of my favorite pieces of code. When Brian Kernighan contributed to the beautiful code book from O'Reilly, he chose this piece of code, which made me feel kind of good. It's just like, yes, I can see a classic as well. Rob Pike apparently knocked this one up in an afternoon. Just kind of threw it together. It's a really good example of many things. Idiomatic C. A lot of people kind of program into the language they're working with, rather than programming with it. They don't embrace its idioms. It's really difficult to write this kind of thing in Java. Well, you can do it. It'll be a lot longer, and we call that enterprise code. It's really simple. It takes advantage of some of the things that annoy people in C and actually turns this apparent weakness into a strength. It's also a very good example of mutual recursion, employee examples that people normally deal with. So, profoundly instructive. Now, whilst we're on the subject of recursion, this is really interesting. This is a piece of code that does not compile. It was written by Irvin Unruh, who used to work for the compiler group at Siemens. This is in 1994. He presented it to the C++ Standardization Committee, and this was the beginning of template metaprogramming. If you don't know what template metaprogramming is, well, let's first of all start with templates in C++. Templates are kind of like generics done so that they work. So those of you who work in Java, it's not like that. It's proper. Those of you who work in Csharp, it's still like that. Not like that. It's proper. Templates are profound, and this was the great discovery. Templates are Turing complete. Anything that can be computed can be computed using templates at compile time, and this code does not compile and its error message is the first few prime numbers. That's cool. That's crazy. A program that does not compile and gives you useful output. Template metaprogramming is a technique that C++ programmers use to preserve their jobs. Nobody will understand that you can't get rid of them because it's just like, what does this do? I love this example. Adam Patterson and he used a template metaprogramming library which is very much like functional programming at compile time to program the common Carter and challenge of fizzbuzz. Now, if you Google for fizzbuzz you will find two different categories of entry. There are those entries that say fizzbuzz is a drinking game and there are those entries that say it's a kids game. So I'm kind of intrigued. I often like to note that there's not a lot of difference between adults and children but I'm not entirely sure what the children do as a forfeit because the idea is you go around the table feel free to try this later you go around the table one, two, fizz every time you hit a multiple of three you say fizz four, buzz every time you hit a multiple of five you say buzz fizz, seven, eight when you hit a multiple of both three and five in other words, fifteen you go fizzbuzz if at any point you get this wrong you have to down a drink and if we're talking alcoholic drinks I mean I don't know, do kids drink more water more milk or something I'm not entirely sure what the forfeit is because with the adult version of the game it all goes downhill for some reason this has been embraced as a coding cutter in the craftsmanship community and this program doesn't compile either and it's error message there you go one, two, fizz four, buzz, fizz seven, eight, fizz, buzz eleven, fizz, thirteen, fourteen, fizz, buzz are your error messages this exciting? are they computationally complete? there you go it's also an example of functional programming which I think is a kind of a curious side effect so here's another implementation this is fizzbuzz now if you know the answer to this I want you to keep quiet if you already know where this comes from shhh I want everybody else, guess the language this, that's got a bad Ada, not a bad guess I've got some Ada in my slides tomorrow no scheme, another good guess we've got some scheme later Ruby you didn't see that coming this is done by Tom Stewart who has a book out later this year, Understanding Computation you can find this article which will be in the book as a chapter it's called Programming with Nothing what he decided to do was to restrain his use of language features he would program he would do fizzbuzz and he would program it without using numbers and without using Boolean logic and without using conditional statements in fact without Ruby he only allowed himself two things the ability to define a lambda that took one argument and the ability to call the lambda if you have a background in mathematics or computer science theory this is basically church numerals in other words what you're doing is you're defining a number system by certain operations it's related to the idea of defining the natural numbers based on sets for example you pick an empty set then that represents zero if I pick a set that has the empty set that's got one thing in it number one if I take a set that has that and so on I can create the number two so in other words we can define a natural number system he goes a step further and does this with lambdas he recreates control structures he gains up one other luxury which is also to allow himself to define constants so that he could write it this this short if you expand it from the constants it looks like this and you can see that there's not a lot of anything but defining defining lambdas passing things to them given that it's supposed to do the numbers from one to a hundred just to let you know that's a hundred yeah I strongly encourage you to read the article it's absolutely fascinating slightly mind bending, slightly mad but nonetheless a great deal of insight I did say there'd be some lisp this was a list 1.5 it's written in the early 60s you can find the pdf of this online but I guess I quite like old books so I went and spent good money on getting my own copy it's really quite inspiring because it's very it's particularly readable as well for a book written in the early 60s by a bunch of academics it doesn't simply tell you how to implement lisp the book as you go through if you're bored one afternoon try it it's really quite profound it shows you the inner workings it's one of these examples of don't simply understand how to drive the car understand how to take the car apart and put it back together again and lisp has been a source of inspiration for many programmers and exasperation for many others but it has some really profound ideas one of them was metacircularity the idea of defining a language in itself this is an idea that is fundamental to many of the tools that we deal with the idea of self-hosting systems lisp was written was defined initially in lisp but you don't have to translate it hand translate it into the appropriate implementation but we find the idea elsewhere linux is built and hosted on linux junit is self-tested using junit and so on you have the idea of cross-compilers the first time you encounter cross-compilers how can a c-compiler compile a c-program that is the c-compiler for another platform how does that work I try and explain this to my older boy on the way to school one day I'm not entirely sure it worked out but it is a profound idea this metacircularity is quite profound the point that we see this this is taken from structure interpretation of computer programs which uses scheme and similar idea the idea of the eval procedure here is a simple way of defining scheme written in scheme Alan Kay, inventor of small talk once described this kind of approach Maxwell's equations for computer science the original version of small talk was written with small talk defined in small talk Dan Ingalls went and implemented it in 1972 he went and implemented it at home I need you to think about that here we have somebody implementing something at home in 1972 didn't have home computers back then so he would have been on a time-sharing terminal that he had access to what was the language that was designed for time-sharing systems for people to be able to program this is a real test of your history 1960s begins with B ends in ASIC you see, you're sharp you're sharp, I can't get one past you basic it turns out the original version of small talk the purest of the pure was written in basic yeah that upsets some small talkers when they find out but it is profound, we see this reflected in this example from Peter Norvig the director of research at Google he decided to have a go at writing a really simple version of Lisp so in 90 lines or 91 lines it's called Lispy, he wrote it in Python and there we see the eval function and we also see the main rappel the main interpreting loop and it's there but there's your eval I think it's an interesting side note that he said, yes I tried implementing it in Java it took 1400 lines which is why there are more jobs than some programmers let's move away from Java to a thing that is characteristically not Java except for its first four letters JavaScript this is the basic of the 21st century this is what kids are using and messing about with not when they're actually being taught to program they use more sensible languages then but when they want to try and get something done and they're hacking away instead of hacking away in assembly they're hacking away in JavaScript any application that can be written in JavaScript will eventually be written in JavaScript and this is kind of a there is kind of an interesting observation, now I realize I don't have an internet connection in this room so I'm kind of glad that I it wasn't a very good connection but here's one I prepared earlier this is it was developed by Fabrice Bellard it is basically an Intel interpreter in JavaScript upon which he has layered a small installation of Red Hat Linux so this is Linux running on a JavaScript chip within my Chrome environment on Windows 8 now I can't actually see this because I'm running an extended desktop so please forgive any mistakes that I make and there we go we've got stuff there's a Hello World program see it all fits together there's talk about this program now I'm going to edit this program because I'm a little I'm a little concerned about the punctuation there you go should have a comma if you're not sure why just consider the following two sentences let's eat Grandma let's eat Grandma yeah one of them has a comma the other has cannibalism so it saves lives okay now I'm going to compile it this is going to be kind of slow you know oh that's actually quicker than I expected yes we have achieved programmingness alright now there's other things we could do it appears we're already running enough operating systems this is getting a little bit like Inception okay yeah there we go that was unexpected it does normally run however that does reflect my own personal feelings on Emacs it wasn't me that did it it was the run time right now we're going to get that one back let's kill that in the background let me just bring that out for a moment yeah that's going to be interesting you say we have a signal in here let's actually find yeah that's kind of annoying ah there we go that's interesting I had not run Emacs like that before let's just try and connect up what's the login is airtel demo isn't it this doesn't like it that's annoying what's the ballroom one do airtel demo br yeah okay let's try that one and that's still okay let's try running that don't worry let's go somewhere there you go so that's Emacs for you let's try that so I've got another version excellent there you go that's the boot up sequence welcome to you so let's have a look at something else because if you are careful you will have noticed that there is also a DOS directory in the DOS directory LA no I don't think I wanted that one try and bring that one home and this is really not happy today don't run Emacs it's the moral of the story yeah whatever right so that's the example we've got there I'd like to present you with another piece of art this is the 1989 winner in the best layout category for the international obfuscated C code in contest it calculates E which is kind of interesting kind of provocative if you actually want to calculate Pi you need to use this program which is the winner of the 1988 best layout category this one calculates Pi to 2 decimal places by measuring its own surface area which is kind of cool now whilst on the subject of globes here we can get that this is one of the most profound examples this is known as the club it was written by Yusuke Endo in 2010 and when you execute it it rotates the world through 45 degrees I'm wary of doing anything live with code at this point because I've just been disconnected from the ballroom you know what I did actually upload the video earlier so let's just see if it's still in the buffer I'm suspecting the answer is no sadly let's try and reconnect that's really very frustrating air tail disconnect air tail connect automatically let's try that yeah that's unfortunate an error code yes what could possibly go wrong exactly what we expected would go wrong however I did find conveniently enough the original page when you execute it it produces the logo rotated through 45 degrees when you execute the code from that it rotates it a further 45 degrees and so on you can actually specify the number of degrees you wish it to rotate on the command line so you can rotate it by one degree at a time this is a coin it's a multi coin a program that produces itself as its own output or a variant of itself such that it eventually gets back to the original now I think one of the things that's most interesting about this one is the comments this is awe inspiring thank you you are a madman you are completely insane very very impressive wow my favorite one though do you accept worshipers it really is a masterpiece so yeah that's kind of one of the more certainly one of the more provocative and profound examples now let's just see if we can find a window that actually works yeah this is going to be interesting let's just see if we can find a shell that works MinGW shell right this is going to be interesting because I was going to use JS Linux to do this however that's not working out so well for us so I'm going to do something else let's see the next piece of code is a very interesting piece of code let's see if we can get that we don't know who wrote it they posted anonymously let's just do this let's but it does something rather interesting if I'm really lucky this will actually work I'll just pull this shell up I put up a simpler version of the script that doesn't use a function basically if we execute this oops I can't see what I'm typing there script I'm really lucky this will actually work okay so what's this code doing now what's it doing you're telling me how it's doing it damn it why do programmers always do that I don't want to know how it does it I can see how it does it it's sorting it yes ladies and gentlemen this is sleep sort as I said we don't know who created it but we do know when it was created man am I a genius check out the sorting algorithm I just invented so anonymous we don't know the beginning of 2011 I think the first comment after this oh god it works this is a supremely cool code it's possibly one of the least efficient ways of sorting it's not the least efficient way of sorting however I think what is interesting for the algorithmic geeks amongst you is to work out what the computational complexity of this is it's linear yes we have a linear sorting algorithm that's pretty cool but it doesn't so tell us that maybe the complexity is not the only thing we care about when we're dealing with algorithms it's instructive in that sense it's certainly better in this sense than what's known as Bogo sort Bogo sort is where you take a sequence of numbers and you randomly shuffle it and you check whether or not it's sorted if it's not sorted, repeat until it's sorted so this is a little better than that a little more ingenious and actually there is something again here that is subtly profound because this is the basis of many distributed algorithms this idea of just fork out lots of different processes and you harvest the values back together again although it has some terrible performance worse cases there's something in here that is quite sort of insightful so not content with demos that don't work this is one of my favorite regular expressions now normally when people deal with regular expressions basically people describe this as oh yeah I had a problem and then I used a regular expression now I have two problems this one's kind of interesting because this works in Ruby it works in Perl if I put this in if I'm really lucky this will work what does that do see it's all about primes and pi tonight primes this calculates in unary forget binary, unary, base one whether or not a number is a prime number without this without any loops relying on a backtracking property of some regular expression matches because if you can match a multiple of something then it's not a prime because you can divide it if you can't match it then it must be a prime it may be the least efficient way to calculate primes but it's certainly one of the most ingenious if you tell somebody oh yeah there's a regular expression that matches primes you can initially think of something like huge and monstrous but it turns out it's smaller monstrous instead now whilst we're on the subject of prime numbers the let's see if we can get let's see if we can get that one this is what is known as an illegal prime Phil Carmody in 2001 found a prime number this is over a thousand digits long found a prime number that when expressed in hexadecimal and where the hex represents byte values or pairs each hex value represents a nibble then that corresponds to a g-zipped version of a c-program that when unzipped allows you to crack dvd encryption which is why it is known as an illegal prime because you're not supposed to be able to crack that and certainly if you do you're not supposed to tell anybody about it hence it is illegal so this is one of the more interesting numbers there's a whole load of illegal primes as well there are actually so this one you actually have to g-unzip and then compile there is actually a larger illegal prime that is the executable code that when you write it to file and execute it it will crack it and then compile it or decompress it obviously it's slightly platform specific but I'm not going to hold that against it so you end up with these kind of like really crazy examples this is a really interesting one from Alexei Shveshnikov it's a one line web server now of course some of the heavy lifting is done by other applications but you can see there's your 404 message your protocol HTTP 1.0 you've got all the bits and pieces there and there's 200 ok I don't really recommend that you go back on Monday and say to hell with Apache forget internet forget the IAS stuff we're just going to go for this I think it might have some security issues but this kind of compression is quite a profound idea there's lots of really small examples from which we can learn a great deal practical in the sense of you can quickly get on a closed network a very simple web server up and running you can probably even get it running on that version of JS Linux if only it would run so a lot of this interesting enough comes back to some things on a lot of the ideas come out of Unix originally this is the Lyons book the John Lyons, the late John Lyons of the University of New South Wales he put this together in the 1970s because he wanted to teach an operating systems course but he wanted to use a real operating system and around that time AT&T were basically made the source to Unix available and so he wrote a complete commentary on the operating system so he basically published the code with a commentary there's only about 10,000 Lyons in the kernel of the 6th edition of Unix I just want you to think about that for a moment and think about your current project you can get an operating system for 10,000 Lyons what's your project doing? I've seen classes that are longer than that okay, they scare me so when somebody says, yeah it needs to be this so what are you doing, we're taking data from here and putting it there you used to be able to buy an operating system for that for free it's a very geeky thing to have as you can see it was passed around by Samizdat basically people photocopied this stuff for those of you who are too young to remember what a photocopier is it's like a scanner but more expensive and more social if you're at a university you spend quality time hanging around by the photocopier hoping to meet interesting people failing some of the people on your own course you sit there photocopying large tracts of stuff so, yeah we've lost out something on the sociability side there but you do end up with students it used to be the case that students would make very careful cost-benefit analyses of this I remember at uni when one guy decided that he would photocopy Kearling and Richie the C programming language because it was 10% cheaper than buying the book which also shows you that the whole thing about time is money no, not when you're a student so I put the kind of retro lightsabers in there these are my kids' lightsabers they're not real sadly but there's also something else here again, educational from a paper in the early 70s from the late Dennis Richie in can Thompson they made an observation that I think is as true today as it ever has been there have always been fairly severe size constraints on the Unix operating system and its software given the partially antagonistic desires for reasonable efficiency and expressive power the size constraint has encouraged not only economy but a certain elegance of design without that constraint it's likely you would not have had many of the design decisions indeed Unix was born out of the ashes of the Maltix project which was fairly unconstrained and that lack of constraint was an issue you need to be working against a constraint to really find the concepts now again everything has a long history one of the most interesting things about the Unix command line that is spread through to other command line systems is the functional programming model that you get on the command line a lot of people aren't aware of it as being a functional programming model but pipeline architectures are basically data flow architectures they are relatively stateless the state is affected only at the end of the pipeline and this idea of the pipeline is a really interesting one and it has a prehistory Doug McElroy and this paper there's all this memo from 1964 makes the observation we should have some ways of coupling programs like garden hoses screw in another segment when it becomes necessary to massage data in another way and this is the way of IO also in other words a unified model for processing and communication and this garden hose metaphor seen in 1964 it's worth kind of going back to 1964 and thinking what they had because they didn't there really wasn't an awful lot of computing around and this was far sighted a couple of other things here they're interesting our loader should be able to do stuff yeah fine our library system et cetera and then I love the technical jargon in this it should be possible to get private system components for buggering around with just to you know that's it because that's what we're going to do we're going to mess it out with this stuff now sometime after seeing this I found another little discussion that went back on the history while Thompson and Richie were laying out a file system McElroy was sketching out how to do data processing by connecting together cascades of processes and he was looking for a kind of prefix notation do not underestimate the power of notation the Nobel physicist Richard Feynman once observed that the history of mathematics is the history of notation when you are able to grasp an idea and you have a notation for it it becomes thinking and expressing that idea that becomes simpler never underestimate the importance of notation a lot of programmers do a lot of programming language designers do notation matters and basically they pre-varicated so spent a couple of years trying to come up with this and Ken Thompson who is very much a doer said I'm going to do this we're messing about with this for so long and he basically put pipes into Unix and overnight there was a change originally all of these features all of these simple tools had command line arguments but suddenly you ended up with this pipeline model and in the way that programmers will rush in to fill a void the next morning we had this orgy of one liners everybody had a one liner and that started the Unix philosophy that started this whole compositional approach otherwise it would have merely been something another kind of VMS style system so it wasn't just a slightly good idea it actually transformed a little piece of notation the pipe sometimes difficult to find on some keyboards easier these days but it used to be quite hard and normally jumps around based on your nationalization features which are very frustrating having tried to use a I remember this company I used to work at we had a job lot of spare Spanish keyboards using an operating system that only had a US mapping while all the rest of our operating systems had UK all the rest of the systems had UK mappings and you're sitting there going like don't look down but where's the pipe can somebody direct me I can't do programming where's the pipe where's the back tick program without these once you figured it out it was good so I'd like to draw this to a close with another little piece of history a very important piece of history is the original announcement take this stuff for granted most of our ability to share information with one another and share code and to basically make available all of this knowledge this history is enabled by this and there's a little piece of code out there which is the worldwide web and I'd just like to close with this observation from the author Stephen King if you don't have time to read you don't have the time or the tools to write I hope that's been interesting thank you