Code conventions: Difference between revisions

From Nasqueron Agora
(→‎PHP: The keywords true, false and null must be in lower case. (http://devcentral.nasqueron.org/D159))
Line 3: Line 3:
* Don't use more complicated constructs like ternary operators
* Don't use more complicated constructs like ternary operators
* [http://jeroendedauw.github.io/slides/craftmanship/functions/#/1 Keep functions short and simple].
* [http://jeroendedauw.github.io/slides/craftmanship/functions/#/1 Keep functions short and simple].
* Define explicitly methods visibility, as several languages have different default values (e.g. private for C# class members, public for PHP methods)


== Python ==
== Python ==

Revision as of 17:45, 18 August 2016

All languages

  • Don't use more complicated constructs like ternary operators
  • Keep functions short and simple.
  • Define explicitly methods visibility, as several languages have different default values (e.g. private for C# class members, public for PHP methods)

Python

We follow PEP-8.

PHP

  • K&R, 1TBS variant, including for functions
  • 4 spaces as indent
  • The keywords true, false and null must be in lower case.

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)