Warning, /games/killbots/README.codestyle is written in an unsupported language. File is not indexed.

0001 ==========================
0002  Killbots C++ Style Guide
0003 ==========================
0004 
0005 *******************************************************************************
0006  Indentation
0007 *******************************************************************************
0008 
0009 Structural indentation is done with tabs. Formatting is done with spaces. All
0010 code having the same nested depth has the same number of tabs. This separates
0011 meaning from presentation.
0012 
0013 Tabwidth is a matter of personal preference. If the above is followed source is
0014 tabwidth independent.
0015 
0016 Ensure your editor doesn't do automatic conversion from spaces to tabs, as this
0017 will break things.
0018 
0019 Labels (public, private, goto, case, etc.) do not get indented.
0020 
0021 Empty lines do not get indentation. In fact, no lines should have trailing
0022 whitespace.
0023 
0024 If a pair of parentheses span multiple lines, the closing parenthesis should be
0025 indented (with spaces) to appear in the same column as the opening parenthesis.
0026 
0027 Examples:
0028 -------------------------------------------------------------------------------
0029 bool Killbots::Engine::cellIsValid( const QPoint & cell ) const
0030 {
0031 ____return ( 0 <= cell.x()
0032 ____.........&& cell.x() < m_rules->columns()
0033 ____.........&& 0 <= cell.y()
0034 ____.........&& cell.y() < m_rules->rows()
0035 ____.......);
0036 }
0037 -------------------------------------------------------------------------------
0038 namespace Killbots
0039 {
0040 ____class RenderPrivate
0041 ____{
0042 ____public:
0043 ________RenderPrivate()
0044 ________..:.m_svgRenderer(),
0045 ________....m_pixmapCache("killbots-cache"),
0046 ________....m_cursors(),
0047 ________....m_hasBeenLoaded( false )
0048 ________{};
0049 -------------------------------------------------------------------------------
0050 ____if ( m_rulesetChanged )
0051 ____{
0052 ________if ( ! m_engine->gameHasStarted() ||
0053 ________.....KMessageBox::questionYesNo( this,
0054 ________.................................i18n("A new ruleset has been selected, but there is already a game in progress."),
0055 ________.................................i18n("Rule Set Changed"),
0056 ________.................................KGuiItem( i18n("Continue Current Game") ),
0057 ________.................................KGuiItem( i18n("Start a New Game") )
0058 ________...............................) == KMessageBox::No
0059 ________...)
0060 ________{
0061 -------------------------------------------------------------------------------
0062 
0063 
0064 *******************************************************************************
0065  Braces
0066 *******************************************************************************
0067 
0068 Opening and closing braces are always on a new line.
0069 
0070 For loop or conditional statements, braces can be omitted if the block is a
0071 single-line statement and the conditional fits on a single line. If braces are
0072 used in one block of an if-elseif-else statement, they should be used in the
0073 other blocks even if those blocks are a single line.
0074 
0075 Blocks never appear on the same line as the loop/conditional, even if braces
0076 aren't used.
0077 
0078 Empty blocks are represented on a single line as '{}'
0079 
0080 Examples:
0081 -------------------------------------------------------------------------------
0082 void Killbots::Engine::refreshSpriteMap()
0083 {
0084     m_spriteMap.clear();
0085     for (Sprite * bot : std::as_const(m_bots))
0086         m_spriteMap.insert( bot->gridPos(), bot );
0087     for (Sprite * junkheap : std::as_const(m_junkheaps))
0088         m_spriteMap.insert( junkheap->gridPos(), junkheap );
0089 }
0090 -------------------------------------------------------------------------------
0091 if ( m_rules->pushableJunkheaps() != Ruleset::None && cellIsValid( nextCell ) )
0092 {
0093     if ( spriteTypeAt( nextCell ) == NoSprite )
0094         return true;
0095     else if ( spriteTypeAt( nextCell ) == Junkheap )
0096         return m_rules->pushableJunkheaps() == Ruleset::Many && canPushJunkheap( m_spriteMap.value( nextCell ), direction );
0097     else
0098         return m_rules->squaskKillsEnabled();
0099 }
0100 else
0101 {
0102     return false;
0103 }
0104 -------------------------------------------------------------------------------
0105 while ( m_rulesetMap.contains( name ) )
0106     name += '_';
0107 -------------------------------------------------------------------------------
0108 
0109 *******************************************************************************
0110  Whitespace
0111 *******************************************************************************
0112 
0113 Lines should generally be kept to less than 100 characters, but don't make code
0114 uglier just to avoid width.
0115 
0116 Two empty lines should be used to separate function definitions.
0117 
0118 Within a block, empty lines may be used to break up unrelated lines, but never
0119 more than one.
0120 
0121 No space appears between the function name and the opening bracket.
0122 
0123 A single space appears between the loop/conditional statement name and the
0124 opening bracket.
0125 
0126 Padding spaces appear inside of all parentheses, unless the parentheses are
0127 empty or contain only a string literal.
0128 
0129 Binary operators are separated from their operands with a single space. Unary
0130 operators are not.
0131 
0132 Pointer and reference symbols have a space on either side.
0133 
0134 No padding spaces appear inside angle brackets when using template functions
0135 or classes.
0136 
0137 No space appears between a label and the following colon.
0138 
0139 No whitespace should appear inside Qt's SIGNAL and SLOT macros.
0140 
0141 
0142 *******************************************************************************
0143  Indentifiers
0144 *******************************************************************************
0145 
0146 All identifiers should use camel case.
0147 
0148 Classnames and namespaces begin with uppercase letters. All other identifiers
0149 begin with lowercase letters.
0150 
0151 Class data members are prefixed with 'm_', unless they are public KConfigXT
0152 widgets, in which case, they are prefixed with 'kfcg_'.
0153 
0154 Indentifiers should favour descriptiveness over brevity. Single letter
0155 variables are acceptable only for iterators or coordinates.
0156 
0157 All indentifiers should use American English spelling. (Comments can be in your
0158 choice of English.)
0159 
0160 Examples:
0161 -------------------------------------------------------------------------------
0162 namespace Killbots
0163 {
0164     class Ruleset;
0165 
0166     class RulesetSelector : public QWidget
0167     {
0168         Q_OBJECT
0169 
0170     public: // functions
0171         explicit RulesetSelector( QWidget * parent = 0 );
0172         virtual ~RulesetSelector();
0173 
0174     public: // data members
0175         KLineEdit * kcfg_Ruleset;
0176 
0177     private: // functions
0178         void findRulesets();
0179 
0180     private Q_SLOTS:
0181         void selectionChanged( QString rulesetName );
0182 
0183     private: // data members
0184         QListWidget * m_listWidget;
0185         QLabel * m_author;
0186         QLabel * m_authorContact;
0187         QLabel * m_description;
0188         QMap< QString, Ruleset * > m_rulesetMap;
0189     };
0190 }
0191 -------------------------------------------------------------------------------
0192 
0193 
0194 *******************************************************************************
0195  Comments
0196 *******************************************************************************
0197 
0198 Feel free to comment as much as possible.
0199 
0200 Comments should describe the purpose of logic or give background details not
0201 obvious from the code. Comments should not describe what the code is doing,
0202 unless the code is extremely dense (in which case the code should probably be
0203 rewritten/refactored anyway).
0204 
0205 Comments appear on the line before the code it is commenting on.
0206 
0207 Use '/**/' for comments longer than 3 lines.
0208 
0209 
0210 *******************************************************************************
0211  Class Definitions
0212 *******************************************************************************
0213 
0214 Classes should be given simple names and placed inside the Killbots namespace
0215 instead of adding a prefix. (i.e. Killbots::MainWindow instead of
0216 KillbotsMainWindow)
0217 
0218 No inline function definitions in the header, even if they are a single
0219 statement. Same goes for constructors.
0220 
0221 Define destructors even if they're empty.
0222 
0223 Class definitions should be layed out in the following order.
0224   public: // types
0225   public: // functions
0226   public Q_SLOTS:
0227   public: // data members
0228   Q_SIGNALS:
0229   protected: // types
0230   protected: // functions
0231   protected Q_SLOTS:
0232   protected: // data members
0233   private: // types
0234   private: // functions
0235   private Q_SLOTS:
0236   private: // data members
0237 
0238 
0239 *******************************************************************************
0240  Includes
0241 *******************************************************************************
0242 
0243 Include guards are of the form NAMESPACE_CLASSNAME_H.
0244 
0245 Group includes in the following order with blank lines in between:
0246   File's own header
0247   Killbots headers
0248   KDE headers
0249   Qt headers
0250 
0251 Inside of groups, sort includes alphabetically.
0252 
0253 Use the "new" style includes with directory names where appropriate
0254 
0255 Forward declare whenever possible in headers.
0256 
0257 moc includes appear at the bottom of the source file.
0258 
0259 Examples:
0260 -------------------------------------------------------------------------------
0261 #ifndef KILLBOTS_RULESETSELECTOR_H
0262 #define KILLBOTS_RULESETSELECTOR_H
0263 
0264 class KLineEdit;
0265 
0266 #include <QtCore/QMap>
0267 class QLabel;
0268 class QListWidget;
0269 #include <QWidget>
0270 
0271 namespace Killbots
0272 {
0273     class Ruleset;
0274 -------------------------------------------------------------------------------
0275 #include "rulesetselector.h"
0276 
0277 #include "ruleset.h"
0278 #include "settings.h"
0279 
0280 #include <KDE/KDebug>
0281 #include <KDE/KDialog>
0282 #include <KDE/KLineEdit>
0283 #include <KDE/KLocalizedString>
0284 #include <KDE/KStandardDirs>
0285 
0286 #include <QLabel>
0287 #include <QListWidget>
0288 -------------------------------------------------------------------------------
0289 
0290 
0291 *******************************************************************************
0292  Miscellaneous
0293 *******************************************************************************
0294 
0295 It is generally preferred that functions have a single return statement, but
0296 multiple returns statements are exceptable if a single return would make the
0297 code more complicated.
0298 
0299 Use the "Q_UNUSED" macro on unused function parameters.
0300 
0301 Use "static_cast<>" instead of the C or C++ style type casts when casting
0302 pointers.
0303 
0304 When converting one type to another use C++ or constructor style casts. For
0305 example, use "int()" to convert floating types to integers.
0306 
0307 Make sure code passes all the English Breakfast Network checks.