Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen gezeigt.

Link zu dieser Vergleichsansicht

Nächste Überarbeitung Beide Seiten der Revision
private:codingstyle [2013/04/18 22:44]
Patrick Wacker angelegt
private:codingstyle [2013/04/19 00:05]
Patrick Wacker first statements taken place
Zeile 1: Zeile 1:
 +
 +
 +//80 characters line - the + is at character 74
 +
 +--------------------------------------------------------------------------+-----
 +
 +//the following line starts with a tabulator
 +
 + < tab!
 +
 +
 ====== Coding Style ====== ====== Coding Style ======
  
-This documents ​discripes ​the coding style I prefer in the most cases+==== Indroduction ==== 
 + 
 +This documents ​discribes ​the coding style I prefer in the most cases
 and most other situations as well. and most other situations as well.
  
 In general I like the coding style of the linux kernel and most parts In general I like the coding style of the linux kernel and most parts
 of the descriptions made here are identical to the linux kernel. of the descriptions made here are identical to the linux kernel.
 +
 +=== Editing this document ===
 +
 +The text for this docuemnt is written with the syntax that dokuwiki supports.
 +See https://​www.dokuwiki.org for more details.
 +
 +But this document should be easy readable as plain text as well. So do not
 +use any fancy looking html outputs.
 +
 +Only the following dokuwiki syntax options should be used:
 +
 +<​code>​
 +**text** for bold text
 +__text__ for underlined text
 +==== header ==== for chapters
 +</​code>​
 +
 +each code expample must be intented with a tabulator! (not spaces!)
 +[This is automaticaly displayed as code examples!]
 +
 +
 +
 +
 +
 +--------------------------------------------------------------------------+-----
 +
 +
 +
 +===== Coding style =====
 +
 +This documents discripes the coding style I prefer. Coding style is very
 +personal, and I won't force my views on onybody, but this is what goes for
 +anything that I have to be able to maintain, and I'd prefer it for most
 +other things too.
 +
 +Please at least consider the points made here.
 +
 +First off, I'd suggest printing out a copy of the GNU coding standards,
 +and NOT read it.  Burn them, it's a great symbolic gesture.
 +
 +Anyway, here goes:
 +
 +
 +==== Indentation ====
 +
 +Tabs are 8 characters, and thus indentations are also 8 characters.
 +
 +Rationale: The whole idea behind indentation is to clearly define where
 +a block of control starts and ends. Especially when you've been looking
 +at your screen for many hours, you'll find it a lot easier to see how 
 +the indentation works if you have large indentations.
 +
 +Now, some people will claim that having 8-character indentations makes
 +the code move too far to the right, and makes it hard to read on a
 +80-character terminal screen. ​ The answer to that is that if you need
 +more than 3 levels of indentation,​ you're screwed anyway, and should fix
 +your program.
 +
 +In short, 8-char indents make things easier to read, and have the added
 +benefit of warning you when you're nesting your functions too deep.
 +Heed that warning.
 +
 +The preferred way to ease multiple indentation levels in a switch statement is
 +to align the "​switch"​ and its subordinate "​case"​ labels in the same column
 +instead of "​double-indenting"​ the "​case"​ labels. ​ E.g.:
 +
 + switch (suffix) {
 + case '​G':​
 + case '​g':​
 + mem <<= 30;
 + break;
 + case '​M':​
 + case '​m':​
 + mem <<= 20;
 + break;
 + case '​K':​
 + case '​k':​
 + mem <<= 10;
 + /* fall through */
 + default:
 + break;
 + }
 +
 +
 +Don't put multiple statements on a single line unless you have
 +something to hide:
 +
 + if (condition) do_this;
 +   do_something_everytime;​
 +
 +Don't put multiple assignments on a single line either. ​ Kernel coding style
 +is super simple. ​ Avoid tricky expressions.
 +
 +Outside of comments, documentation and except in Kconfig, spaces are never
 +used for indentation,​ and the above example is deliberately broken.
 +
 +Get a decent editor and don't leave whitespace at the end of lines.
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
  
  
Projektwerkzeuge