Warning, /multimedia/juk/HACKING is written in an unsupported language. File is not indexed.
0001 Since I tend to be one of the more pedantic people on coding style I'll provide 0002 a bit of a reference here. Please take a few minutes to read this as it will 0003 save us both time when processing patches. 0004 0005 ================================================================================ 0006 Indentation 0007 ================================================================================ 0008 0009 Older versions of JuK had two different indenting schemes. Now all JuK source 0010 code files simply use 4 spaces at all levels. In most cases the style of the 0011 file currently being worked in should be followed. So: 0012 0013 static void foo() 0014 { 0015 if(bar()) // <-- 4 spaces 0016 baz() // <-- 8 spaces 0017 } 0018 0019 ================================================================================ 0020 Braces 0021 ================================================================================ 0022 0023 Braces opening classes, structs, namespaces and functions should be on their own 0024 line. Braces opening conditionals should be on the same line with one notable 0025 exception: if the conditional is split up onto several lines then the opening 0026 brace should be on its own line. i.e. 0027 0028 class Foo 0029 { 0030 // stuff 0031 }; 0032 0033 if(foo == bar) { 0034 // stuff 0035 } 0036 0037 while(foo == bar && 0038 baz == quux && 0039 flop == pop) 0040 { 0041 // stuff 0042 } 0043 0044 static void foo() 0045 { 0046 // stuff 0047 } 0048 0049 Other exceptions include inline functions that are just returning or setting a 0050 value. However multiple statements should not ever be combined onto one line: 0051 0052 class Foo 0053 { 0054 public: 0055 String value() const { return m_value; } 0056 }; 0057 0058 Also conditionals / loops that only contiain one line in their body (but where 0059 the conditional statement fits onto one line) should omit braces: 0060 0061 if(foo == bar) 0062 baz(); 0063 0064 But: 0065 0066 if(baz == quux && 0067 ralf == spot) 0068 { 0069 bar(); 0070 } 0071 0072 ================================================================================ 0073 Spaces 0074 ================================================================================ 0075 0076 Spaces should not be used between the conditional / loop type and the 0077 conditional statement. They should also not be used after parenthesis. However 0078 the should be to mark of mathematical or comparative operators. 0079 0080 if ( foo == bar ) 0081 ^ ^ ^ 0082 0083 The marked spaces should be ommitted to produce: 0084 0085 if(foo == bar) 0086 0087 ================================================================================ 0088 Header Organization 0089 ================================================================================ 0090 0091 Member variables should always be private and prefixed with "m_". Accessors may 0092 be inline in the headers. The organization of the members in a class should be 0093 roughly as follows: 0094 0095 public: 0096 public slots: 0097 protected: 0098 protected slots: 0099 signals: 0100 private: // member funtions 0101 private slots: 0102 private: // member variables 0103 0104 If there are no private slots there is no need for two private sections, however 0105 private functions and private variables should be clearly separated. 0106 0107 The implementations files -- .cpp files -- should follow (when possible) the 0108 same order of function declarations as the header files. 0109 0110 Virtual functions should always be marked as such even in derrived classes where 0111 it is not strictly necessary. 0112 0113 Header guards should be of the form FILENAME_H, as below (for an example file 0114 foo.h: 0115 0116 /* copyright/license stuff 0117 * blah 0118 */ 0119 0120 #ifndef FOO_H 0121 #define FOO_H 0122 0123 #include <qt stuff> 0124 0125 // classes 0126 0127 #endif 0128 0129 // vim modeline (see below) 0130 0131 ================================================================================ 0132 Whitespace 0133 ================================================================================ 0134 0135 Whitespace should be used liberally. When blocks of code are logically distinct 0136 I tend to put a blank line between them. This is difficult to explain 0137 systematically but after looking a bit at the current code organization this 0138 ideally will be somewhat clear. 0139 0140 Also I tend to separate comments by blank lines on both sides. 0141 0142 ================================================================================ 0143 Pointer and Reference Operators 0144 ================================================================================ 0145 0146 This one is pretty simple. I prefer "Foo *f" to "Foo* f" in function signatures 0147 and declarations. The same goes for "Foo &f" over "Foo& f". 0148 0149 ================================================================================ 0150 Editor Support 0151 ================================================================================ 0152 0153 Most JuK files that Michael Pyne has touched will eventually have a vim modeline 0154 at the bottom of the file (after any moc #includes). The current vim modeline 0155 is the following: 0156 0157 // vim: set et sw=4 tw=0 sta: 0158 0159 The vim: ... : part encloses the commands to automatically use when opening the 0160 file in vim. The following commands are set: 0161 et : Uses spaces instead of the <TAB> when the Tab key is pressed. No 0162 JuK source should have tab characters anymore, this helps enforce 0163 that. Full name is expandtab. 0164 sw = 4 : Makes indenting levels 4 spaces wide, for use with the vim indenting 0165 features. Full name is shiftwidth. 0166 tw = 0 : Prevents vim from wrapping lines as you are typing. Full name is 0167 textwidth. 0168 sta : Use shiftwidth to determine tab size at the beginning of the line, 0169 instead of tabstop (which is normally 8 spaces wide). Full name is 0170 smarttab. 0171 0172 Also, vim users will want to have the command "let c_space_errors=1" in their 0173 .vimrc in order to flag extra whitespace at the end of lines, which is also a 0174 no-no in source code. 0175 0176 There are vim and emacs scripts for KDE developers in kdesdk/scripts, you may 0177 also want to see what is available there. 0178 0179 ================================================================================ 0180 0181 There are likely things missing here and I'll try to add them over time as I 0182 notice things that are often missed. Please let me know if specific points are 0183 ambiguous. 0184 0185 Scott Wheeler <wheeler@kde.org>