1 00:00:06,580 --> 00:00:09,060 - Correctness versus performance. 2 00:00:09,060 --> 00:00:11,940 So this is a big one for me, because we've also been trained 3 00:00:11,940 --> 00:00:15,040 as developers to kinda focus on performance, again, 4 00:00:15,040 --> 00:00:17,310 as a priority, and we tend to write code 5 00:00:17,310 --> 00:00:19,910 with the idea that this gonna be faster than that. 6 00:00:19,910 --> 00:00:23,030 The reality is is that unless you've done a thousand times 7 00:00:23,030 --> 00:00:25,470 and you already know, you're guessing, 8 00:00:25,470 --> 00:00:28,230 and usually code that's focused on performance 9 00:00:28,230 --> 00:00:29,980 is clever code. 10 00:00:29,980 --> 00:00:31,750 I wanna reverse the tables on this. 11 00:00:31,750 --> 00:00:33,890 I don't wanna optimize for performance. 12 00:00:33,890 --> 00:00:37,090 I wanna optimize for correctness when we're writing code, 13 00:00:37,090 --> 00:00:39,290 I wanna use our debuggers and our profiles, 14 00:00:39,290 --> 00:00:41,940 not really our debuggers, I apologize, our profiles, 15 00:00:41,940 --> 00:00:44,950 our ability to benchmark, our ability to trace, 16 00:00:44,950 --> 00:00:48,060 to identify where we may have a performance problem, 17 00:00:48,060 --> 00:00:50,700 and then fix the performance issues like that, 18 00:00:50,700 --> 00:00:55,220 still trying to maintain levels of correct or readable code. 19 00:00:55,220 --> 00:00:57,500 Look, the performance of your software 20 00:00:57,500 --> 00:00:59,440 is gonna come from four places, 21 00:00:59,440 --> 00:01:01,550 or I should say the lack of performance 22 00:01:01,550 --> 00:01:03,220 is gonna come from four places. 23 00:01:03,220 --> 00:01:06,680 First is latency, and it's gonna be latency on networking 24 00:01:06,680 --> 00:01:09,630 and IO, disk IO, those types of things. 25 00:01:09,630 --> 00:01:12,190 That's going to be a real killer of performance, 26 00:01:12,190 --> 00:01:14,850 and those are things you probably want to focus on first. 27 00:01:14,850 --> 00:01:16,970 Your next potential performance strain 28 00:01:16,970 --> 00:01:18,690 is going to be on memory allocations. 29 00:01:18,690 --> 00:01:20,720 We're gonna talk about that in this class, 30 00:01:20,720 --> 00:01:23,970 and memory allocations can cause performance problems, 31 00:01:23,970 --> 00:01:25,390 and we'll see that when we start 32 00:01:25,390 --> 00:01:26,730 talking about the garbage collector, 33 00:01:26,730 --> 00:01:28,930 and the garbage collector's doing an amazing job, 34 00:01:28,930 --> 00:01:30,920 but we don't wanna walk away from it. 35 00:01:30,920 --> 00:01:32,540 When we talk about performance in GO, 36 00:01:32,540 --> 00:01:34,550 it's not about is it the fastest, 37 00:01:34,550 --> 00:01:36,600 it's about is it fast enough, 38 00:01:36,600 --> 00:01:39,470 but garbage collection and memory allocations, 39 00:01:39,470 --> 00:01:41,160 that will be your number two. 40 00:01:41,160 --> 00:01:44,580 Number three is going to be how you access data, 41 00:01:44,580 --> 00:01:46,630 how efficiently you access data. 42 00:01:46,630 --> 00:01:48,910 We're gonna talk about that in this class as well. 43 00:01:48,910 --> 00:01:52,300 And then, number four would be algorithm efficiencies, 44 00:01:52,300 --> 00:01:57,200 can we streamline an algorithm to take less steps than more, 45 00:01:57,200 --> 00:02:00,120 and we tend to, if we're optimizing performance, 46 00:02:00,120 --> 00:02:02,590 focus on that piece, and the reality is 47 00:02:02,590 --> 00:02:04,260 the hardware's gonna be so fast 48 00:02:04,260 --> 00:02:06,480 if we solve the first three problems, 49 00:02:06,480 --> 00:02:09,080 that we can have a little algorithm inefficiency, 50 00:02:09,080 --> 00:02:12,980 and still get more than we need in terms of performance, 51 00:02:12,980 --> 00:02:14,880 and now we're optimizing for correctness, 52 00:02:14,880 --> 00:02:17,460 and this is really where we wanna go. 53 00:02:17,460 --> 00:02:19,300 And there's some great quotes 54 00:02:19,300 --> 00:02:22,120 by some amazing people in this area. 55 00:02:22,120 --> 00:02:24,120 Wes Dyer, "Make it correct, make it clear, 56 00:02:24,120 --> 00:02:26,080 "make it concise, make it fast." 57 00:02:26,080 --> 00:02:28,450 I want us to listen to this history. 58 00:02:28,450 --> 00:02:30,250 These are people who've already learned these lessons. 59 00:02:30,250 --> 00:02:33,430 I don't wanna make the same mistakes. 60 00:02:33,430 --> 00:02:36,180 Alright, JBD who works over at Google, and again, 61 00:02:36,180 --> 00:02:37,250 you gotta look her up, 62 00:02:37,250 --> 00:02:41,000 she's also a tremendous thought leader in this space. 63 00:02:41,000 --> 00:02:44,170 Engineering's not about finding the perfect solutions, 64 00:02:44,170 --> 00:02:45,430 it's about understanding the trade-offs, 65 00:02:45,430 --> 00:02:46,610 we talked about this. 66 00:02:46,610 --> 00:02:49,090 Engineering's about understanding the costs you're taking 67 00:02:49,090 --> 00:02:50,900 for the benefits that you need. 68 00:02:50,900 --> 00:02:53,750 It also is about optimizing for correctness, 69 00:02:53,750 --> 00:02:56,230 knowing what we're doing in terms of our code. 70 00:02:56,230 --> 00:02:58,750 And correctness of the implementation 71 00:02:58,750 --> 00:03:00,210 is the most important concern. 72 00:03:00,210 --> 00:03:01,930 Listen what Al is saying here, 73 00:03:01,930 --> 00:03:04,660 "but there's no royal road", listen to Al again, 74 00:03:04,660 --> 00:03:07,000 what he's gonna say is that it takes several things, 75 00:03:07,000 --> 00:03:09,590 invariants, that's the engineering costs, 76 00:03:09,590 --> 00:03:11,450 testing and code reviews. 77 00:03:11,450 --> 00:03:14,700 And testing and code reviews really require our ability 78 00:03:14,700 --> 00:03:17,180 to read and understand code. 79 00:03:17,180 --> 00:03:19,700 Without our ability to read and understand code, 80 00:03:19,700 --> 00:03:21,660 we're really going to be lost. 81 00:03:21,660 --> 00:03:24,190 There's a great quote that says that 82 00:03:24,190 --> 00:03:28,080 we are one of the few industries where we ask people 83 00:03:28,080 --> 00:03:30,920 how to write code before we teach them how to read, 84 00:03:30,920 --> 00:03:33,250 and this is really mind boggling 85 00:03:33,250 --> 00:03:34,940 when you start to think about it, 86 00:03:34,940 --> 00:03:37,190 because everything that we're gonna talk about, 87 00:03:37,190 --> 00:03:38,560 about correctness, 88 00:03:38,560 --> 00:03:42,540 is going to stem from our ability to read code first. 89 00:03:42,540 --> 00:03:47,030 And this class is all about our ability to read code, 90 00:03:47,030 --> 00:03:50,910 to optimize for correctness, to be productive. 91 00:03:50,910 --> 00:03:51,780 That's what we're trying to do, 92 00:03:51,780 --> 00:03:54,330 that's what GO is trying to do, 93 00:03:54,330 --> 00:03:57,240 and if we continue to look at quotes even from Bryan, right, 94 00:03:57,240 --> 00:04:01,420 the basic ideas here of good style, of correctness, 95 00:04:01,420 --> 00:04:04,640 they're fundamental to writing clear and simple code, 96 00:04:04,640 --> 00:04:08,440 and we've known this, he's known this for over 35 years. 97 00:04:08,440 --> 00:04:09,890 I'm not telling you anything new, 98 00:04:09,890 --> 00:04:12,230 these are not my ideas, these are not my philosophies, 99 00:04:12,230 --> 00:04:15,300 I'm trying to bring to you industry leaders 100 00:04:15,300 --> 00:04:17,170 who are telling us over and over again 101 00:04:17,170 --> 00:04:19,840 correctness over performance when it comes to the code, 102 00:04:19,840 --> 00:04:24,210 and to do that, we've gotta be very good at reading code. 103 00:04:24,210 --> 00:04:27,180 But I love what Jason Fried said here, maybe again, 104 00:04:27,180 --> 00:04:29,350 next to Sarah May, one of my favorite quotes here 105 00:04:29,350 --> 00:04:30,710 in the material, 106 00:04:30,710 --> 00:04:34,460 "Problems can usually be solved with mundane solutions. 107 00:04:34,460 --> 00:04:36,280 "That means there's no glamorous work. 108 00:04:36,280 --> 00:04:38,120 "You don't get to show off." 109 00:04:38,120 --> 00:04:42,340 Okay, you build something, it works, you move on, okay? 110 00:04:42,340 --> 00:04:44,270 And this is really important. 111 00:04:44,270 --> 00:04:45,103 This is one of those quotes 112 00:04:45,103 --> 00:04:47,420 I want you to put in front of you at all times, 113 00:04:47,420 --> 00:04:51,120 because if you are a back-end developer, like I am, 114 00:04:51,120 --> 00:04:53,950 and what you're looking to become if you're not already, 115 00:04:53,950 --> 00:04:56,450 then the idea is that your software 116 00:04:56,450 --> 00:04:59,020 should be working 24/7 without issues. 117 00:04:59,020 --> 00:05:01,550 The reality is nobody should know your name 118 00:05:01,550 --> 00:05:04,100 if you're doing your job well. 119 00:05:04,100 --> 00:05:05,710 If somebody knows your name, 120 00:05:05,710 --> 00:05:08,730 probably means your software's failing or causing problems. 121 00:05:08,730 --> 00:05:10,020 You want people to know your name? 122 00:05:10,020 --> 00:05:11,470 Become a front-end dev. 123 00:05:11,470 --> 00:05:13,270 Front-end devs get the oohs and the aahs, 124 00:05:13,270 --> 00:05:14,540 but I promise you this, 125 00:05:14,540 --> 00:05:16,900 you're gonna spend two weeks working on a screen, 126 00:05:16,900 --> 00:05:19,560 killing yourself to get things in a certain location, 127 00:05:19,560 --> 00:05:21,700 certain words, and the first thing somebody's gonna do 128 00:05:21,700 --> 00:05:23,780 when they look at it is point something out 129 00:05:23,780 --> 00:05:25,030 that they don't like. 130 00:05:25,030 --> 00:05:26,770 Aah, that used to drive me crazy. 131 00:05:26,770 --> 00:05:28,480 I'm a back-end dev, okay? 132 00:05:28,480 --> 00:05:30,740 I build systems to the point 133 00:05:30,740 --> 00:05:32,750 where nobody knows I even exist. 134 00:05:32,750 --> 00:05:34,360 That's a good day in the office.