Alrighty.
So let's talk about comments and what are good comments and what are bad comments.
Right.
So first of all you have a class called math utils.
And we got two methods right here.
And you do not have to understand what's going on.
This is exactly why we're creating comments.
Right.
So first of all let's just recap that we can write inline comments just like that.
Or we can use a forward slash and an asterisk to create, um, a comment for multiple lines.
Simply hit enter, he will create another asterisk, and then we can close it with another slash.
So now we have a multi-line comment that we can use.
You can use them for uh, methods for classes and so on.
So just a very short recap.
Now what would be a good and a bad name for those methods right here.
You know, calculate factorial is a very good name as we have already discovered.
It tells you that this method calculates a factorial for a specific number.
So a bad.
And this is important.
A bad practice here for common would be to write down calculates the factorial number.
Right?
It's so obvious because it's already clarified by the name of the method itself.
So instead of writing such things like what is going on, do not do what, do tell why, so not what,
but why.
Okay, so instead of telling what's going on, tell why it's going on and why it's important.
So for example this calculation here uses a recursive approach.
So we should not write down uh using a recursive approach for calculation because that is describing
what is going on.
We are using a recursive approach.
The good comment would be to explain why we are using a recursive approach here.
And then because it's more intuitive.
All right.
This is saying we are doing that with a reason because it's more intuitive.
Now every developer will be able to find out what's going on here right now.
Don't get me wrong, the comment is also saying that we are using a recursive approach because I would
not be able to see this within a second or two seconds.
I would have to take a look and then go ahead.
Oh yeah, maybe that's recursive, right?
But you don't want to do it that way.
Add a comment, tell what's going on recursive approach.
But then add a because and explain why it's going on.
Right.
So always focus on comments that are more related to why something is happening over what is happening
in general.
Great.
So let's do this again for this binary search method.
Here.
Obviously this method performs a binary search.
Maybe it would be interesting to get some more information about what's going on here in depth, but
that's not the main reason to write a comment.
If you want to know how to perform a binary search, you should dig deeper in data structure and algorithms
and learn how to perform a binary search.
They should not all well.
It's not so exclusive that it should be part of our comment, right?
So instead of telling what's going on, we want to say why we're using that approach.
We're using the binary approach because we want to improve the performance for large data sets.
And then you can add something like using binary search here.
Uh, there you go to improve the performance for large data sets.
Alrighty.
So what are we doing.
We're using the binary search.
Even though it's obvious from the name.
Still okay to add it here, but add the reason why you're adding the binary search to improve the performance.
And if it's not important to add this information because there is no alternative, obviously binary
search was the best way, then do not write a comment at all.
If you don't need to add a comment, do not do it just for the sake of it.
Only add comments if they are important, if they help other developers to understand what's going on
and why you are making that decision to add that specific method, class, interface or whatever.