CodingStyle

Chair for Computer Aided Medical Procedures & Augmented Reality
Lehrstuhl für Informatikanwendungen in der Medizin & Augmented Reality

THIS WEBPAGE IS DEPRECATED - please visit our new website

Back to main page.

CodingStyle

Codingstyle for the UbiTrack? Library. Check back often for new rules. All rules are guidelines only. You are advised to always know what you're doing.

See also the PointerGuide

Whitespace

  • No whitespace after the end of a line
  • Like this: (Oops.. This isn't Whitesmith after all.. Emacs-Style anyone?)
class Foo
{
public:
    Foo( int x )
        : m_myMember( x )
        , m_member2( 3 )
    {
    }

    int doIt()
    {
        ...
    }
}
  • Tabs are 4 spaces and indent with tabs only.
  • Space after opening parenthesises and before closing parenthesises (e.g. 'doEverything( universe, hammer )' or 'template< foo >')

Naming-Conventions

  • Class and Namespaces: start in upper case and continue camel case (e.g. ClassName?)
  • Variables: start in lower case and continue camel case (e.g. someStrangeVariable)
  • Member Variables: are prefixed by "m_" (e.g. m_anotherStrangeVariable)
  • Object Methods: start lower case and continue camel case (e.g. veryImportantMethod() )

Hierarchy/Files

  • Every namespace belongs in its own subdirectory
  • Headerfiles contain as little code as possible
  • .cpp for Code and .h for Header-Files

emacs-Style

  • Here is an emacs c-style for use with cc-mode
  • Still useful for non emacs users, since it specifies the ubitrack style in great detail


(defconst ubitrack-c-style
  '(
    (c-basic-offset                 . 4)
    (c-comment-only-line-offset . 0)
    (c-echo-syntactic-information-p . t)
    (c-toggle-auto-hungy-state      . t)
    (c-cleanup-list . (
             empty-defun-braces
             defun-close-semi
             list-close-comma
             scope-operator
             space-before-funcall
             compact-empty-funcall))
    (c-hanging-braces-alist . ((class-open after before)
                (class-close after before)
                (defun-open after before)
                (defun-close after before)
                (inline-open after before)
                (inline-close after before)
                (brace-list-open)
                (brace-list-close)
                (brace-list-intro)
                (brace-list-entry)
                (brace-entry-open)
                (block-open after)
                (block-close . c-snug-do-while)
                (statement-case-open after before)
                (substatement-open after before)
                (extern-lang-open after before)
                (extern-lang-close after before)
                (namespace-open)
                (namespace-close after)
                (inexpr-class-open after before)
                (inexpr-class-close after before)))
    (c-hanging-colons-alist . ((case-label after)
                (label after)
                (access-label after)
                (member-init-intro before)
                (inher-intro before)))
    (c-offsets-alist .
             ((string                . c-lineup-dont-change)
              (c                     . c-lineup-C-comments)
              (comment-intro         . c-lineup-comment)
              (class-open            . 0)
              (class-close           . 0)
              (defun-open            . 0)
              (defun-close           . 0)
              (defun-block-intro     . +)
              (inline-open           . 0)
              (inline-close          . 0)
              (extern-lang-open      . 0)
              (extern-lang-close     . 0)
              (func-decl-cont        . 0)
              (topmost-intro         . 0)
              (topmost-intro-cont    . 0)
              (member-init-intro     . +)
              (member-init-cont      . -2) ; woher kommt das +2?
              (inher-intro           . +)
              (inher-cont            . -2)
              (block-open            . 0)
              (block-close           . 0)
              (brace-list-open       . 0)
              (brace-list-close      . 0)
              (brace-list-intro      . 0)
              (brace-list-entry      . 0)
              (brace-entry-open      . 0)
              (statement             . 0)
              (statement-cont        . 0)
              (statement-block-intro . +)
              (statement-case-intro  . +)
              (statement-case-open   . 0)
              (substatement          . +)
              (substatement-open     . 0)
              (case-label            . 0) ; +?
              (access-label          . -)
              (label                 . 0)
              (do-while-closure      . 0)
              (else-clause           . 0)
              (catch-clause          . 0)
              (comment-intro         . 0)
              (arglist-intro         . +)
              (arglist-cont          . c-lineup-arglist)
              (arglist-cont-nonempty . c-lineup-arglist)
              (arglist-close         . c-lineup-arglist)
              (stream-op             . c-lineup-streamop)
              (inclass               . +) ; here
              ;(cpp-macro             . 0)
              (cpp-macro-cont        . c-lineup-dont-change)
              (friend                . 0)
              (extern-lang-open      . 0)
              (extern-lang-close     . 0)
              (inextern-lang         . +)
              (namespace-open        . 0)
              (namespace-close       . 0)
              (innamespace           . 0)
              (template-args-cont    . (c-lineup-template-args +))
              (inexpr-statement      . +)
              (inexpr-class          . +)
              ))
    )
  "c style for ubitrack")

  • Other useful cc-mode code snippets for use in the .emacs file
(defun my-c-mode-common-hook ()
  (c-add-style "ubitrack" ubitrack-c-style t)
  (setq tab-width 4)
  (c-toggle-auto-hungry-state t)
  (define-key c-mode-base-map "\C-m" 'newline-and-indent)
  (modify-syntax-entry ?_ "w" c++-mode-syntax-table)
  (modify-syntax-entry ?_ "w" c-mode-syntax-table)
  (setq paragraph-start
        (concat paragraph-start
                ;; include some common HTML tags
                "\\|</?\\([ou]l\\|li\\|d[tdl]\\|p\\|br\\)>"))
  )

(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)


Edit | Attach | Refresh | Diffs | More | Revision r1.11 - 22 Dec 2008 - 13:49 - PeterKeitler

Lehrstuhl für Computer Aided Medical Procedures & Augmented Reality    rss.gif