X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=doc%2FCodingStyle;h=4ac0f189ff19973e31f170129d3e987193eeed9f;hp=fc70d3ef3dcee7f50c4c922f4dfc382cbcb5abf0;hb=4d59c02d51fbf50ff24d616b00296aa4cbb1ea5e;hpb=ffad02322624ab79fdad1a23a3aa83cd67376151;ds=sidebyside diff --git a/doc/CodingStyle b/doc/CodingStyle index fc70d3ef..4ac0f189 100644 --- a/doc/CodingStyle +++ b/doc/CodingStyle @@ -9,7 +9,7 @@ This document attempts to describe the preferred coding style for GiNaC. Different people have different ideas of how source code should be formatted to be most beautiful and/or useful to work with. GiNaC itself was developed -by a group of people whose ideas on these matters differred in some details. +by a group of people whose ideas on these matters differed in some details. It also evolved over the course of the years, and received contributions from outside. As a result, the GiNaC source is not in all places 100% consistent with the rules laid out in this document. Old code will @@ -63,8 +63,7 @@ same column on the screen, to make it look more tidy and clear. Here is an example that features both indentation and alignment: -class person -{ +class person { string name; // person's full name int age; // age in years }; @@ -90,12 +89,11 @@ exact same value the author of the code used. Take the "person" class definition from above as an example (here and in the following, ':' represents a Tab, while '.' represents a Space). Assume -that we had done both intendation and alignment with Tabs, with a tab-size +that we had done both indentation and alignment with Tabs, with a tab-size of 8: |-------|-------|-------|-------|-------|-------|------- <- tab stops -class person -{ +class person { ::::::::string name;::::// person's full name ::::::::int age;::::::::// age in years }; @@ -103,8 +101,7 @@ class person Now somebody who prefers a tab-size of 4 looks at the code: |---|---|---|---|---|---|---|---|---|---|---|---|---|--- <- tab stops -class person -{ +class person { ::::string name;::::// person's full name ::::int age;::::// age in years }; @@ -132,8 +129,7 @@ This is how our class definition should be entered using this scheme (remember, ':' are Tabs, '.' are Spaces): |-------|-------|-------|-------|-------|-------|------- <- tab stops -class person -{ +class person { ::::::::string name;..// person's full name ::::::::int age;......// age in years }; @@ -142,8 +138,7 @@ class person tab-size, and it still looks good: |---|---|---|---|---|---|---|---|---|---|---|---|---|--- <- tab stops -class person -{ +class person { ::::string name;..// person's full name ::::int age;......// age in years }; @@ -238,7 +233,7 @@ whitespace. One word: K&R, also known as "One True Brace Style", suitably extended for C++. The opening brace goes at the end of the line, except for function -bodies and classes. Really short functions can be written in one single line. +bodies. Really short functions can be written in one single line. if (a == b) { // do something @@ -284,8 +279,7 @@ bodies and classes. Really short functions can be written in one single line. // catchall } - class foo - { + class foo { public: foo(int i) : x(i) { @@ -301,6 +295,10 @@ bodies and classes. Really short functions can be written in one single line. int x; }; + namespace bar { + // a foo by any other name... + } + void foo::schwupp(char c) { // diwupp @@ -336,7 +334,7 @@ Names of header files end in ".h" (not ".hpp", ".H", ".hh", or ".hxx"). Don't place "using namespace std;", "using std::vector;" or anything like this into public library header files. Doing so would force the import of all or parts of the "std" namespace upon all users of the library, even if they don't -want it. Always fully qualify indentifiers in the headers. +want it. Always fully qualify identifiers in the headers. Definitions that are only used internally within the library but have to be placed in a public header file for one reason or another should be put into