 This kind of silly talk Apparently somebody is already hoping that all of my slides are in drawn. I can't actually quite battle that because you can see I have some real artistic ability So my talk today is about is about we're binius about poison potion and why and in order for this remote work Okay, so my name is Brian Ford and I have the pleasure of working with Engineer full-time on Revenius pretty pretty awesome job Engineer is quite a cool company in terms of open source. They have sponsored a lot of open source with Revenius with JRuby with rails and other projects like fog which the app for Managing stuff in the cloud and stuff like that. So I want to thank engineer for all the stuff that they're doing but also I want to sort of say that this talk is like you would maybe consider a blog post that I might write that doesn't necessarily reflect the opinions of So we're partially here to talk about this guy how many people in this room know who this guy is So for all you guys that thought this was Jack Black this is not I Thought the same thing. I have a funny story. I'll tell you real time How many people have read wise for the guy to be awesome? How many people sleep with it under their pillow? Okay, so earlier in the conference Dave Thomas was talking to us and he basically gave us like three sort of ideas right one was There basically he's challenging us to go out and inspire somebody he's challenging us to Diversify to do something a little bit different than we're used to doing And he's challenging us to do something new not just following someone else's footsteps But actually do something new and actually maybe do it worse instead of thinking that you're always going to do it better And the reason that I thought that was really interesting is because I think that why in bodies Or embodied in his work and in his interactions with us those those three ideas I think he like really embodied it so Dave Thomas also showed us something here and What I think like for a possible explanation of where why it might actually be now I think he's maybe hiding His head where he's like telling him some stuff Yeah, Dave Thomas the channel why so I Think in my experience with why I'm looking at his projects. I think that why struggle with programming Not that he wasn't a good color. He wrote some pretty pretty awesome stuff They wrote, you know stuff like camping which is pretty interesting way to think about something But I think he struggled with the idea the idea of programming how we interact with programming how we talk to people about programming And how we get people excited about programming And the reason I think that's kind of interesting is because I think a lot of Problems that we see maybe if we think about enterprise software is that we think that we're doing something that is as serious as Launching, you know something like the space shuttle in the space And I think that's false most of our software is not anywhere near that scope And it doesn't need to be anywhere near that serious the consequences of something not working He's not the same as a space shuttle failing to launch There's also this idea that Our software the programs that we write have to be super super good like the quality of them is something like, you know The quality of BMW M3, right? Also, I think false. I think that that is not necessarily the quality of our software I think most of our software is more like this and as for wheels to or whatever you get in it You drag somewhere you get there safely. It's not like this thing is going to fall apart on the road as you're getting there But it's not meant to go 200 miles an hour And when we start optimizing our software, it's more like this The other thing is when we think about our languages, especially Ruby, you know, I think Ruby's a fantastic language, but I think mentally we think you know our language is something like this The super tool 300 that's it's sleek and it's you know, well engineered and if you were to read that paragraph It tells you all about how it's you know strong pliers and Designs so it's easy on your hand and all this stuff But when you look at other industries where people are seeing high levels of craftsmanship They don't use Leatherman 300 In fact, if they use a hammer, they use a very specific hammer for a very specific job And I mean there's just a small collection of hammers there if you've done any construction, you know how important it is So one of the things you know thinking about this general purpose programming language. That's just great. It's like your Leatherman 300 Considering how realistic that is is I think a good exercise Recently I wrote this blog. This is a very recent blog post. I think the sixth of november This is a blog post about toys and sort of considering why why white toys quite successful And it's looking at things like the iPod which when it first came out it was sort of considered a toy It was there's other stuff out that had better features and you know more More storage and all kinds of crazy stuff But the iPod became you know the best selling music player in fall time In in this post he basically defines this toy as something that Is a technological product which is simple and fun to use And that may be criticized by some people for being weak Or not suitable for serious work, right? When you think about like how useful The iPod is for what you want to do to play music and enjoyment or entertainment It is suitable for that serious work The blog post goes on let's sort of talk about Three areas why you think toys are Maybe more successful than other serious products and he basically looks at these three areas user oriented interfaces or user experience Like obviously the iPod have really good user experience It's quite simple to use The other point that he makes is that sometimes when we when we're so serious about something like we're in our business suits And we're doing our enterprise sort of software stuff not not to completely go down the whole enterprise is whatever The idea that something is really serious There's two things that can happen one is the people that look at you and see you in your suit Automatically attribute to you some greater level of authority than you may necessarily deserve And the people that are in those roles tend to think of themselves And maybe take themselves more seriously than they should and then that Sort of feeds back and makes them less Able to like question Am I really doing this? Well, is there something that could do better that sort of And then finally if it's a toy meaning that It's probably, you know, not as complicated as some serious product Then it may be easier to use and if it's easier to use then there's more people That are able to use it and that's a bigger ecosystem. There's more people using it. There's more people giving feedback So that that was that was pretty interesting As an example of something that's not exactly a toy. We're really simple. There is a great article about six months ago One of the challenges in world health is um easy diagnosis of a condition called anemia, right? If you don't have the most red blood cells in your blood Unfortunately in a lot of rural areas It's very difficult to have this test done because you have to draw blood and send it to the lab But they have a complex machine that spins very fast and it separates the blood cells in the plasma A couple rice university students Made this project where they took a simple Salad spinner and they modified it so that you could with no power Just the pump action of the of the salad spinner you can spin this for about 10 minutes and actually get usable results So this is something that can go out into rural areas and Very poor places and actually enable doctors to do diagnosis Of this condition so that it can be treated That was a pretty interesting way to think about something that that is potentially really useful But it's very simple so What do we do this little thought thought experiment like i'm pretty sure everybody here is a pretty badass programmer, right? Well, what if what if you didn't know anything about programming Why I think this is really interesting. I was at a conference where a foreign state university professor was giving a little lightning talk About teaching Haskell to people who didn't know programming And I thought that's pretty crazy. Why and how would you start with Haskell? Why would you like try to teach Haskell if somebody doesn't know anything about programming? So I clarify I asked so are you talking about kids here? You're talking about adults and he said no adults just people who you know They've never done any program. They don't know anything about program Okay, so he took us through a series of sort of simple things that you do with folks so Starting with values and I was like, well, do you define what the value is? He's like, no, we assume people can do some basic math So we start with values something like one, you know An integer and some simple operations like adding two numbers together So really simple things and out of that you have values and you have instructions And then you add this idea like what if you took the result of an expression and you gave it a label or name But then you could use later so I can set a equal to something and I can come back and I can use that in the expression for b So now we have simple values expressions and we have variables And then you think about what if you could instead of doing the operation right now Maybe save it for later And at the same time maybe you know Do the operation with different values instead of always having a single value that you have in your expression So this idea of sort of functions comes out And then finally you just like think about a few more values. What if you have like a name and we'll put that in between quotes and then maybe, you know try to add them together or Call some sort of other functions. So you have these very simple concepts And if you think about it for a minute like how much of your programs do these sort of simple things And also looking at this, there's no real distinction here between apparently we didn't cover conditionals obviously, right? But there's still no real distinction here between functional programming and regular programming, right? The mutual state really doesn't even enter the conversation at that point It's really simple introduction and think about how much you could actually deal with these simple constructs, right? So I think that's that's kind of interesting Okay, so all that is sort of introduction to why so why created a programming language and we're Having the little foxes from point of view sort of start in a few of these slides because they've been unemployed for a little while so they were looking for So According to the words I put on here Why made this For people to have more fun. I don't know that what I do know is then in wise documentation He said in this order. These are the languages that really inspired inspired his work on potion So I owe ruby o camel lua rebalt and c interest in combination but Why are we new? Right He already knew ruby and and I'm sure you knew about lisp and And other other languages So there's this sort of there's this sort of thing when you're dealing with ruby It's like people learn ruby and then they want to go to a school They want to go to closure. They want to go learn something else They want to you know, have the coolest most interesting thing and then why was in this community? And yet he was like, I'm gonna play around with the language and he didn't make it whatever that language is, right? So let's look at some of the stuff that he did for him This is a little tour of potion, okay so We had simple values. So you have Numbers you have Decimal numbers you have strings and there's a couple forms of strings that are really pretty familiar to us Single quoted strings have only a single escape Sequence and that's the double quote to embed a single quote in a string nothing else is sort of processed Everything else is taken literally and the double quotes Are an escape string where you can actually put a new line character in there. So hello new line Then there's two basic structured data types one is the list up at the top So one two three just put the sequence together new the list put in parentheses and get a list and then a table which is a simple associative array essentially, right? There's a key and a value Kind of interesting thing is If you take a list and you put a key and a value and it transparently sort of promotes to a table So underneath tables and lists are actually pretty similar. And if you know Louis, you know that this idea is not not really new it's kind of you can do and then Of course you need functions, right? So those two x equals Are sort of two different ways that you can do functions They don't both exist one is wise way and one is the way that I that I think I'm going to implement instead But basically the idea is that There's no depth or anything right to make a function. You basically In the top one you put a list Followed by a colon and some statements in a period So anything that starts with a colon the list is optional, right? It can take no arguments and then it starts with a colon and ends with a period is A function and all those functions are closures. So they really do close over their state So if you look at setting a is equal to five and then you set y equal to a closure That has the just a as a local variable one. That's going to close over five in the adversary super super simple syntax for that and then You have like calling calling methods essentially so at the top you have a simple table And we're putting a new entry and we're putting an entry in pages with a value of 10 Already under string. Hello, and you send it the length method Message you can take a number two. I mean you can take a string two turn it into a number of du plus And then down at the very bottom we have a really interesting construct Ignoring homepage get per second where we're setting session equal to url query So we're sending query message to url. Whatever the result of that is There's a question mark at and session And this is called a query in potion And basically what I guess it's pretty similar to what we tried to implement as object try But basically if the method exists it calls it if it doesn't you get no back But it's a very concise syntax and then conditionals so conditionals are kind of funny If we decompose this we have a response equals. Okay, so we're just setting a value if parentheses name equals ruby, right? And then the colon Blast this slide is messed up This is what happens when you write your own slides. Okay after the grin grimace and groan is supposed to be a query So the conditionals are simply A An expression in parentheses followed by the code block. So it's very it's very uniform What's even more interesting is that in potion if else if and else are actually parsed as message sense And then the compiler sort of treats some specialist says, oh, you're Doing if okay. Well, so I will evaluate this first thing and then I will call out That closure else if that's what they're actually parsed as if they were just And yeah with the periods. Yes Yeah, you can't right because they're special case But what you could imagine is what would happen? So sorry the question was can you override them? And you can't because they're special case in the compiler, right But the idea is that if you wanted to add something where you can do lazy evaluations So you could really pass along the Condition without evaluating it beforehand then you could conceivably do something like that What I think is interesting from a syntax standpoint is that it's it's very uniform And there's fewer concepts that you'd have to actually describe Right That's really key Why they creating some classes so You send the class message to Something and that's something in the top is implicit. There is What's called a lobby in potion, which is like sort of object in ruby But if you're familiar with something else like IO, there's actually a lobby instance. So you send that to class Then you send class that thing and you get back in the class. So fruit is a class and then We can create an instance of it, right The slash color is the way that potion does instance variables. They're called paths And the idea is that they're kind of like a path in a file system To create a subclass that you see where we're creating apple as a subclass of fruit fruit is the receiver of the class message and to set a instance method on Apple you say apple the name of the instance method Equals and then our closure syntax. It's very concise The closure that is past to class Is the initialized method essentially when it's creating an instance of that class It runs that bit of code that this Past class is closure and this isn't wise documentation as i'm reading through the first time i get to that I'm just like chuckling inside so i have to add this here That was what why is always a very dramatic and even in this html it comes out like that Okay, so what do we have so far? We have some really simple syntax Some fairly basic ideas you can create a closure which is something you can execute later You can make some values. You have a couple of structured data types tables and less Really really simple so When I first started looking at this My initial reaction after I went through I started playing with a little bit was like God it's missing this and it's missing that there's no namespace. There's no modules There's always that i'm gonna have to do something about this. I what can you do this language? Okay, so i'm going to start implementing potion, but there's a lot of stuff i'm going to have to fix right I was kind of my initial attitude looking at it So I said okay, what am i going to call it? Well i'm going to call it poison because it's like Sort of a nasty nasty potion Oh So that's where the name came from and initially the reason I was actually working on this is we're working on a peg Implementation based on the lua l-peg And so I was like, what am I going to parse with this? I don't want to parse python. I don't want to think of portal or something So I'll put it that way So that's that's where that's where poison comes from. I call it an interpretation of potion Sort of like a singer If you if you listen to latin music a singer interprets a song a lot of singers are not songwriters they interpret some of the song Okay, and then rubinia. So of course, you know, what am I going to write this out? Of course, I'm gonna write them through videos right so rubinias is a basic for everybody I'll give you a super brief introduction if you want to hear more you should go Evan's talk, which was earlier My machine is available on the hallway Also, it's in your back So rubinias is a is a bytecode virtual machine. So you can compile two instructions, right? And it's got, you know, a modern chip based on lvm. It's got a cool garbage collector And it's got a lot of really cool stuff And I think it's really healthy for our community. It is not encumbered. It's got a great bsd license It's not encumbered by Anybody there's no corporation who is going to do anything to you whether you use it on a mobile phone or on your computer Or anywhere else We're improving the technology a lot, but it's really interesting. I think it's a really important thing for our community So it runs ruby That's that's the fundamental thing about the rubinias vm is that it runs ruby and why that's important is that There's a number of different vms out there and there's actually a project parent He has probably know of right That the idea of parent is like he could run any language on this thing, right? The truth is When you write a virtual machine, you write that virtual machine for one language the parent language is like pcl or something. I mean like it's a it's a very Almost like, you know, like a similar language type thing, but that's really the language for the parent vm And uh, there's other there's other, you know languages. There's the jvm for instance or other virtual machines There's a jvm the jvm language is job regardless of what people say There's some people that would say that you could actually do a lot of stuff on the jvm without touching java And what I think is that's very similar to saying you can get in the ocean without getting wet There's a way to do it you can get in the ocean without getting wet you can go down for the ways But it's not the most, you know, useful sort of thing to actually be in that little suit And when I'm in the ocean I would rather be enjoying myself so That's another reason why I think Rubini is so critical So really quick let's run through how Rubini is actually actually does something because we're going to implement a language I don't want to know how it works, right so It starts with source code you write some ruby source code in this case There's a single class a single method in that class And if we put that through the parser, right we can get back a data structure in this case An abstract syntax tree that we have sort of printed out here Without knowing a lot about the parser we can kind of see stuff that that would make sense for a thing about We round this on a script There's a name script. There's the file wise stuff Makes sense. So you look at this for a little bit. You think okay, that's not too complicated You can look at it in a different form if you want to look at it as an s expression You can you can actually give the rubinius compiler the dash cap s switch and see this as an array of arrays And this is essentially what we're looking at. This is just part of the tree There's obviously more to it. We're basically looking at an abstract syntax tree So when rubinius compiles your code it starts by parsing it into this data structure From this data structure it goes into the compiler You can run the the rvx compile command And you can give it the dash cap l end if you want and you want to look at just one method And it'll show you what that abstract syntax tree is compiled down to in instructions So down there where the numbered things are zero zero zero zero zero two That lists the things for just a sequence of instructions that the virtual machine is going to execute Since I don't know like what all your backgrounds are the point of this being really simple is to show you that this is actually really simple All right, so if you know this I'm not trying to be pedantic and I'm not trying to insult your intelligence If you don't know this I hope that you see the correlation between some simple data structures that this is not very hard Because I want more people to play with this So if we're going to do a little bit of code like this So let's make an instance of that class that we have and we're going to call that method that method takes a single argument We're going to pass it rocks and we expect that it's going to print why rocks, right? But how does it actually do that? The virtual machine, which is a simple stack based virtual machine It's simply going to execute those instructions one after the other The ip equals zero that's the instruction pointer It's just starting out the index zero in this array of things and it's just going to start processing Now kind of tweak this a little bit like where it says push literal Why it's it would really be looking that up in a table, but that's Implementation detail can just as easily sort of be there. So we're going to just consider the simple student instructions run through it So I do a zero basically tells us the the virtual machine Go get push literal and do what it says. Well Push literal is going to put something on our stack So we do and now we have the string y on our stack and then There's no error. This supposed to be push literal one No, I'm sorry. This is correct. Sorry Blur is the value that was passed into our Fast into our function. So we're going to push that value that local variable onto the stack The value that we passed in was the string rocks And so when we do that we get rocks and our stack is growing downward. That's why we pushed it Allow private is a little instruction that says basically you can find a private method So so go that now what we're going to do is we're going to send send a message The message that we're going to send is 2s and it takes zero arguments So what that's going to do is it's going to the receiver is that that last element that we pushed in the stack It's rocks. We're going to send 2s to rocks. It's already a string. So basically what happens when you send 2s to a string Get a string back. So nothing changes Now we're going to push the bang And so now that's what our stack looks like Last instruction is a special binius instruction It's a build a string out of n elements on the stack in this case three So it's going to build a string out of y rocks explanation point Puts that back on the stack The last instruction is to return the way Ruby works, right? When you have a method the last expression the result of the last expression is what gets returned and that's the last thing that's on the stack so basically Why rocks Is return okay So now we're going to implement some pulleism right and Now the hard part will start right not really right It's going to be the exact same thing. So now we know how Ruby works. We can basically write some implementation of pulleism Now we're going to do exactly the same thing different syntax, but that doesn't really matter, right? We're just going to take a string here true We're going to send up a string message and then the result of that we're going to send the print message So we can do the same thing we can we can actually look at that syntax in A tree structure like this Or we can look at it in the s expression structure like that This tree structure by the way is using the exact same Rubinius like facility that we printed our other AST out It's just a little a different set of Nodes and so we have this this tree it prints it out And again, you can sort of look at the relationship between an expression like true string print And these messages like you're sending string and the value you're sending it to the value true So it's it's it's fairly easy to see that there's this correlation between the syntax and the structure that you're actually operating Okay So how hard is this to actually like do something with well? It's pretty simple You know some simple where we can basically potion or poison sorry is my top level module There's a parser thing under it. So I do I create an instance of the parser and I ask it to parse some text which gives me back this tree I could print it to an s expression Or I could ask it to graph itself and I get that tree representation So still nothing nothing really that different than we're doing with ruby already. It's just different syntax, right? Inside the parser. It's not that complicated either. So There's a parse method You pass it a string. It's going to save that string away And then it's going to call this method parse a string Which is the the comment says is actually defining in a c extension And then if there was a syntax error, it's going to show you that and Otherwise it's going to pass you back the abstracts and texture The c extension itself this could you probably can't read but it's not important because it's like two two functions what we're doing is we're using the Excuse me. We're using the Greg parser that why used in his implementation It's a peg parser. It's a re it's a modification of e and p Marta's peg leg To be it's made to be re-entrant, but it's very simple simple syntax It's really really easy to recover me. You basically You basically create a little structure You create an instance of the data structure that the parser needs You say hey go parse some text and then when it returns you check and see if it was successful or not And if it is then you pass them stuff back The syntax for the peg is also really is there is also a talk if you're really interested in pagular is that earlier talk as well Uh, I don't know why I did this this schedule, but anyway, you need all your prerequisites before you come to this Actually, they did it in the correct order. They just didn't tell you that So we're parsing true It's a it's an immediate so an immediate can be a nil or a true or a false, right And true is just some text. It's just like, you know, literally true the string and not Something else The way that the parser is working if we so if we go back you see the potion valve is true con so Why builds this nice little ast using c of stuff and I don't want to do that So what I do is I just call back into ruby code. So that potion ast is a really simple Callback and It just calls that method true con That method just creates an instance of boolean passes at the value true And that instance of boolean is just a node in my ast So it just sort of records the value that it's passed to it. It's a little So that's the parser. So now we basically have our ast structure The compiler is just one little step more than that, right? Basically, uh, I created an instance of the compiler. I give it a string It parses it behind the scenes and it compiles it to a potion or a poison code Object that you can call And that's the call you can send them at the call and execute. So I'm saying true string print and when I call call on the code that I get back is prints true Your turn value is nil. So that's what we get back And compile itself is also not very complicated for compiles. What we're doing is Basically creating an instance of the ravineous code generator and what that is is a class That you call methods on and it collects data as you're calling methods on into that instruction string that we saw earlier to run And so we're just setting up a little bit of stuff We're going to run down that ast right using a visitor pattern We're going to like set up some other stuff at the bottom. Basically, we're just going to define directly on an instance of code Poison code we're going to define the call method and then we're just going to send that object back In the ast visit. It's just A simple visitor. So when it gets when it gets to the boolean node the boolean node calls boolean on the compiler and The compiler says if you're true push true if you're false push false And the way I implemented this is sort of like actually creating a data That data type for true. I said, well, you know what what if I'm just sort of like namespaced some poison methods So you can do a dynamic symbol. So I just said hey, I'll call all my poison methods pn colon and I already have something that turns true to a string. So I'll just alias to that Similar string Instead of, you know, like print wants print as functional kind of in Ruby, you know, you call that you say print and then what you want printed But I think it's kind of cool to say string print send of the print message So all we do is just sort of flip that around and alias that method again And so if we look at the code to do to do true string print It really comes down to pushing true on the stack Sending that potion string method, which is an alias to 2s Sending the potion print method, which is the alias to sort of reverse print and return of the vibe And that's it That's that's how easy you can implement a language. So it Basically what the language is is syntax that can be very different like the syntax of poison potion Is quite a bit different than Ruby But it's going to do very similar things and the rubinius vm does those in a sort of in a sense Generic way with this instruction set and it's really easy to assemble those instructions and do that. And so off you go The the one idea to sort of contemplate about this is that a lot of a lot of people think if you're going to write You know, like if we're going to have potion on rubinius Then potion things should be able to talk to rubi objects Transparenly ruby objects should be able to talk potion objects transparently That's one way you could do it, but there's also another way that you could do it And that's sort of using an idea of a of a distinct sort of communication boundary And if you take something like actors and you imagine an interface on the potion side Creating an actor and talking over messages to something on the ruby side that's using actors You would have to go through far less of that sort of Make a potion thing look like a ruby thing and vice versa You would just have to worry about the message messages between the two So when you're thinking about writing your own language, don't don't like getting yourself tight in the knot thinking Oh my god, if I write this language, it's got to like act like ruby. It's got to respond to ruby messages It doesn't need to do that. There's more than one way to interoperate and actually have really valuable stuff come back to you So that's just an advisory Okay, think about it. So a couple books. I wrote books. There's a couple books you can use. This book is great. It's a super Super good interaction to languages, right? It'll take you through parsing, virtual machines Interpreting, how to do that AST, how to walk and all that stuff. Really good book If you want to get more serious, this book is fantastic If you want to get in this code generation and sort of understand what happens in a compiler that's generating machine code This book is super super good And if you want to understand virtual machines, this book is It's pretty much the best one that I've seen. There's a couple other virtual machine books out there, but that one's really good And uh, I'm gonna work on this All right virtual machines now So, um, I won't be doing a learn poison the hard way this way But uh, zed is actually put out his sort of template for how you would do a learn tax the hard way And I think that's pretty cool. So, uh, yeah This is uh, where you can find the code and there is a website which has got, you know, terrible little placeholder page right now But uh, if someone has like mad design chops, and I want to do like a poison, uh, website Page for me. There's a URL And thank you everyone, uh, you know, I was in uh ruby com for a while and I saw Aaron Patterson give a talk with cross cultural humor and he pulled it off really fantastically and he Sort of does this thing sort of almost every morning like so my good morning everybody. So I think uh, Aaron Patterson is one of the people that is Very much like why in a playful sense and sort of keeping us I'm getting too far into our head and you know reminding us that we're human or like to connect and support that so Thanks to uh, to Aaron Patterson and uh, thank you