Difference between revisions of "Policies/Kdepim Coding Style"

Jump to: navigation, search
(First line, last line(s) may not be empty)
(First line, last line(s) may not be empty)
Line 96: Line 96:
  
 
The output of the '''check''' script is:
 
The output of the '''check''' script is:
  {{Output|1=check the file }}
+
  {{Output|1=check the file /home/guy-kde/Software/coding-style-check/trim.cpp
 +
The first line is empty}}
 
      
 
      
 
This shows:
 
This shows:

Revision as of 19:39, 6 March 2013

Under construction.png
 
Under Construction
This is a new page, currently under construction!


Contents

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.

In short: Kdepim coding style follows the Kdelibs coding style.

The rules for Kdepim

  • don't use any <TAB>s
  • Trim the lines
  • Only single empty lines should be used
  • The first line, the last line(s) may not be empty

Migration

As discussed at the KDEPIM meeting, 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.

One can use the scripts for own work.It is recommanded to use them in this order.

The scripts

don't use any <TAB>s

  • coding-style-check-Tabs.sh
  • coding-style-change-Tabs.sh

The output of the check script is:

check the file /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
a  b    c            d

This shows:

  • the name of the file which is under test.
  • the number of occurence(a), the line number(b), the position found(c) and the line itself(d).

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 changes the vertical alignment of the code.

Trim the lines

  • coding-style-check-Trim.sh
  • coding-style-change-Trim.sh

The output of the check script is:

check the file /home/guy-kde/Software/coding-style-check/trim.cpp
1->51: Space(s) at end of line (28):   QVariant m_matchData;

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.


The change script:

  • remove all trailing space(s).

Only single empty lines should be used

  • coding-style-check-Twice.sh
  • coding-style-change-Twice.sh

The output of the check script is:

check the file /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.

The change script:

  • removes all the next empty line(s).

First line, last line(s) may not be empty

Some of the sources have a first empty lines, some have one or more empty last line(s).

  • coding-style-check-First-Last.sh
  • coding-style-change-First-Last.sh

The output of the check script is:

check the file /home/guy-kde/Software/coding-style-check/trim.cpp
The first line is empty

This shows:


KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal