[arch-dev-public] Let's agree on a common coding style

Allan McRae allan at archlinux.org
Sat Feb 13 18:29:02 EST 2010

On 14/02/10 01:32, Pierre Schmitz wrote:
> Hi all,
> while looking at our devtools, other scripts we have written together and even
> PKGBUILDs, you will see as much different types of indention, bracing etc. as
> there are authors.
> This always annoyed me and as I just watched Greg's talk at fosdem about
> committing kernel patches I'll go ahead and will start with devtools.
> I would suggest to use this coding style:
> * indent with tabs
> * tabs have 8 characters
> * don't use more than 132 columns
> * opening braces are top right, closing are bottom left:
> function foo() {
> 	echo bar
> }
> * if and for statements are like this:
> if true; then
> 	do something
> else
> 	do something else
> fi
> for i in a b c; do
> 	echo $i
> done

These all agree with the makepkg coding style (apart from the "function" 
part which has been adjusted) so I am fine with this.

> * use single quotes if a string does not parseable content

Meh, do not really make a difference.

> We could also talk about using `` or $(); source vs. .; $foo vs. ${bar} etc..
> But that's probably too much.

Backticks suck because they are non-nestable.  Always $().  Braces I do 
not care about.

This was added to the guidelines wiki page:
Add these lines at the bottom of the document to enforce our guideline:

# vim: set noexpandtab tabstop=8 shiftwidth=8 textwidth=132 autoindent
# kate: indent-mode normal; indent-width 8; tab-indents on; tab-width 8; 
word-wrap on; word-wrap-column 132

What about adding ones for emacs, geany, eclipse, ...    I.e., I think 
adding these a waste of time as it will always be an incomplete list.

How about test style:
if [ $FOO - eq 0 ]
if (( ! $FOO ))
makepkg has switched to the later.

In then end, none of our coding projects is really big (apart from 
pacman which has its own guidelines) so as long as indentation is 
consistent within a project (tabs vs spaces), I could not care less...


More information about the arch-dev-public mailing list