Bestand wählen

Prying Open The Black Box

Zitierlink des Filmsegments
Embed Code

Automatisierte Medienanalyse

Erkannte Entitäten
the the and the the the the the the the
online and on got this 103 of you probably know from on banners we have around downtown this the theme of this year's conference is
on 1 industry on stage and the last 2 years have been exceptionally grave raw history and with all this year at 1 stage how industry stronger than ever so please in general and welcome to clean 2015 the biggest ratio of order laundry and dry-cleaning industry I could have just didn't I just here from the dry cleaning industry unfortunately a conference actually ended 2 days ago and you should probably stick your eye anyway because as you'll find out how industries also very are obsessed with keeping things dry and things I was right at the end I work in
the light of minivans and is never really
I work in the health and light of in a row of and I'm the I'm not going on
in my man and his answer changing coat I I love interiors and
is actually my for frills conf and this actually a conference with a lot of sentimental value for me personally 4 years ago I was in a real strong my 1st tech conference were on the reals comes scholarship program but I came back the year after 1 cereals for office hour and had my request merged since then have been making regular contributions to rails and shortly after of year was accepted into 14 and then a year later games we can respond reverse time so I would like to thank you can you know like think the community for supporting me and what do and if you are a constant for use go I would like to personally thank you for informant get and I hope that was a worthwhile investment for you In our if here for a 1st time or if you just recently picked of rails I like to welcome you on behalf of the Ruby on Rails community I promise that you have a good time here In facts and I had such a good time
rails Conf last year I took 1 of assigning with me and I travel around the country that is in the Web for a lot we went to Hollywood we 1 on the Conan show together we sat at a poker table and we even made it to Canada after spending a few days on the bolt from by the way and if you think about this please don't steal of rails consign believe it not mentally conferences over uh like a mentioned
earlier I'm on the rails for team I also work on the
newsletter called this week in rails but if you would like to keep up with the latest changes in rails this would be a pretty good way to do it you can subscribe to a newsletter that neural or if you're interested in writing this newsletter we should have a chat after this or 1st more
agency in Ankara Canada comparables and
gas speaking of Canada if you have never been there and if you will like experience can itself I rolled jumper at you can run like Canada and all you need to do is to require Canada and you'll be able to program like it I if you want to actually experience Canada but we're organising really conference in Ankara later this year the details are early this course right now but if you're interested in common you can fall living through the Twitter account to stay in the loop but it's actually get on to we'll talk but like many of you I
watched David keynote last year and I stop calling myself engineer and became instead of after curing this jump a over a year I realised that perhaps isn't really fully capture what I do for work you see the money were confined from 380 work on some pretty complex Rails apps and when I work on these complex Rails
apps I spend most of time fixing things instead of making Michael look pretty so I either I'm fixing an existing bargain AB or perhaps I'm writing new cold and then you call somehow broke that out in unexpected ways and to figure out why so this is something that I am that the of pride and you can see it Missouri seriously but of course in
reality what I actually do is pretty boring and all I do is I the the figure what's wrong and fix it and repeat but by the way that's my coworker force can hold if you see him around the conference please do not be alarmed the
so as boring as my job is in reality but because I work on the rails code base so when I get trapped in into these projects sometimes people think that I'm doing something really special for a number of infection probably heard of this before and might even you the same where personally about it this rails
thing is basically just magic and it might be cool over while the soon things stopped working the way you expect that magic becomes black magic and black magic is obviously bad because you can understand it and the only way out is the higher the wizard to fix your recalled through and 1 of the rules
40 members are freer recently tweeted about this topic so it turns out that there's actually no magic in rails there's some saying the following conventions parts all you need to do is actually just read the documentation and learn about these things itself 1 of the this and we sparked the conversation on Twitter and 1 of replies kind of something up pretty eloquently perhaps what it really is is that real work alluded to well all of the velocity and we really productive without actually spending a lot of time studying the documentation so it almost seems like it can read your mind and now that's and that's basically the key the cost of learning rails is not part of from you do not need to spend a lot of time learning before it can start writing code and With that lands
perhaps the rails is not really magic after all perhaps we just treating it as a black box because we don't really understand what's inside the black box so today we're going to trial and the black box together so you don't have to be afraid of more some and you've probably had this happen to you before euros Encoding rails and it blew up on you and if no idea what the 1st thing you do is
stop tend to be preference not too bad but you see what actually happened here is that you wrote some cold and you try to run the cold you expect that the code is this something for you and that didn't happen perhaps a court is something else perhaps nothing happen or perhaps you get an exception but you see you actually have some pretty solid advantages here or 1st . wrote called to presumably you that you you probably understand the called the new role and because he wrote the code you have access to decode you can run it you can modify you can do whatever you want to go and inferred because he wrote the code we understand exactly what went wrong here that you might not know why or how it went wrong yet but we do know is that the expected in the happened and that's freaky I finally because there's no magic involves the bug is not going anywhere is not magically disappear you so you have time to fix it so with that in mind wherein look at some of the weapons you have to help you figure these things out when they do not work the way you expect and this is probably a little bit off the is this assumption of reappointed element where you should probably start checking documentation surprisingly not a lot of people know where to go look for rails documentation this is not an EPI for rails that's the soldiers found this is actually the official documentation and so this is where you get the documentation for latest stable release and if you using not the latest stable release that's not a problem you can get the docks for any tax version from the same website and finally if you're on the bleeding edge of running on trails or using bear on our city in go to edge if you had a really engrossed or use the latest documentation for was on master there's also this thing called rails guides which is basically more detailed and hands on articles about specific topics and the same thing again take version or into the edge versions well another seemingly obvious thing is that you should problem using the latest version of rails because the problem you have things might already been fixed but this the zeros set and then because which version this latest how they find out if you knew in this might not be very often it's because the rails versions scheme might not work the way expects and the 1st digit and the the version there is the major version and the 1 in the middle is called the minor version and the last thing is called patch version now major minor thing doesn't really matter so much because the 1st 2 digits together is called really serious and basically for this purpose as long as you stay in the same really serious they should be 100 per cent compatible with you what do you think the only with more about fixes applied so in other words you should try to stay on the latest patch version of the really serious that you're using the when I'm when to buy the at fixed for a particular version we get back poured into this thing called the stable branches for a particular really serious so you see that someone fix about and get help the poor press was merge but there's no released from patch version of redundant you can change a gem file and pointed to the corresponding stable branch and you get the cold instantly but it's so the ease of his or when you read the documentation and using the latest version and you still having the same problems so this is a good time to get serious and they can get to the bottom of the problem the the 1st and the most powerful weapons you have what is called the stack trace you probably seen it before you get 1 of these things whenever again error and you have and the 1st line is basically telling you what the error was and the rest of them as the stack trace stack trace is basically a bed from trail of cold it's a ranging from logical order the bottom is the oldest thing that it ran in the top is the the most recent thing that was executed on there are apparently some cost of reversing the order in real stuff in review 2 . 3 I just heard that history but on either where 1 of them is the latest 1 of them is the oldest and it goes in that order but
perhaps the visualization make it easier to understand what the spectra is really telling you is that at some point
but this create method in your polls controller you of yeah this tree method in the polls controller is executed on I wonder if I can fix this real quick
search give me half a 2nd
so I guess it's just going to be that way anyway so this is the pulse controller and at some point rails executed decree methods here and that's the blue frame bottom screen and now and the Creative method eventually calls to respond to block and that's the it per bold frame on the stack trace and that purple block eventually called some pole start save up this fixed thank you for that I'm a cult will start save which eventually calls the and ensure all the before save callback which is the red thing on the stack trace and finally that calls this venture permission of method somewhere and that's the yellow frame and at this point something we don't know what gets the something went wrong and here and an exception was raised so really the stack trace
is really just a snapshot of the last breadcrumb trail that led to the point where things started going south sort of like a notice lantern no no offense intended and and that
something is not right here on well the 1st thing someone must have called the polls controller create method related to not just you know call itself in thin air and if you look at the if you remember really didn't
really call the before create order before save copper correctly all the colonies the top save method and somehow that calls to ensure also and it's not showing up in the stack
trace so I'll think rails as being completely honest with us here and the and yet come on we need the full story here and so it turns out the rails is in fact hiding something from us here out rails shift of this thing called the backtrace clean air by the father will only show you the applications that trees in it saw it will only show you the application stack frames in intersect traces and it will remove everything else and in fact if you look at your
initializes you probably see 1 of these files and it tells you how you can customize the spectra is cleaner and ends at the bottom of the there's a line that you can uncommon if you do that then releases interviewed the full trees
which now looks like this this is exactly the same error and because it doesn't fit on the screen more just that the font size a little bit I'm hoping still read it
I gave you can I made in the slide the seems in free and I tried to highlight the 4 lines that we see in the original factories as see it is embedded in this like C of very tall stack trees and so but you know once we disabled the batteries cleaner we see everything that's actually going on here as it turns out this real things which is really cold on computer that's executing somewhere and is what is really doing is is trying really hard to use the other way this a priest for a reasonable because from when something went wrong is most likely and adapt cold and by having the batteries cleaner helps you focus on what is most likely to be wrong but at the same time if you suspect rails is responsible for problems then you really need to to see everything and now to get the full picture and understand what's going wrong OK so now we have learned to read the stack traces you might start to appreciate how useful they could be and but you only get that traces when you have an error what if you don't have an error 1 if you call basically just silently failed or perhaps the at some height acute simple that and you have no idea how it got there what
you can just raise their own air there's actually like this my lovers Simple but is actually a very useful thing the time for example let's
say you have no idea I got to ensure permission method and you just raise an error within there and then you have a stack trace and you know exactly what led to the execution of that cold it the sometime
this factory is just doesn't give you enough information to be up the problem so long as we mentioned earlier is that traces snapshot after state of the system before right before it went the exception happens the but in reality a bunch of other things probably happened before that point and the root cause of the problem can be anywhere with within their so as an example let's say you got no method error and you look at the Century understand why that's happening you trying to call a current user don't name but it's because current user is nil you end up calling you don't name and obviously that doesn't work but look in the stack trace here doesn't really help you know because you understand yes I'm getting a new effort error because I'm trying to call about name on but what you really want to know is why current user is new to begin with and current user is set in the before filter all the way it lasts sold the stack trace it's not capture any of that information for you and that's not very helpful sold to find out why current user is nil we're going to look at this really advanced debugging method called the
put statements as this is probably the 1st thing you learn when you learn Ruby on but it can actually be pretty powerful weapon for debugging as well this how you use it you go
into the piece of code that you want to know what investigate and you put some I got a thousand times and what is actually have to be that like basically the idea is you want to print something ridiculous onto the consuls so that you can possibly miss so whenever it runs this called the Prince somewhat so I got a dozen times and consul and you will immediately spotted that is happening and was study can print every a lot of other stuff in there you can look at the variables you have access to for anything you need on the screen to help you understand the problem and there are some other things that you can try to do here for example
inputs scholar which basically gets you stack without actually throwing exception so you call this going to continue run after point but you still have a stack trace to tell you what exactly led to the execution of that code and there's also this thing called pp in the center library with stands preprint I give you a little bit more organized of what of complex objects when you print them to counsel and rails also give you this thing called instance values which basically gives you a hash of other instance variables on the current object which is also pretty handy when you're debugging but problem problems the problem with the advanced debugging techniques other than the fact that it's in to pollute you're loss with a lot of so many gods that is that we need to know ahead of time exactly what you need to find out so if you forgot to put up put statements for the session user ID variable then like you don't get that information you log in you have to basically change recorded that by providing everything we start over fortunately there's a better way to do this even more advanced debugging technique called debugger and if you are
using rails for 1 to or evolved you will notice that during the have a debugger and you dump file called by about and if you don't have 1 you just at that yourself at the so
to use it basically just replace on would means with the by call and when it reaches that line you get something like this in the Council
from here you can execute arbitrary really cold so you can check check the colors inter instance variables and so on besides the usual
Rico there's some some by about specific command so you can run Mono have time to get into that but I you you can look up the documentation yourself and finally in formant you you can also add this Council helper and you're you're templates which allows you to use similar things but in the browser right so but we
still have a not problem even that really offends deepening technique of using divided does not enough for us because you look at the stack trace you see at the 1st few frames are we actually want to investigate all rails cold so it's not like you can actually open up the file and add the debugger call to method or can we now I feel very closely you see that there is a file name and line number in each frame of the stack trace and you might be wondering perhaps these are just regular Ruby files sitting on my computer somewhere so maybe if I open this file in the text editor and changes and save it perhaps that would just work and you will be absolutely right this is 1 of the nice things about working with interval language like really most of the things you're executing there just like plain text files sitting on a computer somewhere and you can modify them without recompiling them really linking them or whatever so can colleges open up the text the pointed to this file a changes and work or there's a more
convenient way called on open so because using bundle for rails out anyway you just had bundled in the jam name for example when and is going to bring up i in and your favorite text editor and that you can modify the files higher relighting and put statements in their origin at the by calls or in change stuff around to experiment with any theories that you might have you literally go crazy with this enough you too bad above written things because once you're done you can run this command college and and would basically restore every changes that you like all the damages made to jam so you don't have to you if you are too cautious about doing this and there's 1 thing to remember because all the germs of law that once when you start your Rails app I if you made any changes to the chance rails or any other libraries you would need to restart the real server and if using string you have to stop the swallow from which gets really annoying if you're going to make a lot changes to this files constantly so you can temporally disable string by setting the disable strain of environment variable and spring will be disabled for that terminal sessions yeah OK so now if you have a computer viewing actually tried this in your app and you try running bundled handrails you know is something pretty strange yes detector the
open yes you're in the rails jam but the jam is empty so this is actually because rails as defined in the a few small libraries and the rails can is actually just a metagenome that requires of them so some of these libraries you might be familiar with is at record active support but you don't really need to know what's the difference between each library because the stack already tell you which library you're
looking at so in this case it's pretty obvious that you need to do on the open Active Record so that the
bundle uh right so is an alternative if you happen to have a real slow cool Brill's cones locally on a computer but instead of using bundle then you can also modify gem von pointed to directory and this directory should happen to be the rails check out that you have locally and this is pretty cool because it the real shock you have this obviously a git repository so all the commands and you know like get already works in there you can stash stuff you can reset stuff to clean up after yourself in even check out specific branches for specific text you like if you suspect that the leaders for print from 1 has a regression you can compare between 4 when it's 2 . 0 and 4 1 2 1 1 just simply by checking out the corresponding tags and the repository and we study real server so that's pretty convenient OK so we're going back to the stack
trace so let's say you finally figure out how to make this bundle thing work and you finally opened the
1st file in the stack trace it looks like this you can if you have 2020 vision you probably read it but I don't and this file is like in reliance and I have no idea what is about what you did well 1st of
all Dick is not that bad and there are a lot of stuff going on in the file but most of them actually matter the we need to do is use the laser focus on from you working on and ignore everything else otherwise you just get over like trying to learn all the rails and the 1 hour debugging session that you have it's not at work so to have new that you can basically ideas as yourself for questions whenever you look a method tried the base as quickly as possible find out what this method is supposed to do what are the inputs to this method now that could come in the form of the arguments and the method method or it could be instance variables or it could be global variables but given the specific set of inputs what is the expected output of this method and finally the day actual output matched exist that the expected outcome so let's folder breadcrumbs and see what happens
we are in this method this is the method that the stack trace pointers to this call finest yeah class and now with all knowing anything else about this method you can quickly knows that this is probably the right place to look because in our stack-trace we're getting a subclass Not Found error and this Linus raising is a plus Not Found error so this is probably what is ultimately causing a problem what is unclear go is wise this cold raising this very like it just is an unconditional rates wise that up so it turns out that is rescuing name error here and then ignoring the origin the NameError and raised to surpass not found error OK so now the from shifts into this because we know that the cold rescue name error and soul something from here must be falling in a mirror for some reason and because you learn to use the debugger you can quickly check the value of this Stoffel STI class thing might be available in my view method but it doesn't really matter because it's going to return a bullion more like a true or false event and based on that can quickly eliminate either 1 of the French so let's say support for SDI classes falls so all you need to do is look at this compute type method and figure out why it's raising in the mirror but there's a problem that we know that we need to look inside this method but we don't know where this method is actually defined and because really allow you to mix in all of models in the class the answer to this question may not be immediately obvious to me the 1st
thing you might find useful for no new taxes the India project why search but this is this usually usually go over well in rails because we the same method like 50 times impulse to pronounce so you probably gonna find a lot of definitions for the same effort but fortunately because really knows about where this method is otherwise it can call so we can actually just asked review for this information to do this you ever debugger
like we always do and has to be in the same context calls method but I'm once
you're in there you can call the method helper which is a method that takes the the name of the method you want check in the form of symbol and return some pretty useful metadata so for example you can ask for the source location which is a string that tells you where which file defined this method in which line number define this method for the last owner which is the model the class that contains this method that you're looking at if you add meshes source chairman the jump file which by the way will be from a part of real fight it will be in the default gen file and if you have this jam then you can even ask for the source of this method so in you type methods compute type bought source it would literally print out the method definition and you do better for you and you can even get the comments that goes before the method so perhaps so would help me understand what the methods intended to be so if that information let's say we got to this
method somehow and it looks like a lot again once again we need to stay focus solely quickly eliminate 1 of the branches and now we left with this and unfortunately after reading the code a few times you still have no idea why the code is written in the specific ways in particular you might think that something is fishy industry lines that I point out and unfortunately they're not a lot of comments surrounded to help me understand what it was supposed to what do you that well at some point in time some human being robust called recently with a clear purpose in mind usually we don't just put colon rails for reasons I sold 1 thing you can do is you can probably go back in time to look at the initial implementation and go for the incremental changes that it's been through and perhaps that would help me understand the current implementation and the rationale behind and this is exactly what getloc will tell you
will tell you all the comments on this file you can get the same thing on get have by using the history you but what is even cooler is get so did blame basically tells you who you touch the last 1 who is the person that touched the each line in the file last and 1 for nearly a tells you that commit that touches the outline and I'm with the shall you can do it did show and I will show you the mid and it gives you the full contact of change and you can obviously and designed to have this well-disciplined button that does the same thing but but unfortunately this come it turns out to be a refactoring commit that basically just leave a few things around so doesn't really explain anything about the purpose of the method yeah so when you actually want to do is you want to see the 2nd most recent commit that touch the line and you're interested in and to do that you can run get blame with the shower and period after at the carrier this very important so I will like to highlight that and if you don't you you can see from back 3 and similar more so yes this is how you this how you how did to some start from the Karen after shall you have given and that basically not achieved the result of what you want to blame the 2nd most recent commit that touched the and if you
prefer this on get help I the Chrome extension to make it easier unfortunately there's a bug in there and it affects but but hopefully it will be fixed by the time you have a chance to try this at home or if you're interested in working on this you can compare with me later at the Conference with it so after all the work we have established the good understanding of the problem but but with everything else that's going on you have to have some agentive Someya libraries that can be so many things to many variables what you do not naturally 1 of the solutions is to generate a new Rails out and see if you can reproduce the problem there and if you can then it's probably reals about and if you cannot then it's probably some other gems and use new apps and you might not know this but if you do you specified at that like when you generate new Rails app it was set up to point to your local chart Council and a few other nice things like a disabled spring and stuff so basically it's a more convenient way for you to do some of the stuff I mentioned earlier and sometimes you don't really need a full blown grows up to reveal deal from time for example you having Active Record issue all you need to do is set of a model connected connected base and you can test the problem with all the in the full context of rails for that we have these but report templates on the rails repository is in the guide for the inverse of what report template folder they're basically minimum boilerplate code required to run the test case again and on the rails libraries and I and there's 1 for Active Record 1 for an action packed and we just recently added that generate template for the test so with the problem of producing fresh application in Iceland task is it's very easy for others to help you so you can probably if you can consistently reproduce a from the makes it very easy for other to investigate maybe fix a problem for you so being able to you on reproducing from on a fresh row apps or in 1 of those but important place an attached at two-year issue with greatly increase your odds of getting help or with everything you've learned from the stock you probably know enough to nail down where exactly from this happening and you can probably yourself and you and for parts and that's why you might like while I read all the stuff I did not learn anything new from this talk I already use all of these things to talk about in my own apps and you're 100 per cent rights you probably know these things already and you've probably debugging your applications every day at work and that's kind of points this rails
thing the turns solve this just read and when things this working really well it's just quickly turned into Ruby and it turns out that
rails is just another big legacy code base which is probably not that different from all the other cool bases that you have to work with so you probably know how to deal with this already and and so if you will like you practice any of these things or if you will like a refund because you try these on your albinism work we are hosting a rails for community of our on Wednesday during the happy hour at hero could so you can bring out you come talk to us and then we can probably help you with the or you should probably do this if you haven't already highly in 1 of the rows contributor is running a lap later this afternoon I'm on contributing rails and she's going to cover a lot of the things I didn't have time to go into so if you haven't already signed up for a lab is this afternoon that's all I prepared for you today once again funny on intranets as gold and the
century mansion intereference conference where you know and in the in the in the in the in
Quelle <Physik>
Puls <Technik>
Lineare Regression
Radikal <Mathematik>
Analytische Fortsetzung
Quelle <Physik>
Ordnung <Mathematik>
Tabelle <Informatik>
Selbst organisierendes System
Weg <Topologie>
Reelle Zahl
Äußere Algebra eines Moduls
Verzweigendes Programm
Faktor <Algebra>
Wort <Informatik>
Persönliche Identifikationsnummer
Element <Mathematik>
Computerunterstütztes Verfahren
Komplex <Algebra>
Regulärer Graph
Wurzel <Mathematik>
Maschinelles Sehen
Freier Ladungsträger
Physikalischer Effekt
Spannweite <Stochastik>
Projektive Ebene
Web Site
App <Programm>
Physikalische Theorie
Physikalisches System
Objekt <Kategorie>
Brennen <Datenverarbeitung>
Offene Menge
Umsetzung <Informatik>
Gesetz <Physik>
Elektronischer Programmführer
Metropolitan area network
App <Programm>
Befehl <Informatik>
Kontextbezogenes System
Rechter Winkel
Grundsätze ordnungsmäßiger Datenverarbeitung
SCI <Informatik>
Klasse <Mathematik>
Open Source
Lesezeichen <Internet>
Ruby on Rails
Elektronische Publikation
MIDI <Musikelektronik>
Patch <Software>
Formale Sprache
Kartesische Koordinaten
Prozess <Informatik>
Stützpunkt <Mathematik>
Figurierte Zahl
Funktion <Mathematik>
Prozess <Informatik>
Twitter <Softwareplattform>
Explosion <Stochastik>
Keller <Informatik>
Zeiger <Informatik>
Keller <Informatik>


