Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of unnecessary comments #88

Closed
NikitaLejnev opened this issue Dec 31, 2021 · 8 comments
Closed

Get rid of unnecessary comments #88

NikitaLejnev opened this issue Dec 31, 2021 · 8 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@NikitaLejnev
Copy link
Contributor

Idea

Comments are supposed to improve readability and make it easier to reason about the code. Currently there are a lot of comments that are redundant. There is no sense in commenting a function if its name clearly describes its purpose. There is no sense in commenting blocks of code in a large method, it is much better to extract them into their own functions.

Todo

  • If you see a comment that doesn't add important information, please remove it.
  • If you want to comment something, please consider another way of communicating what you're trying to achieve.
@NikitaLejnev NikitaLejnev added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Dec 31, 2021
@Nokkvi
Copy link

Nokkvi commented Jan 1, 2022

I agree that many comments in the repo add little to no value, can I take this issue?

@William-McGonagle
Copy link
Member

William-McGonagle commented Jan 1, 2022

I agree that comments are supposed to improve readability, but we want the onboarding process for new contributors to be as quick as possible, and that is done through somewhat redundant comments. So, if you can find a way to make a redundant comment less redundant, do that, but don't remove comments that are already there.

https://mitcommlab.mit.edu/broad/commkit/coding-and-comment-style/

We are using the MIT guide for commenting, and on top of that, we have been using Google's idea that comments should break up code flow. What this means is in the example below, a comment should be used to break up the separate ideas in the code (just like a period or comma in a sentence), as it increases readability.

Bad:

// Create the Badge and Text
var resultTitle = "\033[1m";
if (result == true) resultTitle += "\033[1;37;42m PASSED ";
if (result == false) resultTitle += "\033[1;37;41m FAILED ";
resultTitle += "\033[22m";
resultTitle += "\033[0m";
return `${resultTitle} ${text}`;

Good:

// Set Title to Be Bold
var resultTitle = "\033[1m";

// Create the Badge Text
if (result == true) resultTitle += "\033[1;37;42m PASSED ";
if (result == false) resultTitle += "\033[1;37;41m FAILED ";

// Unbold Title
resultTitle += "\033[22m";
resultTitle += "\033[0m";

// Log to Console
return `${resultTitle} ${text}`;

@NikitaLejnev
Copy link
Contributor Author

@William-McGonagle The point is to separate implementation details from higher level logic so you can get the general idea of what the method is doing without looking at the concrete implementation. Conversely, if you need to see how the function is implemented you look at it. I often extract the commented blocks into functions that are named after the comments. Two birds with one stone.

@William-McGonagle
Copy link
Member

@NikitaLejnev I do have to say- I really like the new utility functions that you have added as they reduce the need for comments, but in the places like Sequelize references or high-level express stuff, we should keep them in because it makes the code easier for the new commiters.

@NikitaLejnev
Copy link
Contributor Author

@William-McGonagle Fair enough. Thank you for being open to discussing ideas and suggestions. I like your idea and love the way you handle the project.

@Nokkvi
Copy link

Nokkvi commented Jan 1, 2022

@William-McGonagle, possibly I'm not understanding correctly, but my assumption for this issue was for removing comments that don't add value.

A example I found in the code:

function TokenizeString(input) {
  // Make it Lowercase
  const lowercase = input.toLowerCase();

  // Switch Around Similar Looking Symbols
  let partsRemoved = lowercase;
  partsRemoved = partsRemoved.replace(/\$/g, "s");
  partsRemoved = partsRemoved.replace(/@/g, "a");

  // Return the Final Result
  return partsRemoved;
}

Here the top and bottom comments are not adding value because the following line describes exactly the same thing.
But the middle comment adds value as it is not immediately obvious what that part of the code does.

Just my 2 cents, but I would like to keep working on this project, as I like the idea you've got here.``

@William-McGonagle
Copy link
Member

@Nokkvi I would agree with your point that the first and last comment don't add value. But you are right that the middle comments should be kept because they somewhat help to explain the flow.

@Nokkvi
Copy link

Nokkvi commented Jan 2, 2022

#93

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants