1 00:00:00,000 --> 00:00:09,356 [MUSIC] 2 00:00:09,356 --> 00:00:12,093 Hey, my name is Ashley Boucher and in this course, 3 00:00:12,093 --> 00:00:14,649 we're gonna be diving deeper into functions. 4 00:00:14,649 --> 00:00:17,849 You might have touched on functions previously in your coursework, but 5 00:00:17,849 --> 00:00:21,207 before moving on, be sure to check the teacher's notes to make sure you've 6 00:00:21,207 --> 00:00:23,365 covered all the prerequisites for this course. 7 00:00:23,365 --> 00:00:26,843 Also, don't forget that you have complete control over how you watch this video. 8 00:00:26,843 --> 00:00:28,291 Want to slow me down or speed me up? 9 00:00:28,291 --> 00:00:32,714 Go for it, feel free to pause, rewind, or even fast-forward as necessary. 10 00:00:32,714 --> 00:00:34,455 So what's a function? 11 00:00:34,455 --> 00:00:36,959 A function is a reusable block of code. 12 00:00:36,959 --> 00:00:39,333 You write a block of code, give it a name, and 13 00:00:39,333 --> 00:00:42,595 then you can call the block of code whenever you need to use it. 14 00:00:42,595 --> 00:00:46,855 Typically, a function does one programming task and it does it really well. 15 00:00:46,855 --> 00:00:49,429 That's the standard we're looking for, in other words, 16 00:00:49,429 --> 00:00:52,786 you should be able to think of a short and descriptive name for your function. 17 00:00:52,786 --> 00:00:56,244 If you can't do that, the function is probably doing too much. 18 00:00:56,244 --> 00:00:59,800 One thing developers should always try to do is not repeat themselves. 19 00:00:59,800 --> 00:01:03,164 This is known as DRY programming or Don't Repeat Yourself. 20 00:01:03,164 --> 00:01:06,786 Functions are great way to help us avoid writing the same code over and 21 00:01:06,786 --> 00:01:11,047 over because we can just call the function whenever we need to execute that code. 22 00:01:11,047 --> 00:01:13,816 Another equally important reason to use functions is 23 00:01:13,816 --> 00:01:17,824 that they make your code easy to read and follow, they also make easy to test. 24 00:01:17,824 --> 00:01:19,684 Sure, you could write your code for 25 00:01:19,684 --> 00:01:23,778 program in one script file without any functions, but what if there's a bug? 26 00:01:23,778 --> 00:01:27,658 How would you ever find it let alone squash it, and how would anyone also 27 00:01:27,658 --> 00:01:30,051 working on your code know what it was doing or 28 00:01:30,051 --> 00:01:32,714 make changes to it without breaking something? 29 00:01:32,714 --> 00:01:35,825 Functions are everywhere in programming and they are very important, so 30 00:01:35,825 --> 00:01:37,140 let's learn more about them.