--Boundary-00=_ZV92DvXQ608aNQ1 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline With much love from Russia comes temperature checker (prediction: it's hot! flaming hot!) in the form of a proposal for a common coding style in kdelibs. It's something we talked about during the KDE Four meeting. The reason for it is that it's a pain in a butt to read through kdelibs code. Indention differs within files which makes a lot of them unreadable (oh, and btw shoutouts to George and Lubos for having indention styles that make grown may cry and baby jesus swear). Since KDE uses this thing called Qt, which also happens to be a library, it was agreed that it makes natural sense to adopt the style used in Qt. Attached is a file which describes Qt coding style. The idea is that it would be adopted for kdelibs. To make it clear, no mass reindenting would take place.. For already existing code the indention would be changed when a person would be editting it. So if you fix a bug in already existing code, you simply indent your code with the standard indention. This way history won't be messed up and we'll end up with consistant style in all files by the time KDE4 is out. The style is obviously mandatory for all new files. No exceptions. Either everything or nothing. Well, the only exception are libraries that are not maintained in the KDE SVN (for example, if it ever happens, integrated KHTML/WebKit would be maintained outside KDE SVN and the coding style that applies to it is one chosen for this project - interestingly enough WebKit coding style is basically exactly like Qt coding style so that's not going to be an issue). Oh, and this is of course only for kdelibs, in your apps/modules you can still use the 2.3 tabs indention or whatever your sick mind desires. with not a whole lot love but a lot of perseverance your boy toy -- If it's stupid but works, it isn't stupid. --Boundary-00=_ZV92DvXQ608aNQ1 Content-Type: text/html; charset="us-ascii"; name="QtCodingStyle.html" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="QtCodingStyle.html"
This is a overview of the coding convention we use when writing Qt code. The data has been gathered by mining the Qt sources, discussion forums, email threads and through collaboration of the developers.
// Wrong int a, b; char *c, *d; // Correct int height; int width; char *nameOfThis; char *nameOfThat;
// Wrong short Cntr; char ITEM_DELIM = '\t'; // Correct short counter; char itemDelimiter = '\t';
// Wrong if(foo){ } // Correct if (foo) { }
// Wrong char* blockOfMemory = (char* ) malloc(data.size()); // Correct char *blockOfMemory = (char *)malloc(data.size()); char *blockOfMemory = reinterpret_cast<char *>(malloc(data.size()));
// Wrong if (codec) { } // Correct if (codec) { }
static void foo(int g) { qDebug("foo: %i", g); } class Moo { };
// Wrong if (address.isEmpty()) { return false; } for (int i = 0; i < 10; ++i) { qDebug("%i", i); } // Correct if (address.isEmpty()) return false; for (int i = 0; i < 10; ++i) qDebug("%i", i);
// Correct if (address.isEmpty() || !isValid() || !codec) { return false; }
// Wrong if (address.isEmpty()) return false; else { qDebug("%s", qPrintable(address)); ++it; } // Correct if (address.isEmpty()) { return false; } else { qDebug("%s", qPrintable(address)); ++it; }
switch (myEnum) { case Value1: doSomething(); break; case Value2: doSomethingElse(); // fall through default: defaultHandling(); break; }