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

Establish code design/format guidelines #85

Open
sharon-wang opened this issue Nov 20, 2020 · 3 comments
Open

Establish code design/format guidelines #85

sharon-wang opened this issue Nov 20, 2020 · 3 comments
Labels
documentation Improvements or additions to documentation repo renovation Improvements to this GitHub repository

Comments

@sharon-wang
Copy link
Member

We should decide on how we'd like to format our code and configure an auto-formatter/linter to enforce the guidelines we set out.

We may want to create a markdown document with these guidelines.

@sharon-wang sharon-wang added documentation Improvements or additions to documentation repo renovation Improvements to this GitHub repository labels Nov 20, 2020
@sharon-wang
Copy link
Member Author

We've decided that multi-line comment format, i.e.

/*
 *
 */

is reserved for documentation outside of functions/code.

// will be used for single line comments only, such as in-line documentation with code.


All comments should use sentence case (i.e. start with a capital), but only multi-line comments should include periods. Single line comments should not end with a period.

Multi-line example

/**
 * Retrieve the favicon path.
 * 
 * @return {String} The absolute or relative path from the site origin to the favicon.
 */

Single line example

// Default favicon path is at the root of the origin

@vezwork
Copy link
Member

vezwork commented Dec 29, 2020

We've decided that early returns in functions are preferred over returning once at the end of a function, i.e.
✅ PREFERRED:

function example(input) {
  if (input !== null) {
    return true;
  }
  return false;
}

❌ NOT-PREFERRED:

function example(input) {
  const result = false;
  if (input !== null) {
    result = true;
  }
  return result;
}

Justification: early returns make it easier to understand a code-path of a function without having to read the entire function. They also make it so that you do not have to think about and keep track of function-scoped variables while reading the function.

Note that there are cases where it could be better to not early return, for example if you have to cleanup resources before returning, it may be better to have that cleanup code once at the end of the function before you return.

@vezwork
Copy link
Member

vezwork commented Jan 31, 2021

It would be good to have html style opinions. The formatting is quite strange and not especially readable right now. (Sharon thinks so too).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation repo renovation Improvements to this GitHub repository
Projects
None yet
Development

No branches or pull requests

2 participants