Placeholder Image

字幕表 動画を再生する

  • so yes, this is me at my day job, detecting bugs.

  • Ah, yes.

  • So I work every transfer as a friend and engineer and team leader.

  • And for me, that means that I write mostly react.

  • I smell see, assists a little bit of Ruby again.

  • And I also manage a team of six.

  • And I'm responsible for the day to day delivery for that team.

  • And this is also made about six years ago, I was helping run a workshop for young girls in New Zealand, which does?

  • Yeah, where I'm from.

  • And, yes, I'm a very long way away from home.

  • But the idea was that we would get these young women into the company to sort of show them what it was actually like to be a software engineer.

  • There were about 14 years old and they were all in the same tip class at school.

  • And honestly, I think we kind of blew their minds on How cool is this shit actually is compared to what they were learning on, but yeah, I really want to encourage people thio to do as many of these kinds of programs is as you can because it's incredibly rewarding and also inspirational because this was one of the inspirations for this talk.

  • Having worked with Junior Debs quite a lot.

  • It's one of these things that I've noticed is is they really struggle with debugging, and I think that's kind of because we don't really teach it as a skill.

  • It's one of those that you sort of expect developers to just pick up naturally.

  • And there's so much there to learn if you really focus on it.

  • And that's why I decided to write this talk.

  • Hopefully they'll be something useful in here, no matter how deep down this hole you've been before.

  • Better yeah, the quick look of the process itself.

  • How often have you actually spent time thinking about how you debug?

  • It's easy to forget that it's a difficult skill that it's It's something that you need to master in order to become a really experience developer, and it's learned over time and improve with experience.

  • And it's not just about the tools you use, but it's the mindset in the process and how you actually work through your debugging tasks.

  • And it becomes particularly clear when we compare those new developers with more experience ones.

  • Often new developers will jump straight into.

  • The coach will go and change a whole bunch of things.

  • They won't remember what they've changed in what they heaven and what actually might have fixed the problem and what was maybe just some extra bit of code that they stuck in there?

  • That wasn't useful little.

  • But it's something we do pretty much every single day.

  • And so in the talk, I won't go into the detail of how important it is to reproduce the bug.

  • Be methodical, only changed one thing at a time had a narrow down where the buggers.

  • But it's surprising how often this stuff is not talk.

  • So if you're a junior developer or you're teaching junior developers, I hope you're one of either that these two things.

  • Um, yeah, I do spend the time really looking into this stuff with them.

  • So there is one step that I do wanna cover really quickly because even the most senior developers I've worked with and including myself, sometimes I forget to write tests like this is the first thing that you do, right.

  • If you've discovered a bug, right, Otis, that reproduces it because it not only will keep your focus on just that one bug.

  • It'll also speed you up because you no longer need to launch you out and click about to get to the states of where your bug actually is.

  • And, of course, it'll help your bug never return.

  • So let's move on to the tools, starting with the consul Will the polls.

  • Aaron.

  • As you can see, we've got 56% of developers on the left hand side.

  • Use console.

  • Look on 67 on the right hand side, and it's It's not surprising, right, because we've been conditioned to use it alongside simple text editors like sublime text, Adam Note Pad, etcetera and a large portion of Web developers have also just simply missed the exposure to, ah form or or street or structured debugging process like myself.

  • And the browser console is a pretty nice way to inspect the results of your logs so it works and it's easy.

  • Well, why change it well, because there is so much more so even if we just take a closer look at console that look, you'll see that there are lots of different ways to optimize it.

  • So here on top.

  • We have the normal concert log usage for logging out these two variables.

  • Pin one and pen to, and here they are here but on the bottom.

  • If you just add to extricate characters to 10 this log into an object.

  • Here, you know only get the results of the lab but off the value of the variable.

  • But you also get the variable context, so it's much easier to see at a glance what you're lugging.

  • It could be really useful, especially when you're logging a lot of different things in your application, and you can also really add easily.

  • Add styling to your locks by including this percentage Cyan C at the beginning and then passing through some styling as the second parameter, you can get really pretty callous, so sticking to the consul for now.

  • Did you know that there are actually a whole bunch of different, well methods on that object?

  • I'm gonna show you my favorites, but Googling will reveal a hell of a lot more.

  • For instance, console table is super useful if you want to log out an array of objects, so here you can see it's much easier to kind of compare at a glance the different values and next we have console group, which is when I don't know about you.

  • But have you ever at if it ended up adding so many logs in your application that you can't tell which was the one that you just added well group and group collapse A really useful for structuring your logs into collapsible groups, creating less noise in the console for you to analyze, which is really the kind of game.

  • Another useful function you can use in the Consul is the dollar selector.

  • So it works similarly similarly to the J.

  • Crew selector.

  • It's an alias for the document, Doc.

  • Select a function in the console.

  • If you include a zero after it is done here, you can get the most recently inspected HTML element, or JavaScript object.

  • No one gets you a sick and most recently selected Exeter Exeter up to full super useful.

  • If you want to quickly see what properties what attributes on the domino door.

  • JavaScript objects that you're looking at, and if you use dollar dollar, it's the equivalent of document dot query selectable.

  • Even better, it returns you a proper array rather than a node list so you can manipulate its right away.

  • Consul, don't trace has been a lifesaver for me, especially when you're working in a new cold baths.

  • And you can't actually, you don't have that, you know, inherent knowledge of what is calling What?

  • Um and so in here, I added a consul trace on this handle filter click function to figure out what was calling it, and you can see that it's now telling me that it was cool by Handel Clock in filtered Out Gaius and Console Doctor is great when you want to inspect a dom note as a JavaScript object rather than as its markup, which is what concert log returns you.

  • You can see all the properties on that Don owed much more easily.

  • And no, though it's even more useful.

  • As you can see, Consul Logs blitz spits out the objects in black and white, and it only displays to levels Deep Consulate there, on the other hand, allows you to add some really handy configuration.

  • So here we've just added this extra object where we've said colors true of dip null, and it means that we get our logs or pretty with lots of different colors, and you can now access the LAT and long properties on that geo object.

  • So let's say we've been working with console functions for a while and want to step it up.

  • Well, let's dive into the details.

  • So I'm gonna focus on chrome because it's what I'm most familiar with.

  • But the Firefox Dave Tools also really great and have a lot of the same functionality.

  • Browser details have some really handy features for debugging.

  • So the devil's debug A Is that the best one off them?

  • One of the simplest ways to activate this is by using a debug, a keyword in your code.

  • So this debug a key.

  • Would I touch this in into my editor and opened up in crime?

  • And when I refreshed it hit the debug Ricky with their that break point?

  • And so now you can see Sorry, I'm having video issues as well, but hopefully you'll be able to see that we can log out the of the variables in scope at the moment.

  • We can also inspect the entire scope at this point of execution, and we can also step through the code.

  • And speaking of stepping just in case you've never used a debunker before.

  • Here, your main options.

  • They're pretty much the same, no matter what kind of language you're writing or what kind of tool you're using.

  • First, we have resumed, which is when you're on a break point on you.

  • Press this and you'll be able to resume the script until the next break point.

  • It's hit.

  • If you hold this button down, you also have the option to play through without hitting any more break points, which could be useful when you just want to get the code running.

  • The next is step over, which executes the next function after a break point and stops afterwards.

  • And then we have the step into and out of functions and note that these air functions that were stepping over into and out off, not lines of coach that can take a little bit.

  • Thio kind of get that, um and yes, So what we've been doing here is adding a line of code break point with the debug.

  • A key would in our idea, but if you set things, break points in the diff tools or in your head, Issa, you'll see why this could be much more efficient than using Consul Log.

  • It's almost as if you've pippins your whole code base with consul locks without actually having to do so and having to clean anything up.

  • Simply click on the line number.

  • So here I've clicked on 14 21 and 26 and then run your code as usual.

  • And the execution will stop on your set line of code break points, which you can then press resume to hit the next one and go through as opposed to needing to step through over every single function.

  • And when you're doing this, you may also want to use a watch expression.

  • So that's what I've got here.

  • On the right hand side.

  • I've just decided Thio click the little plus button there, and I've just decided to watch this dot state dot mysteries because I want to see what's happening to that data.

  • And then as you step through the code that, um, expression will update so you'll be able to see the value of whatever you're watching.

  • There are lots of different types of break points, and you can see these are cities directly in the details.

  • So, for example, example, we've got the line of code, which is what we've just been talking about.

  • Conditional line of code, which I'll show in a second dom.

  • So if it don't know changes except us off, you wanna break on a particular http request event, listeners exceptions and functions.

  • So here on the left, you can see howto ad break points just on certain event listeners.

  • So here, just by taking click, there means that any time I click on my app, a break point will be hit and then we have the dumb nards.

  • So here I'm gonna break on when a dumb nodes attribute is modified and then conditional break points down the bottom could be really useful.

  • For when a certain function say, s girl Handa or a react Renda is called multiple times.

  • But you only want to stop execution when something has a certain value.

  • So here I am, creating a break point that will only be hit if the length of my mysteries array is more than zero.

  • So I hear only want to stop when the FBI has actually returned my data because I only actually care about the data for this particular debugging case.

  • I know that the FBI is returning, so I don't need to stop when a pia hasn't returned.

  • But the react renderers run, so you can always click on the pores on exceptions button.

  • If you want a break point when there's an era and the tick box to pause on court, exceptions can be really useful.

  • For instance, if you've gotta try catch that's swallowing your errors and you're not sure why, then you can find out more about those exceptions.

  • When you have a bunch of break points in your app, it can be useful to disable one or more when you're focused on something specific.

  • So this chick mark in the break points list here will just disable that breakpoint temporarily.

  • And in the debugging TOBA, you can disable all break points in case you want to.

  • Just check how your runs while you're chickens and changes you've made, for example, and it's all that's really useful when you're using.

  • The D Bagger is like boxing.

  • The slits us prevent the D bugger from stepping into certain scripts when we're debating code.

  • So here I was debugging a reaction lifecycle function, and I jumped into the React Dom library.

  • I could be pretty sure that my bug is not in the react on library, so I black box the script and this way, next time I stepped through into a function that comes from this file the debate.

  • You will simply ignore it, and I can focus on my application code.

  • You can also include file patterns in the digital sittings to black box entire folders like no bottles.

  • For example, another useful trick when you're really unfamiliar with the code base is command plus backslash.

  • If you press this short cut when JavaScript, as executing it will add a break point to the code straight away and stop it executing, you'll be able to instantly see what is happening the moment you press that shortcut.

  • And you can also not add log points and crime death tolls, which is essentially a console log that you don't have to remember to delete from your coat.

  • The D beggar want paws on these points, but you'll still get the results in the console.

  • Another really useful tool, windy bagging and the deaf tools is the snippets option.

  • Under the Sources panel here, you can save your own codes in efforts to run in the console, and there are some really great collections of snippets of edible, online and different libraries.

  • So one of my favorites, old, wins the console with a function called console not safe, which you can use and pass anything to it, which then gets downloaded as adjacent.

  • Wow, this is really handy, especially when you have a big Jason objects that you wanna open maybe in an I D or you want to send it to a colleague, for example.

  • Another useful tool is live expressions.

  • You can click the EI icon here to type something into the console and create a live expression.

  • This pins it to the top of the console, and it updates riel time.

  • It could be really useful.

  • When something in your code needs to respond to a window with or scroll position, for example, you'll be able to see it update as you scroll down the side.

  • So what about when you want to actually test some of your bug fixing hypotheses while a really great feature in crime has cooled local overrides, So here we go to the sources panel and go toe over its and we can set them up by selecting a folder on, in this case, my discount clinic.

  • And we didn't need to give crime access to that photo.

  • And then we can go and change any of the code on this size, for example, this pot of the Reddit website and adds whatever we want.

  • So I'm gonna add a background color of purple.

  • And now if I go command save, you can see about this little purple dot up here on the file.

  • And then when I refresh the changes of persistent, which is really, really useful if I close the diff tools and refresh, the changes are gone.

  • This approach is really useful for making smallest changes to production websites.

  • When you're trying to debug something in particular, when you want to fix something quickly and you have a reasonably good idea of where it is, you don't need to have your local environment running.

  • You don't even have to have the original code on your computer.

  • It's could be done with just about any computer set up.

  • So what happens when you want to go further and make bigger changes that you know, I only want to persist on browser Refresh, but persist to your own project file sitting locally on your computer, while the details also have a really interesting feature called workspaces.

  • So here's a little app I made for calculating insulin dosage for diabetics.

  • Note.

  • It's a production app on her Roku?

  • No, on my local host.

  • So this could could be any website.

  • Right?

  • So in the file system tab, I can add the folder.

  • This is my actual photo on my disk up for this application and again give the details access to it.

  • And now you can see my applications loaded here in the sources panel.

  • I'm gonna make a change.

  • It's gonna add a consul log of high.

  • Why not?

  • And if I say that and go to my idea, you can see that the file itself has been updated and I can also go back the other way.

  • So I'm gonna add everyone here and see that it's persisted here to the diff tools.

  • This could be super useful, really powerful, and in fact, for some people, it allows them to use just the diff tools de bugger as a sorry def tools As the idea, however, it can be a little flaky, and it's still not as good as a full I D.

  • In my opinion.

  • In particular, it struggles with more complicated build systems.

  • But if you have a project that you built with, create, react up or view so you see Ally, for example, you can actually just drag the entire folder onto the sources panel, and it's all set up for you.

  • So if you like this idea of being able to assist changes on your production website, there's one last way I want to show you.

  • This is the concept of proxy ing your production files to local files on your hard drive, similar to work spaces but without the diff tools, persistence but with a lot more other features that better support complicated build systems.

  • The simplest is a crime extension.

  • Cord results over it.

  • So say you have a version of your application running on local host.

  • Using this extension, you could proxy the cool that your production website is making in this case on the left hand side, bundle dot Js to the version of that file on your local drive.

  • So that's my local host bundle dot Js, and this allows you to change your code and test it within the larger environment where the bug actually occurred.

  • Applications like Fiddler and Childs Proxy, which is my personal favorite, also allow you to do this, but with a lot more features, including the ability to monitor and inspect all the calls that your website is making.

  • I've been on teams that have literally used child's proxy for their entire front and development flow.

  • Many big applications could be tricky to sit up locally and trying to keep the best friend architecture and AP eyes up to date as people are working on them as well as your own front end code base.

  • Across multiple teams can be a pain in the ass that content quite a lot of time.

  • If, however, you have a reliable staging environment that everyone's pushing to, then proxy in your front in files is a nice way to skip that Sit up entirely.

  • It's a lot of the technology I'm covering.

  • Either it's seriously enhanced by or doesn't work at all without source maps.

  • So so this map is a file that allows the browser or other technology to match the compile.

  • It'll compress code back to its original file.

  • It's a really important tool that helps with debugging.

  • Unified code is almost impossible to debug properly.

  • On the top, we're inspecting a website without source maps, and you can see all the variables have met been mangled and the Essex class has been transpired.

  • Where is on the bottom?

  • Source Maps have been set up, and it's a easier to understand what's going on because it's the code we actually wrote.

  • And depending on your build process, it should be pretty straightforward to sit up.

  • Here's the conflict for Would Peck and at the top is the way to tell which Peck to use its standard development configuration, which includes source mess by default.

  • If you want more control, you can define it separately.

  • Chosen cheap module evil because I like the balance between speed and support, but your choice will depend on your use case.

  • Then, beneath that, we have the conflict for production, and the only thing you actually need here is the diff tool property.

  • But if you're using a cliff I gaius to modify your code, you'll want to see it sourced map to true.

  • When you declare that plug him And if you want to sit the file name of the source map, you can bet, too.

  • When you build your project, you should see your source met file like we have over on the right hand side.

  • So what about deploying source maps to protection?

  • Well, I am a big believer in doing this, because production bugs is when you really want to know what's going on, you're in a hurry and you want to decipher the code pretty quickly.

  • So the good thing about source maps is that they only get downloaded when the diff tells opened, so they now have no effect on your application or on its performance.

  • And if you're really worried about people being able to look at your source code and unmodified, and keep in mind that security through obscurity is never a good idea, then there's a pretty straightforward solution.

  • So here you can indicate in the JavaScript file a source.

  • A source mapping euro configurable with Ipek that points to the source map that's been uploaded to a different location, say one that's only accessible by your team.

  • Liken history bucket.

  • Maybe that only set up for your company's VP in tow access.

  • And if you're not able to sit up, source maps say you're just being nosey and checking out someone else's website.

  • You can always click on the format button to make the code at least slightly more readable.

  • So moving on now it's a performance debugging, and I do not have time to do it justice, because there is so much you can learn about here, and it's easily another entire talk.

  • But I wanted to quickly illustrate where you could start, and the key is to find the code that you wrote right, So these flame shots to be a little bit indecipherable until you actually figure out where your code is.

  • So few clicks open the main panel.

  • You'll see all the activity that occurred on the main threat, including the execution of JavaScript.

  • Usually, a lot of the stuff here is found in frameworks, but if you scan through the orange sections, you'll be able to find your JavaScript files, which is usually what you're looking for.

  • Right in this case is my main dot Js file.

  • And no, this is a very basic one page app, which is why it's so small you can then zoom and further and find the functions in Europe and compare the time that they're taking with each other.

  • Here we can see a cool to a pin child and Fitch, which should be a little bit more familiar to us.

  • And the easiest way to debug and APS performance.

  • Poor performance is by doing a performance audit with Lighthouse.

  • This is a tool inside that, would it's panel.

  • You can see the results on the same small one page up on the best, but here is the Opportunities section where they have, ah, where you've got a list of the resources that you should optimize, and it has specific details on how to do so.

  • The order's panel also allows you to order other things like accessibility, which is really great.

  • It makes something so important, so much easier.

  • And if you follow the expense, the specific advice in the order, your app will be so much more usable for so many more people and in many cases, improve the experience Everyone keep in mind, though, there is no substitute for proper manual accessibility testing.

  • So when it comes to debugging specific elements for the accessibility, the elements hand comes in handy here.

  • You can inspect elements and see which properties correctly filled out.

  • So in this case, we're inspecting a text input.

  • You can see that the name property is such, and this is what screen readers will read out.

  • When the use of focuses on this input, you can see that the name was computed by looking at the place holder property.

  • This input should really have a proper label or an area label, but at least it has a placeholder.

  • So all uses would now be able to know what it's for, rather than screen reader just reading out text input.

  • So the last thing for the diff toes Did you know that you can even debug note in the diff tools?

  • You just need to run your node script with the Inspect flag.

  • Yeah, came by the way means break before the code starts so that you can add your break points straight away.

  • Then either click on this green node icon down here on the left or go to crime slash inspects and click on open dedicated def tools.

  • The node.

  • If you like this workflow, you should check out the node inspection manager extension, which manages all your scripts and win and Windows for you.

  • So let's get to the really good stuff.

  • Integrated debugging in the episode has been around for ages, but many JavaScript developers I I'm not aware of it.

  • They think it's too tricky to sit up Well, they don't want to change the debugging minds it because they don't think it's worth it.

  • Well, I'll let you be the judge, but do give it a go first.

  • Unfortunately, we have a lot more front end editor, um, up to these days, some of which include an inbuilt de bugger, I'm gonna focus on Venus code because it's super light and fast.

  • That's what I use every day.

  • And I promise I'm not trying to sell you anything because, well, that would be stupid because it's free.

  • But, yeah, other ideas, like Web Storm, also include an in built deep again, and the idea is pretty similar.

  • I'm gonna take you through my debugging process and how I set it up with a mini front in react depth that talks to an express over.

  • I've added a couple of spelling mistakes to simulate a real bug that you might be trying to fix.

  • So typical bro sis, the debugging A friend and application might look something like this.

  • We up in the browser, we see an error in the console.

  • We go to our editor, we log out some of the variables back to the brows and refresh.

  • Or maybe a hot module reload.

  • And if we're lucky, we've chosen a variable that helps us determine how to fix the buck back to the innocent.

  • Make the fix batch the browser refresh.

  • OK, great affects.

  • Well, that's a hell of a lot of guesswork and switching back and forth.

  • I mean, where we're used to it, but it doesn't need to be this way.

  • Obvious code has a bunch of extensions that let you debug tons of different languages in different configurations.

  • The most useful for us is the day bug off a crime extension.

  • It's actually framework agnostic.

  • So you could be wishing with Angulo of you react whatever you like, but I'm gonna show you the configuration for my app.

  • So festival.

  • I'm going to the extensions and searching for the D bag of current.

  • I'm gonna install that and reload via scarred.

  • And now I can go to configurations and add a new configuration.

  • And I'm gonna choose the launch crime one here.

  • And I'm gonna change the euro two local host 3000 because that's what create react that uses by default and save that and then press play.

  • And you can see that the app is loaded.

  • Was absolutely no other set up or sittings really, really easy.

  • And the debugging experience.

  • It's also really nice.

  • So here I have a bug because there's supposed to be some courts showing up in my act.

  • And if I add a debugging breakpoint about where I think that the bug probably is and then refresh, I can see I've hit my brake point and I can see that quote is undefined.

  • I wonder what.

  • And if I go into the variables here and inspect the actual dasa Aiken C o the data calls it quote.

  • Okay, well, then I can go.

  • And it it The variable fixed the bug, removed the break point and then restart.

  • And hey, it's fixed.

  • And I didn't even need to touch the browser.

  • Obviously, this is a pretty fake example, but you get the idea.

  • So before I finish I should just quickly mention that in no way have I covered the space.

  • I've obviously had to focus on one browser and one I.

  • D.

  • And I didn't even touch on mobile and network and serviced worker debugging, to name a few.

  • There is so much more to explore here.

  • And of course, accurate and realistic test coverage is an extremely important and useful way to prevent bugs in the first place.

  • Provide a quick and easy way to test fixes and prevent them from occurring again.

  • The golden roll My golden rule.

  • Whenever you fix the bug, make sure there's a test for So the last thing I'm gonna leave you with is this.

  • If you want to stick to the good old console log, then that's cool.

  • By may I still use a combo of different tools, including console log.

  • But please, at least set yourself up with a good code snippets.

  • So you're no wasting your life typing it out by hand every single time.

  • That's it.

so yes, this is me at my day job, detecting bugs.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

現代の探偵のための必須JavaScriptデバッグツール レベッカ・ヒル著|JSConf Budapest 2019 (Essential JavaScript debugging tools for the modern detective by Rebecca Hill | JSConf Budapest 2019)

  • 2 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語