Policies/Frameworks Coding Style: Difference between revisions

From KDE TechBase
(Initial stub for KF5 coding style)
 
(Add section "Variable Declarations" with an updated example)
Line 4: Line 4:
* 4 spaces
* 4 spaces
* no tabs
* no tabs
== Variable Declarations ==
* Each variable declaration on a new line
* Each new word in a variable name starts with a capital letter (so-called camelCase)
* Avoid abbreviations
* Take useful names. No short names, except:
** Single character variable names can denote counters and temporary variables whose purpose is obvious
* Variables and functions start with a lowercase letter
Example:
<syntaxhighlight lang="cpp-qt">
// wrong
KCategorizedView *catview;
QString prtxt, Errstr;
// correct
KCategorizedView *groupedDeviceList;
QString progressText;
QString errorString;
</syntaxhighlight>


== Qt Includes ==
== Qt Includes ==

Revision as of 02:51, 21 November 2015

Note
This is a style guide for KDE Frameworks 5. If you write code that is not targeted at KF5, but only at KDE SC 4, refer to that style guide.


Indentation

  • 4 spaces
  • no tabs

Variable Declarations

  • Each variable declaration on a new line
  • Each new word in a variable name starts with a capital letter (so-called camelCase)
  • Avoid abbreviations
  • Take useful names. No short names, except:
    • Single character variable names can denote counters and temporary variables whose purpose is obvious
  • Variables and functions start with a lowercase letter

Example:

// wrong
KCategorizedView *catview;
QString prtxt, Errstr;

// correct
KCategorizedView *groupedDeviceList;
QString progressText;
QString errorString;

Qt Includes

  • For Qt #includes omit the module name and only use the class name. That way chances are good that future migrations of Qt classes between different modules do not need any adjustments in the code.

Example:

// wrong
#include <QtCore/QString>

// correct
#include <QString>


Note
This policy applies to KF5 and is the exact opposite of the preferred style for kdelibs in KDE SC 4.