Code conventions: Difference between revisions

From Nasqueron Agora
No edit summary
Line 5: Line 5:
* Define explicitly methods visibility, as several languages have different default values (e.g. private for C# class members, public for PHP methods)
* Define explicitly methods visibility, as several languages have different default values (e.g. private for C# class members, public for PHP methods)


== Python ==
== C ==
 
If you use [http://clang.llvm.org/docs/ClangFormat.html ClangFormat], a [https://github.com/dereckson/rabbitmq-tcl/blob/master/.clang-format .clang-format file] is available.
We follow [https://www.python.org/dev/peps/pep-0008/ PEP-8].


== PHP ==
== PHP ==
* K&R, 1TBS variant, including for functions
* K&R, 1TBS variant, including for functions
* 4 spaces as indent
* 4 spaces as indent
* The keywords true, false and null must be in lower case.
* The keywords true, false and null must be in lower case.
* Arrays use short syntax
* Array elements ends with a comma
== Python ==
We follow [https://www.python.org/dev/peps/pep-0008/ PEP-8].
== Rust ==
We follow Rust default style, described at https://aturon.github.io/. It's mainly a K&R, 1TBS variant.
Use trailing comma for elements in every struct/impl/etc.


== Shell scripts ==
== Shell scripts ==
UNIX agnosticism:
UNIX agnosticism:
* Don't assume absolue path, use `#!/usr/bin/env bash` and not `#!/bin/bash` (it could be elsewhere on BSD or Solaris)
* Don't assume absolue path, use `#!/usr/bin/env bash` and not `#!/bin/bash` (it could be elsewhere on BSD or Solaris)

Revision as of 02:19, 14 November 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)

C

If you use ClangFormat, a .clang-format file is available.

PHP

  • K&R, 1TBS variant, including for functions
  • 4 spaces as indent
  • The keywords true, false and null must be in lower case.
  • Arrays use short syntax
  • Array elements ends with a comma

Python

We follow PEP-8.

Rust

We follow Rust default style, described at https://aturon.github.io/. It's mainly a K&R, 1TBS variant.

Use trailing comma for elements in every struct/impl/etc.

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)