Code formatting is a religious matter. There is no right answer. However, consistency matters very much, much more than the particular coding style used. The one used by astrometry.net is the following.

For C code

  • Tab characters for indenting up to the current indentation level, then spaces to indent anything further. This allows any editor choice for tabstop width to look exactly correct. Imagine a function call that spans two lines; if one uses spaces on the second line for indentation further than the indent level of the first character of the function name on the previous line, then the indentation will always look correct no matter the tabstop setting.
  • Curly brace on the same line always (k&r).
  • To automatically make your code fit this using astyle, run
    astyle --style=java -twpn myfile.c
    
  • Generally, our coding style is pretty much the same as the kernel's. An absolute adherence to the 8-spaces-per-tab is not necessary though. See http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/

Example for C code:

void myfunc(int foo) {
........bar(foo, baz, bob
........    notice_spaces)
........if (foo)
................return;
}

where a tab is displayed as eight consecutive .'s.

Emacs config

It's not quite right - add an extra space in front of the *\ that ends a multi-line comment.

(setq-default tab-width 4)
(setq-default indent-tabs-mode t)
(setq c-basic-offset 4)
(setq tab-stop-list '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80))
; Don't need this one, I think (setq c-lineup-C-comments 1)

Vim config

set tabstop=8
set shiftwidth=8
set noexpandtab

Also, if one prefers 4 for their tabstops, both tabstop=8 and shiftwidth=8 should be switched to 4.

For Python code

Python code is formatted with 4 spaces per indent, and should follow PEP 8.