Policies/Kdepim Coding Style: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{Construction}} | |||
== Purpose of this document == | |||
This document describes the recommended coding style for kdepim. Nobody is | |||
forced to use this style, but to have consistent formatting of the source code | |||
files it is strongly recommended to make use of it. | |||
{{Remember|1=In short: Kdepim coding style follows the | |||
{{ | [http://techbase.kde.org/Policies/Kdelibs_Coding_Style Kdelibs coding style].}} | ||
== Rules with test and automatic changes == | |||
*don't use any <TAB>s | *don't use any <TAB>s | ||
*The change script makes a substitution of any <TAB> with eight spaces. | |||
*The change works for the complete source, even within comments and strings. | |||
* | *That might be too much and change the vertical alignment of the code. | ||
*Trim the lines | |||
*Only single empty lines should be used. | |||
== Migration == | |||
As discussed at KDEPIM-Treff, Berlin, 3 March 2013, all the files of KDEPIM will | |||
For each rule, one can find one or two script(s). | be reviewed to follow the coding style. This will be done over a long time, | ||
directory after directory, for each of the | |||
.h and .cpp files. | rules defined above. For each rule, one can find one or two script(s). The | ||
first script is to check a single file or a complete directory for all .h and | |||
.cpp files. | |||
If present, the second script makes the changes for a single file or a complete | If present, the second script makes the changes for a single file or a complete | ||
directory for all .h and .cpp files. | directory for all .h and .cpp files. For some complicated situations, the | ||
For some complicated situations, the script makes no change. | script makes no change. | ||
=== The scripts === | |||
*don't use any <TAB>s | |||
==The scripts== | *coding-style-check-Tabs.sh | ||
*coding-style-change-Tabs.sh | |||
*The output of the check is: | |||
{{Output|<syntaxhighlight lang="php" line> | |||
The output of the check is: | /home/guy-kde/projects/kdepimlibs/ktnef/ktnefparser.cpp | ||
{{Output| | |||
1->308: Tab at 16: stream_ >> i; // i <- attribute type & name | 1->308: Tab at 16: stream_ >> i; // i <- attribute type & name | ||
2->311: Tab at 16: stream_ >> i; // i <- data length | 2->311: Tab at 16: stream_ >> i; // i <- data length | ||
3->326: Tab at 22: case attATTACHMENT: // try to get attachment info | 3->326: Tab at 22: case attATTACHMENT: // try to get attachment info | ||
4->367: Tab at 16: stream_ >> u; // u <- checksum | 4->367: Tab at 16: stream_ >> u; // u <- checksum | ||
</syntaxhighlight>}} | |||
This shows: | |||
* the name of the file which is under test. | |||
* the number of occurence, the line number, the position found and the line | |||
itself. | |||
=== Trim the lines === | |||
{{Input| <syntaxhighlight lang="php" line> | |||
coding-style-check-Trim.sh | |||
coding-style-change-Trim.sh | |||
</syntaxhighlight>}} | |||
=== | === Check for multiple empty lines === | ||
{{Input| <syntaxhighlight lang="php" line> | |||
coding-style-check-Twice.sh | |||
coding-style-change-Twice.sh | |||
</syntaxhighlight>}} | |||
The output of the check is: | The output of the check is: | ||
{{Output| | {{Output| <syntaxhighlight lang="php" line> | ||
/home/guy-kde/projects/kdepimlibs/syndication/rss2/enclosure.cpp | |||
1->25: next empty line found | 1->25: next empty line found | ||
2->26: next empty line found | 2->26: next empty line found | ||
3->30: next empty line found</ | 3->30: next empty line found | ||
</syntaxhighlight>}} | |||
This shows: | |||
* the name of the file which is under test. | |||
* the number of occurrences and the line numbers. |
Revision as of 15:42, 6 March 2013
Under Construction |
---|
This is a new page, currently under construction! |
Purpose of this document
This document describes the recommended coding style for kdepim. Nobody is forced to use this style, but to have consistent formatting of the source code files it is strongly recommended to make use of it.
Remember |
---|
In short: Kdepim coding style follows the Kdelibs coding style. |
Rules with test and automatic changes
- don't use any <TAB>s
- The change script makes a substitution of any <TAB> with eight spaces.
- The change works for the complete source, even within comments and strings.
- That might be too much and change the vertical alignment of the code.
- Trim the lines
- Only single empty lines should be used.
Migration
As discussed at KDEPIM-Treff, Berlin, 3 March 2013, all the files of KDEPIM will be reviewed to follow the coding style. This will be done over a long time, directory after directory, for each of the rules defined above. For each rule, one can find one or two script(s). The first script is to check a single file or a complete directory for all .h and .cpp files.
If present, the second script makes the changes for a single file or a complete directory for all .h and .cpp files. For some complicated situations, the script makes no change.
The scripts
- don't use any <TAB>s
- coding-style-check-Tabs.sh
- coding-style-change-Tabs.sh
- The output of the check is:
/home/guy-kde/projects/kdepimlibs/ktnef/ktnefparser.cpp 1->308: Tab at 16: stream_ >> i; // i <- attribute type & name 2->311: Tab at 16: stream_ >> i; // i <- data length 3->326: Tab at 22: case attATTACHMENT: // try to get attachment info 4->367: Tab at 16: stream_ >> u; // u <- checksum
This shows:
- the name of the file which is under test.
- the number of occurence, the line number, the position found and the line
itself.
Trim the lines
coding-style-check-Trim.sh coding-style-change-Trim.sh
Check for multiple empty lines
coding-style-check-Twice.sh coding-style-change-Twice.sh
The output of the check is:
/home/guy-kde/projects/kdepimlibs/syndication/rss2/enclosure.cpp 1->25: next empty line found 2->26: next empty line found 3->30: next empty line found
This shows:
- the name of the file which is under test.
- the number of occurrences and the line numbers.