Instructor: Let's talk about
another developer fundamental.
And this one is commenting your code.
Up until now, you may have seen me comment,
add comments to our scripts.
For example,
right here, I added a comment of booleans.
And this tells the Python interpreter,
hey, this is a comment.
Don't run this.
It's just for me.
You can just ignore it and skip over to line 2.
And you saw that I simply did that in Python
with the # sign.
As soon as Python sees a # sign, it adds a comment.
And you can do that after a line as well.
I can say this assigns to a variable.
And although this may look like two lines,
it's actually just the word wrapping that's happening.
And you can see that the interpreter
just completely ignores these comments.
Now, commenting sounds very, very simple,
but it's an important concept.
And if you wanna be a good programmer,
in all languages, we have commenting,
but there's good ways and bad ways of commenting.
And this is something that comes with practice.
But here are some key guidelines.
When you're commenting your code,
the idea is that you're adding valuable comments.
That is, if I add a comment here that says,
hey, this is assign name variable a value of Andrei string.
A comment like this is not really good.
Why is that?
Well, because your code should be self-explanatory, right?
The idea is for us to write code that is easy to read,
easy to understand.
It's not trying to be clever.
Instead, it should read like English.
And any Python programmer
would know that here we're just simply adding Andrei
as a value of name.
We're assigning a variable.
And adding a comment like this that's self-explanatory
just adds clutter to your code.
So there's a trade-off here.
It's good to comment your code for,
let's say, if you're working on teams
and other developers come
and they wanna understand your code,
but you have to remember this principle
of code being easy to read.
The only time you wanna add comments to your code
is, well, when something really, really important
is happening
where it might be a little complex,
you first decide,
hey, is this code written in a way that makes sense?
For example, if this was variable a
and this was variable b,
well, this might be really hard for somebody to understand.
So you might say that this is
is cool flag,
but before you add that comment,
you wanna say to yourself,
hmm, maybe my code is hard to read.
Maybe I should just change the variable to is_cool
to make it more understandable.
Now, this is something that you improve upon more and more.
And you do wanna use comments as an extra tool
to make your code understandable.
Maybe you write code that six months from now
you wanna go back to understand what you did.
but remember,
more comments doesn't necessarily mean better code.
You want to be concise and keeping things simple
while adding comments only when necessary
to help others understand your code,
not trying to make your unreadable code more readable.
We'll explore this topic
and give you advice on it throughout the course.
But remember this key developer fundamental
because you're gonna need it throughout your career.
By the way, this article over here
has some really important points
that I think you'll really benefit from,
especially in the commenting best practices.
You can read some of the dos and don'ts
and what some of the top programmers do when commenting.
I know it sounds silly
but it is an important concept that most courses overlook.
So I highly recommend you read over this.
I'll link to it in the resources
and I'll see you in the next video.