RubyConf 2014

Cómo depurar aplicaciones Ruby en cualquier dirección temporal

Brock Wilcox  · 

Transcripción

Extracto de la transcripción automática del vídeo realizada por YouTube.

greetings humans from the 21st century today I'm going to talk about debugging which is a very good topic all the time in this case time-travel debugging start off with basics my name is Brock Wilcox or some contact information way down here I also work

for op Toro we help retailers with their returns great they paid for me to come here so prob tomorrow yeah they however do not pay me to do mad science unless I can make it practical so we'll work on that debuggers you all use debuggers yes there's

a lot of different styles of debugging my classical favorite is log base debugging you know print your print here print here all the way down and then you know it got to that line right but then there are debuggers where you have interactive thing you can

step through your program how many of you have ever used to do but I like to do a little poll here you know ever Wow how many of you use it on a regular basis also impressive sweet so and this is a ruby land Ruby Lane debugging all right my favorite debugger

and Ruby land is actually pride dash by bug so you got the by bug debugger which is the new one in two point O guys use values but mixed in with the magic of pro will demo since URL are experts at debugging this might be redundant but I don't care alright

so shows up excellent I get two screens magical so here we are a simple program we pull in our debugger and this binding pry which hopefully you're all very familiar with drops us into this nice ripple and tells us what line of code we have not yet executed

point six year and you can look around you can do some math you can I don't know json.parse something why would you do that whatever okay and you can look at X which is not even born yet so it's step now we haven't run this line yet so X still

doesn't exist and now finally we have seven which is great you can step through and you can see it out putting things here at 17 you can change it and then you have your current value of x very cool very handy highly recommended anyone who is not using

this add it to your gemfile immediately you can ssh the wave Wi-Fi it's fine so that's pry bar anyone know how that works no great so in yard there's an intermediate byte code and there's a great book Ruby under microscope which goes into lots

of details on this highly recommended if you're at all even tangentially interested and this bytecode has a lot of things it's a stack-based so you know you push self and you push them string and then you do a send and pop out the results some stuff

like that in between these things you have these trace lines and anytime one of those is hit that's an opportunity for the interpreter to do some sort of introspection on the current process it could be looking at variables it could be saying hey is this

a breakpoint or not things like that it then in turn exposes an API for third parties to tap into this so what by bug does is it has some some sieve which hooks into these and then it can use their the yard API to say hey when line such-and-such comes up and

you happen to hit one of these trace things hit my call back or if you're doing a full trace every single one you can hit the call back bringing simple you could have lots of the whole talks about how this works internally but fortunately this writes it

out for you right here you can see very clear it's literally inserted into your code at all of the points where you can break it adds in hooks neat yes as mentioned Ruby under my scope wonderful all right it's pretty sweet right anyone yes okay we

can do better than this primitive technology it's horrible forward thinking we can apply some mad science excitement no yeah science all right so there's this gem you can get because I wrote it called pride time travel stuff a little demo program looks

awfully similar but I added a nice little line here and when we run it we can do the same kind of thing and say next see what X is next whatever but then like wait oh I mean a mistake i meant to edit something before and you can go from line 12 to 11 by typing

back and now on this line it has not yet executed yet so X will be seven not 42 at all that's completely wrong okay here seven but when we go back we're now on line 8 and so it hasn't been executed yet and thus we are before X has even been born

we've gone back into the past and we can change everything we can do horrible things I don't know what we can assign it to something which will then just get it over written when we type next but nonetheless we could do anything it's amazing so

you can go back in the past and that's it that's a yes so there's other talks right now I'm going to go into how this is done the magic unveil a little bit but if nothing else you go home add fried you know by bug to your thing and then you

can add pry time travel and your code will probably eat itself but you can do it anyway and we'll see what happens alright so here's how it works this is the idea there's nothing new Under the Sun this is I came up with this one morning and I'm

like wow this is great idea and I googled it and other people have done it so that's how it goes doesn't matter how big the clock is you're trying to hang it doesn't know anyway so what we'll do is every time you type next or Mikus end

or something we'll just for cleaners it's sort of the you know the multiverse theory that every action causes another universe to split what we're going to like embrace this idea and we're going to explicitly fork the universe upon an action

and then we'll take that new universe we peeled off and we're just going to suspend it freeze it go off in the cold locker or something cryogenic it's great and we'll just kind of save that maybe we'll do that several times every time we

[ ... ]

Nota: se han omitido las otras 2.981 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.