1 00:00:00,700 --> 00:00:03,870 Okay, let's see if we can set some ground rules and pick up a couple of 2 00:00:03,870 --> 00:00:07,610 theoretical concepts before we get into the nitty gritty of writing code. 3 00:00:07,610 --> 00:00:09,890 The first two are pretty straightforward. 4 00:00:09,890 --> 00:00:13,200 Computation is the evaluation of functions. 5 00:00:13,200 --> 00:00:17,980 This means that we do our work computing values and outcomes all in functions. 6 00:00:17,980 --> 00:00:22,180 We'll try to keep as much of our work inside of discrete functions as possible. 7 00:00:22,180 --> 00:00:24,910 To me, this is easiest to think of as math. 8 00:00:24,910 --> 00:00:27,640 When we're just talking about it, we take two and combine it with another two, and 9 00:00:27,640 --> 00:00:28,760 we get four. 10 00:00:28,760 --> 00:00:31,590 But in programming we'd be using an add function that takes 11 00:00:31,590 --> 00:00:33,130 at least two arguments. 12 00:00:33,130 --> 00:00:35,050 That function then sends back the four. 13 00:00:35,050 --> 00:00:39,360 So our computation was done by evaluating the add function. 14 00:00:39,360 --> 00:00:41,680 This ties neatly into our next rule. 15 00:00:41,680 --> 00:00:43,765 Programming is done with expressions. 16 00:00:43,765 --> 00:00:46,450 We do our work by using expressions, 17 00:00:46,450 --> 00:00:50,230 passing the output of one function into another, either through chaining or 18 00:00:50,230 --> 00:00:54,120 by assigning the output to a variable and then using that variable. 19 00:00:54,120 --> 00:00:55,940 Again, we can go back to math. 20 00:00:55,940 --> 00:01:00,675 If we have an equation of 5 minus 3 times 2, that of course has subtraction and 21 00:01:00,675 --> 00:01:02,101 multiplication in it. 22 00:01:02,101 --> 00:01:06,112 And according to the order of operations in math, we do the multiplication and 23 00:01:06,112 --> 00:01:09,990 use its resulting value in the subtraction to get us our answer of minus 1. 24 00:01:09,990 --> 00:01:12,790 And just like doing the same math problem over and over again will 25 00:01:12,790 --> 00:01:17,790 always get you the same answer, we should have no side effects from computation. 26 00:01:18,830 --> 00:01:22,700 We don't want to change values that are outside of our function's scope. 27 00:01:22,700 --> 00:01:26,160 We have to be careful with this when we're using mutable types like lists and 28 00:01:26,160 --> 00:01:27,550 dictionaries. 29 00:01:27,550 --> 00:01:30,440 Eliminating side effects means that we can run a function with the same 30 00:01:30,440 --> 00:01:33,500 inputs multiple times and nothing else, no other inputs or 31 00:01:33,500 --> 00:01:35,760 values anywhere in the stack will change. 32 00:01:35,760 --> 00:01:39,350 It also means that we can more easily predict the state of the entire program 33 00:01:39,350 --> 00:01:40,336 at any point in time. 34 00:01:40,336 --> 00:01:44,130 Functions are first-class citizens. 35 00:01:44,130 --> 00:01:47,790 In Python, functions can be provided as an argument to a function call or 36 00:01:47,790 --> 00:01:49,550 returned from a function. 37 00:01:49,550 --> 00:01:52,460 Since functions are usable as values just like variables are, 38 00:01:52,460 --> 00:01:55,480 they're considered to be first-class. 39 00:01:55,480 --> 00:01:57,400 To get the most out of functional programming, 40 00:01:57,400 --> 00:02:00,850 a language needs to be able to do more with functions than just call them. 41 00:02:00,850 --> 00:02:04,340 Being able to chain functions together, take functions as arguments, and 42 00:02:04,340 --> 00:02:08,890 return functions as values gives us some fluidity to how we solve a problem. 43 00:02:08,890 --> 00:02:12,590 Functions should be limited in scope and functionality. 44 00:02:12,590 --> 00:02:15,650 We want to make sure our functions have a well-defined purpose. 45 00:02:15,650 --> 00:02:19,662 We want them to achieve a single task and then give us the answer from that task. 46 00:02:19,662 --> 00:02:23,510 By limiting the scope, or amount of data that a function has, and 47 00:02:23,510 --> 00:02:27,150 the functionality of the function, we can keep our code clean, small, and 48 00:02:27,150 --> 00:02:28,670 effective, all great things. 49 00:02:30,030 --> 00:02:32,770 Okay, the next video will actually get us some practice 50 00:02:32,770 --> 00:02:34,470 to go along with all this theory. 51 00:02:34,470 --> 00:02:35,230 I'll see you there in a bit.