Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,660 --> 00:00:08,280
Let's talk about another developer fundamental and this one is commenting your code.
2
00:00:08,390 --> 00:00:15,680
Up until now you may have seen me comment at comments to our script's for example right here.
3
00:00:15,680 --> 00:00:23,200
I added a comment of billions and this tells the Python interpreter hey this is a comment.
4
00:00:23,210 --> 00:00:25,790
Don't run this it's just for me.
5
00:00:25,790 --> 00:00:32,150
You can just ignore it and skip over to line two and you saw that I simply did that in Python with the
6
00:00:32,270 --> 00:00:33,030
punchline.
7
00:00:33,140 --> 00:00:38,920
As soon as Python sees a pound sign it adds a comment and you can do that after a line as well.
8
00:00:38,990 --> 00:00:50,360
I can say this assigns to a variable and although this may look like two lines it's actually just the
9
00:00:50,480 --> 00:00:56,790
word wrapping that's happening and you can see that the interpreter just completely ignores these comments.
10
00:00:57,080 --> 00:01:02,080
Now commenting sounds very very simple but it's an important concept.
11
00:01:02,090 --> 00:01:07,790
And if you want to be a good programmer in all languages we have commenting.
12
00:01:08,030 --> 00:01:14,500
But there's good ways and bad ways of commenting and this is something that comes with practice.
13
00:01:14,510 --> 00:01:21,430
But here are some key guidelines when you're commenting your code.
14
00:01:21,470 --> 00:01:26,150
The idea is that you're adding valuable comments.
15
00:01:26,150 --> 00:01:40,310
That is if I add a comment here that says hey this is a sign the name variable a value of Andre string
16
00:01:41,750 --> 00:01:45,510
a comment like this is not really good.
17
00:01:45,560 --> 00:01:46,880
Why is that.
18
00:01:46,880 --> 00:01:51,990
Well because your code should be self explanatory.
19
00:01:52,040 --> 00:01:52,600
Right.
20
00:01:52,610 --> 00:01:58,160
The idea is for us to write code that is easy to read easy to understand.
21
00:01:58,160 --> 00:02:00,260
It's not trying to be clever.
22
00:02:00,260 --> 00:02:07,340
Instead it should read like English and any python programmer would know that here we're just simply
23
00:02:07,340 --> 00:02:10,280
adding Andre as a value of name.
24
00:02:10,310 --> 00:02:13,770
We're assigning a variable and adding a comment like this.
25
00:02:13,790 --> 00:02:20,990
That's self-explanatory just adds clutter to your code so there's a tradeoff here.
26
00:02:20,990 --> 00:02:26,390
It's good to comment your code for let's say you if you're working on teams and other developers come
27
00:02:26,660 --> 00:02:33,650
and they want to understand your code but you have to remember this principle of code being easy to
28
00:02:33,650 --> 00:02:35,190
read.
29
00:02:35,210 --> 00:02:43,580
The only time you want to add comments to your code is well when something really really important is
30
00:02:43,580 --> 00:02:51,680
happening where it might be a little complex you first decide hey is this code written in a way that
31
00:02:51,950 --> 00:02:52,860
makes sense.
32
00:02:52,880 --> 00:03:03,490
For example if this was variable a and this was variable B well this might be really hard for somebody
33
00:03:03,490 --> 00:03:04,170
to understand.
34
00:03:04,180 --> 00:03:07,740
So you might say that this is is cool.
35
00:03:07,780 --> 00:03:15,790
Flag but before you add that comment you want to say to yourself maybe my code is hard to read.
36
00:03:15,860 --> 00:03:22,290
Maybe I should just change the variable to is cool to make it more understandable.
37
00:03:22,310 --> 00:03:29,780
Now this is something that you improve upon more and more and you do want to use comments as an extra
38
00:03:29,780 --> 00:03:31,800
tool to make your code understandable.
39
00:03:31,910 --> 00:03:36,820
Maybe you write code that six months from now you want to go back to understand what you did.
40
00:03:37,220 --> 00:03:42,410
But remember more comments doesn't necessarily mean better code.
41
00:03:42,410 --> 00:03:51,020
You want to be concise and keeping things simple while adding comments only when necessary to help others
42
00:03:51,050 --> 00:03:56,840
understand your code not trying to make your unreadable code more readable.
43
00:03:56,840 --> 00:04:01,400
We'll explore this topic and give you advice on it throughout the course.
44
00:04:01,400 --> 00:04:08,590
But remember this key developer fundamental because you're going to need it throughout your career.
45
00:04:08,630 --> 00:04:17,720
By the way this article over here has some really important points that I think you'll really benefit
46
00:04:17,720 --> 00:04:21,830
from especially in the commenting best practices.
47
00:04:21,830 --> 00:04:28,160
You can read some of the dos and don'ts and what some of the top programmers do when commenting.
48
00:04:28,250 --> 00:04:33,610
I know it sounds silly but it is an important concept that most courses overlook.
49
00:04:33,710 --> 00:04:36,780
So I highly recommend you read over this.
50
00:04:36,890 --> 00:04:41,110
I'll link to it in the resources and I'll see you in the next video.
5425
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.