views:

322

answers:

2

How can two developers work on a same C++ code base such that they can work transparently ? Is there any common indentation style for C++ code such that once it is established, the two developers can produce code with the same indentation level.

I have found Emacs very aggressive for Indentation, it tries to force its way, while Vi is pretty forgiving. But the emacs styles(mixed tabs and spaces) are not that much friendly to Vim.

+6  A: 

What I did when I managed a small team was I used a check-in hook that called the BSD program "indent", which forced everybody's code into the same indentation style. See http://stackoverflow.com/questions/284259/enforcing-a-coding-style

Paul Tomblin
This approach should be preferred much more, I think.
weiji
+11  A: 

Get Emacs to do what you want.

From my ~/.emacs file:

(defun my-c-mode-common-hook ()
  (local-set-key "\C-h" 'backward-delete-char)
  ;; this will make sure spaces are used instead of tabs
  (setq tab-width 4 indent-tabs-mode nil)
  (setq indent-tabs-mode 'nil)
  (setq c-basic-offset 4)
  (c-set-offset 'substatement-open 0)
  (c-set-offset 'statement-case-open 0)
  (c-set-offset 'case-label 0)
  (c-set-offset 'brace-list-open 0)
)

(add-hook 'c-mode-hook 'my-c-mode-common-hook)
(add-hook 'c++-mode-hook 'my-c-mode-common-hook)
(add-hook 'perl-mode-hook 'my-c-mode-common-hook)
(add-hook 'cperl-mode-hook 'my-c-mode-common-hook)
(add-hook 'emacs-lisp-mode-hook 'my-c-mode-common-hook)
(add-hook 'nroff-mode-hook 'my-c-mode-common-hook)
(add-hook 'tcl-mode-hook 'my-c-mode-common-hook)
(add-hook 'makefile-mode-hook 'my-c-mode-common-hook)
kmarsh
That is pretty much what I was looking for. I just have to find the equivalent indentation rules for Vim counterpart.
hasan
I am googling for cinoptions(in vim) for the equivalent style. I hope I can land on the equivalent indentation style.
hasan