Code conventions: Difference between revisions

From Nasqueron Agora
(Created page with "== Shell scripts == UNIX agnosticism: * Don't assume absolue path, use `#!/usr/bin/env bash` and not `#!/bin/bash` (it could be elsewhere on BSD or Solaris) * Use `sh` as mus...")
 
No edit summary
Line 1: Line 1:
== All languages ==
* Don't use more complicated constructs like ternary operators
* [http://jeroendedauw.github.io/slides/craftmanship/functions/#/1 Keep functions short and simple].
== Python ==
We follow [https://www.python.org/dev/peps/pep-0008/ PEP-8].
== PHP ==
* K&R, 1TBS variant, including for functions
* 4 spaces as indent
== Shell scripts ==
== Shell scripts ==



Revision as of 00:19, 9 November 2015

All languages

Python

We follow PEP-8.

PHP

  • K&R, 1TBS variant, including for functions
  • 4 spaces as indent

Shell scripts

UNIX agnosticism:

  • Don't assume absolue path, use `#!/usr/bin/env bash` and not `#!/bin/bash` (it could be elsewhere on BSD or Solaris)
  • Use `sh` as must as possible, try to avoid `bash`, document exceptions rationale in your commits

Whitespaces:

  • One whitespace line between shebang and actual content
  • Indent with tabulations

File names:

  • We use hyphens (-) as separators, not underscores or camelcase.
  • Filename should start by a verb if it performs an action
  • Don't use .sh extensions (sometimes you'll see them on Phabricator pastes' titles, but it has been added there, so Phab knows shell syntax highlighting should be used)