Translate

Jump to: navigation, search
Settings

Information about the group Translation of the wiki page Policies/Kdelibs Coding Style.
Policies/Kdelibs Coding StyleCurrent message text
...g Style/Page display title/zh-cn政策 / kdelibs 的编码风格
...ies/Kdelibs Coding Style/1/zh-cn本文档介绍了 kdelibs 的推荐编码风格。并不强迫任何人遵守这种风格,但建议利用它以保持源代码的风格统一。
...ies/Kdelibs Coding Style/2/zh-cn“简而言之:kdelibs 的编码沿用 Qt 4 的风格。”
...ies/Kdelibs Coding Style/3/zh-cn== 缩进 ==
* 不使用 Tab
* 用四个空格代替 Tab
...ies/Kdelibs Coding Style/4/zh-cn== Variable declaration ==
* 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
...ies/Kdelibs Coding Style/5/zh-cnExample:
...ies/Kdelibs Coding Style/6/zh-cn// wrong
...ies/Kdelibs Coding Style/7/zh-cn// correct
...ies/Kdelibs Coding Style/8/zh-cn== Whitespace ==
* Use blank lines to group statements
* Use only one empty line
* Use one space after each keyword
* For pointers or references, use a single space before '*' or '&', but not after
* No space after a cast
...ies/Kdelibs Coding Style/9/zh-cnExample:
...es/Kdelibs Coding Style/10/zh-cn// wrong
...es/Kdelibs Coding Style/11/zh-cn// correct
...es/Kdelibs Coding Style/12/zh-cn== Braces ==
As a base rule, the left curly brace goes on the same line as the start of the statement.
...es/Kdelibs Coding Style/13/zh-cnExample:
...es/Kdelibs Coding Style/14/zh-cn// wrong
...es/Kdelibs Coding Style/15/zh-cn// correct
...es/Kdelibs Coding Style/16/zh-cnException: Function implementations, class, struct and namespace declarations always have the opening brace on the start of a line.
...es/Kdelibs Coding Style/17/zh-cnExample:
...es/Kdelibs Coding Style/18/zh-cnUse curly braces even when the body of a conditional statement contains only one line.
...es/Kdelibs Coding Style/19/zh-cnExample:
...es/Kdelibs Coding Style/20/zh-cn// wrong
...es/Kdelibs Coding Style/21/zh-cn// correct
...es/Kdelibs Coding Style/22/zh-cn== Switch statements ==
Case labels are on the same column as the switch
...es/Kdelibs Coding Style/23/zh-cnExample:
...es/Kdelibs Coding Style/24/zh-cn== Line breaks ==
Try to keep lines shorter than 100 characters, inserting line breaks as necessary.
...es/Kdelibs Coding Style/25/zh-cn== Qt Includes ==
* If you add #includes for Qt classes, use both the module and class name.  This allows library code to be used by applications without excessive compiler include paths.
...es/Kdelibs Coding Style/26/zh-cnExample:
...es/Kdelibs Coding Style/27/zh-cn// wrong
...es/Kdelibs Coding Style/28/zh-cn// correct
...es/Kdelibs Coding Style/29/zh-cn== Artistic Style (astyle) automatic code formatting ==
You can use [http://astyle.sourceforge.net/ astyle] (>=1.23) to format code or to test if you have followed this document. Run the following command:
...es/Kdelibs Coding Style/30/zh-cnWith astyle (>=2.01) you need to run the following command:
...es/Kdelibs Coding Style/31/zh-cnYou can find a shell script to run this command in:
...es/Kdelibs Coding Style/40/zh-cn* [https://projects.kde.org/projects/kde/kdesdk/kde-dev-scripts/repository/revisions/master/raw/astyle-kdelibs kde-dev-scripts/astyle-kdelibs] (POSIX)
* [https://projects.kde.org/projects/kde/kdesdk/kde-dev-scripts/repository/revisions/master/raw/astyle-kdelibs.bat kde-dev-scripts/astyle-kdelibs.bat] (Windows)
...es/Kdelibs Coding Style/32/zh-cn== Emacs and Vim scripts ==
The [https://projects.kde.org/projects/kde/kdesdk/kde-dev-scripts/repository/revisions/master/show kde-dev-scripts] directory in the kdesdk module contains, among other useful things, some useful additions to the Emacs and Vim text editors that make it easier to edit KDE code with them.
 
=== Emacs ===
The [https://projects.kde.org/projects/kde/kdesdk/kde-dev-scripts/repository/revisions/master/show/kde-emacs kde-emacs] directory contains a set of key bindings, macros and general useful code. It is compatible with both GNU Emacs and XEmacs.
...es/Kdelibs Coding Style/33/zh-cnTo start using kde-emacs, add the following to your .emacs:
...es/Kdelibs Coding Style/34/zh-cnMany settings can be changed by editing the "kde-emacs" group via <tt>M-x customize-group</tt>.
...es/Kdelibs Coding Style/35/zh-cnFor more information, including what the key bindings are and what additional settings you could add to your .emacs, please check <tt>kde-emacs.el</tt> itself.
...es/Kdelibs Coding Style/36/zh-cn=== Vim ===
You can find a vim script in [https://projects.kde.org/projects/kde/kdesdk/kde-dev-scripts/repository/revisions/master/raw/kde-devel-vim.vim kde-devel-vim.vim] that helps you to keep the coding style correct. In addition to defaulting to the kdelibs coding style it will automatically use the correct style for Solid and kdepim code. If you want to add rules for other projects feel free to add them in the SetCodingStyle function.
...es/Kdelibs Coding Style/37/zh-cnTo use the script, include it in your {{path|~/.vimrc}} like this:
...es/Kdelibs Coding Style/38/zh-cnDocument started by Urs Wolfer. Some parts of this document have been adopted from the Qt Coding Style document posted by Zack Rusin on kde-core-devel.
...es/Kdelibs Coding Style/39/zh-cn[[Category:Policies]] [[Category:C++]]
NavigationShowing 41 messages.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal