dwyl / style-guide

:newspaper: dwyl's visual and coding style guide
GNU General Public License v2.0
24 stars 13 forks source link

dwyl Style Guide

A style guide is a set of standards [which] establish and enforce style to improve communication.

_https://en.wikipedia.org/wiki/Style_guide_

This style guide is a work in progress and is being put together over the course of #dwylsummer and the rest of our work.

contributions welcome Please open an issue if you have an questions or comments at all!

For now, the visual and coding styles will live in the same repo. If the size of this readme gets out of hand or if we have a lot of requests to separate them, we'll do so.

Contents Guide

Why?

Consistency.

Every developer likes to do things their own way.
Even though we have our own idea of what maintainable code looks like, the important thing isn't how many spaces we indent our code with but that everything is consistent so new people don't have to work through personal formatting quirks of previous developers and can focus on the code.

General

Indentation

2 space indentation (see our developer setup guide for tips on setting this kind of thing up in your text editor).

Intelligently commenting your code

We favour the intelligent approach.

Many developers (not us) believe that well-written code doesn't need comments. Whilst it's true that adding too many comments to your code makes it unreadable. The key is to put yourself in the shoes of the next person who has to work with your code.

If you feel your code is as simple as it can be but what it doesn't isn't immediately obvious, then add a comment.
Good examples of this are when something in your code in one location necessarily has an impact elsewhere.

//JavaScript example
else {
  mod = moduleName.replace('.js', '.\.js'); //escape .js for regex
}
/*CSS example*/
.article {
  position: relative; /*contains `.quote` which is positioned absolutely*/
  ...
}

Quotes

Use ' single quotes ' everywhere, except:


Git

Issues

Commits

commit-message-referenced-from-issue paired-commit-message

Pull Requests

Good pull requests (PR) reduce the back and forth required between the person submitting the PR and the assigned reviewer, saving everyone time.

For our guidelines on contributing pull requests to dwyl projects, please see: https://github.com/dwyl/contributing

Reviewing pull requests

add-comment-inline-in-pr-comment-box

Naming repos


Markdown

This is a good reference for markdown syntax.
For readability, we use:


CSS

General points

Indentation

CSS indentation should mirror the HTML structure.

.article {}
  .article-quote {}

Naming conventions

For now, we don't use BEM CSS naming conventions as it doesn't provide the flexibility we feel we need during the early stages of our work.
Here's what we do use:

Grouping properties


JavaScript

var example_object = {
    name: 'dwyl',
    age: 1 //<-- Having a comma after the '1' would be a 'trailing comma' 
};

Variable naming

https://github.com/dwyl/summer-2015/issues/22