1 00:00:00,600 --> 00:00:07,320 Let's talk about another developer, fundamental, and this one is commenting your code. 2 00:00:08,280 --> 00:00:12,840 Up until now, you may have seen me comment at comments to our scripts. 3 00:00:13,850 --> 00:00:22,100 For example, right here, I added a comment of booleans, and this tells the Python interpreter, hey, 4 00:00:22,100 --> 00:00:25,460 this is a comment, don't run this, it's just for me. 5 00:00:25,730 --> 00:00:28,310 You can just ignore it and skip over to line two. 6 00:00:28,880 --> 00:00:29,900 And you saw that. 7 00:00:29,930 --> 00:00:32,810 I simply did that in Python with the sign. 8 00:00:33,050 --> 00:00:36,590 As soon as Python sees a pound sign, it adds a comment. 9 00:00:36,980 --> 00:00:38,880 And you can do that after a line as well. 10 00:00:38,930 --> 00:00:44,840 I can say this assigns to a variable. 11 00:00:46,610 --> 00:00:52,730 And although this may look like two lines, it's actually just the word wrapping that's happening and 12 00:00:52,730 --> 00:00:56,180 you can see that the interpreter just completely ignores these comments. 13 00:00:57,020 --> 00:01:02,060 Now, commenting sounds very, very simple, but it's an important concept. 14 00:01:02,060 --> 00:01:07,580 And if you want to be a good programmer in all languages, we have commenting. 15 00:01:08,000 --> 00:01:11,060 But there's good days and bad ways of commenting. 16 00:01:12,180 --> 00:01:17,880 And this is something that comes with practice, but here are some key guidelines. 17 00:01:18,860 --> 00:01:27,200 When you're commenting your code, the idea is that you're adding valuable comments, that is, if I 18 00:01:27,200 --> 00:01:42,350 add a comment here that says, hey, this is a sign name variable, a value of Andre strength, a comment 19 00:01:42,350 --> 00:01:43,010 like this. 20 00:01:44,110 --> 00:01:45,250 Is not really good. 21 00:01:45,490 --> 00:01:46,450 Why is that? 22 00:01:46,840 --> 00:01:52,330 Well, because your code should be self-explanatory, right? 23 00:01:52,570 --> 00:01:58,150 The idea is for us to write code that is easy to read, easy to understand. 24 00:01:58,150 --> 00:01:59,980 It's not trying to be clever. 25 00:02:00,160 --> 00:02:02,260 Instead, it should read like English. 26 00:02:02,710 --> 00:02:06,430 And any Python programmer would know that here. 27 00:02:06,430 --> 00:02:10,230 We're just simply adding Andre as a value of name. 28 00:02:10,270 --> 00:02:17,470 We're assigning a variable and adding a comment like this that's self-explanatory just adds clutter 29 00:02:17,500 --> 00:02:18,190 to your code. 30 00:02:19,280 --> 00:02:24,650 So there's a trade off here, it's good to comment your coat for, let's say, if you're working on 31 00:02:24,650 --> 00:02:30,860 teams and other developers come and they want to understand your code, but you have to remember this 32 00:02:30,860 --> 00:02:34,010 principle of code being easy to read. 33 00:02:35,170 --> 00:02:43,480 The only time you want to add comments to your code is, well, when something really, really important 34 00:02:43,480 --> 00:02:51,010 is happening, where it might be a little complex, you first decide, hey, is this code written in 35 00:02:51,010 --> 00:02:52,630 a way that makes sense? 36 00:02:52,810 --> 00:02:55,330 For example, if this was variable A. 37 00:02:56,350 --> 00:02:58,690 And this was variable B. 38 00:03:01,150 --> 00:03:07,660 Well, this might be really hard for somebody to understand, so you might say that this is is cool 39 00:03:07,750 --> 00:03:08,350 flag. 40 00:03:09,670 --> 00:03:16,180 But before you add that comment, you want to say to yourself, maybe my code is hard to read, maybe 41 00:03:16,180 --> 00:03:21,160 I should just change the variable to is cool to make it more understandable. 42 00:03:22,270 --> 00:03:29,800 Now, this is something that you improve upon more and more and you do want to use comments as an extra 43 00:03:29,800 --> 00:03:34,930 tool to make your code understandable, maybe you write code that six months from now you want to go 44 00:03:34,930 --> 00:03:36,370 back to understand what you did. 45 00:03:37,180 --> 00:03:41,620 But remember, more comments doesn't necessarily mean better code. 46 00:03:42,340 --> 00:03:51,040 You want to be concise and keeping things simple while adding comments only when necessary to help others 47 00:03:51,040 --> 00:03:55,960 understand your code, not trying to make your unreadable code more readable. 48 00:03:56,770 --> 00:04:00,760 We'll explore this topic and give you advice on it throughout the course. 49 00:04:01,360 --> 00:04:07,570 But remember this key developer fundamental because you're going to need it throughout your career. 50 00:04:08,620 --> 00:04:17,740 By the way, this article over here has some really important points that I think you'll really benefit 51 00:04:17,740 --> 00:04:25,150 from, especially in the commenting best practices, you can read some of the do's and don'ts and what 52 00:04:25,150 --> 00:04:27,460 some of the top programmers do when commenting. 53 00:04:28,160 --> 00:04:33,370 I know it sounds silly, but it is an important concept that most courses overlook. 54 00:04:33,650 --> 00:04:36,610 So I highly recommend you read over this. 55 00:04:36,790 --> 00:04:41,140 I'll link to it in the resources and I'll see you in the next video.