Formale Metadaten

Titel Prying Open The Black Box
Serientitel RailsConf 2015
Teil 08
Anzahl der Teile 94
Autor Chan, Godfrey
Lizenz CC-Namensnennung - Weitergabe unter gleichen Bedingungen 3.0 Unported:
Sie dürfen das Werk bzw. den Inhalt zu jedem legalen und nicht-kommerziellen Zweck nutzen, verändern und in unveränderter oder veränderter Form vervielfältigen, verbreiten und öffentlich zugänglich machen, sofern Sie den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen und das Werk bzw. diesen Inhalt auch in veränderter Form nur unter den Bedingungen dieser Lizenz weitergeben.
DOI 10.5446/30691
Herausgeber Confreaks, LLC
Erscheinungsjahr 2015
Sprache Englisch

Inhaltliche Metadaten

Fachgebiet Informatik
Abstract Every once a while, Rails might behave in strange ways that you did not expect, and it could be difficult to figure out what is really going on. Was it a bug in the framework? Could it be one of the gems I am using? Did I do something wrong? In this session, we will look at some tips, tricks and tools to help you debug your Rails issues. Along the way, you will also learn how to dive into the Rails codebase without getting lost. The next time you a mysterious bug finds its way into your Rails applications, you will be well-equipped to pry open the black box yourself!

Ähnliche Filme