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

Dieter Plaetinck dieter at plaetinck.be
Sat Feb 13 10:55:57 EST 2010


On Sat, 13 Feb 2010 16:32:24 +0100
Pierre Schmitz <pierre at archlinux.de> 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
+1
> * tabs have 8 characters

isn't the point of indentation with tabs just that everyone can choose
the width of the representation for himself?
unless you plan to use tabs for alignment, which i don't like.
tabs for indentation, spaces for alignment imho.

> * don't use more than 132 columns
where does this number come from?
> * opening braces are top right, closing are bottom left:
+1
> 
> function foo() {
> 	echo bar
> }

only for bash/C.
for sh, leave out the 'function' part (it's a bashism)

> * 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

fine by me

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

+1

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

source is a bashism. '.' is sh, but source is easier to grep for, so i
suggest to use 'source' when the script is bash and you're pretty sure
it will stay bash. '.' otherwise.
${bar} should only be used when it's needed.

Dieter



More information about the arch-dev-public mailing list