Skip to content

👍 Trying to define good code. Will be a full stack web development guide, eventually.

Notifications You must be signed in to change notification settings

erowsika/code-guide

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 

Repository files navigation

Code Guide

All code in any code-base should look like a single person typed it, no matter how many people contributed.

General

  • write DRY (Don't repeat yourself) Code
  • do document and comment your code
  • consistent naming scheme per language (further defined in the language guidelines)
  • avoid deep nesting of code
  • keep short line length

Tabs versus spaces

  • Use tabs for indenting to visualize your codes hierarchy
  • Use spaces for indenting to align your code

Tabs for hierarchy

function alertSomething() {
»   alert('Something!');
}

Spaces for aligning

var foo = '',
····bar = '',
····baz = '';

Both mixed

function alertSomething() {
»   var foo = 'Something',
»   ····bar = '!';

»   alert(foo + bar);
}

This is a really helpful practice. Code can be aligned and it will still be aligned for any monospaced font but you also preserve the semantic tab and every developer can decide his tab size by personal preference.

Version Control (e.g. Git)

Commit Message Format (inspired by Angular Contributing Guidelines)

Each commit message consists of a header and a body:

<type>: <subject>
<body>

Any line of the commit message cannot be longer 100 characters! This allows the message to be easier to read on GitHub as well as in various Git tools.

Type

Must be one of the following:

  • feat: A new feature
  • fix: A bug fix
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • refactor: A code change that neither fixes a bug nor adds a feature
  • perf: A code change that improves performance
  • test: Adding missing tests
  • chore: Changes to the build process or auxiliary tools and libraries such as documentation generation
  • content: Changes to site content or texts for websites or marketing

Subject

The subject contains succinct description of the change:

  • use the imperative, present tense: "change" not "changed" nor "changes"
  • don't capitalize first letter
  • no dot (.) at the end

In case you want to commit a fix, use the present passive voice to describe the problem you fix:

fix: passwords aren't encrypted

fix: emojis are missing

instead of fix: encrypt passwords or fix: add emojis

Body

Just as in the subject, use the imperative, present tense: "change" not "changed" nor "changes". The body further specifies what changed and may include the motivation for the change and contrast this with previous behavior.

Frontend Code HTML and CSS

JavaScript

PHP

  • follow PSR-2
  • follow PHPDoc
    • the @param tag is followed by two spaces, the argument type, two more spaces and the variable name
    • use the short term for all primitives

Ruby

About

👍 Trying to define good code. Will be a full stack web development guide, eventually.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published