pre .code { background-color: #F2F2F2; } .right { color: #080 !important; } .wrong { color: #f00 !important; } .idbutton { color: #888; font-size: smaller; cursor: pointer; } END; include("../header.inc"); ?>
int main() { return 0; }
int main() { return 0; }
namespace
block (and any nested namespaces with the same scope)
should not be indented. The contents of other nested namespaces should be indented.
// Document.h namespace WebCore { class Document { Document(); ... }; namespace NestedNamespace { ... } } // namespace WebCore // Document.cpp namespace WebCore { Document::Document() { ... } } // namespace WebCore
// Document.h namespace WebCore { class Document { Document(); ... }; namespace NestedNamespace { ... } } // namespace WebCore // Document.cpp namespace WebCore { Document::Document() { ... } } // namespace WebCore
switch (condition) { case fooCondition: case barCondition: i++; break; default: i--; }
switch (condition) { case fooCondition: case barCondition: i++; break; default: i--; }
if (attr->name() == srcAttr || attr->name() == lowsrcAttr || (attr->name() == usemapAttr && attr->value().domString()[0] != '#')) return;
if (attr->name() == srcAttr || attr->name() == lowsrcAttr || (attr->name() == usemapAttr && attr->value().domString()[0] != '#')) return;
i++;
i ++;
y = m * x + b; f(a, b); c = a | b; return condition ? 1 : 0;
y=m*x+b; f(a,b); c = a|b; return condition ? 1:0;
for (int i = 0; i < 10; ++i) doSomething(); f(a, b);
for (int i = 0 ; i < 10 ; ++i) doSomething(); f(a , b) ;
if (condition) doIt();
if(condition) doIt();
f(a, b);
f (a, b); f( a, b );
x++; y++; if (condition) doIt();
x++; y++; if (condition) doIt();
else
statement should go on the same line as a preceding close brace if one is present,
else it should line up with the if
statement.
if (condition) { ... } else { ... } if (condition) doSomething(); else doSomethingElse(); if (condition) doSomething(); else { ... }
if (condition) { ... } else { ... } if (condition) doSomething(); else doSomethingElse(); if (condition) doSomething(); else { ... }
else if
statement should be written as an if
statement when the prior if
concludes with a return
statement.
if (condition) { ... return someValue; } if (condition) { ... }
if (condition) { ... return someValue; } else if (condition) { ... }
int main() { ... }
int main() { ... }
class MyClass { ... }; namespace WebCore { ... } for (int i = 0; i < 10; ++i) { ... }
class MyClass { ... };
if (condition) doIt(); if (condition) { // Some comment doIt(); } if (condition) { myFunction(reallyLongParam1, reallyLongParam2, ... reallyLongParam5); }
if (condition) { doIt(); } if (condition) // Some comment doIt(); if (condition) myFunction(reallyLongParam1, reallyLongParam2, ... reallyLongParam5);
for ( ; current; current = current->next) { }
for ( ; current; current = current->next);
0
. In C, it should be written as NULL
. In Objective-C and Objective-C++, follow the guideline for C or C++, respectively, but use nil
to represent a null Objective-C object.bool
values should be written as true
and false
. Objective-C BOOL
values should be written as YES
and NO
.if (condition) doIt(); if (!ptr) return; if (!count) return;
if (condition == true) doIt(); if (ptr == NULL) return; if (count == 0) return;
.0
, .f
and .0f
to floating point
literals.
const double duration = 60; void setDiameter(float diameter) { radius = diameter / 2; } setDiameter(10); const int framesPerSecond = 12; double frameDuration = 1.0 / framesPerSecond;
const double duration = 60.0; void setDiameter(float diameter) { radius = diameter / 2.f; } setDiameter(10.f); const int framesPerSecond = 12; double frameDuration = 1 / framesPerSecond; // integer division
struct Data; size_t bufferSize; class HTMLDocument; String mimeType();
struct data; size_t buffer_size; class HtmlDocument; String MIMEType();
size_t characterSize; size_t length; short tabIndex; // more canonical
size_t charSize; size_t len; short tabulationIndex; // bizarre
class String { public: ... private: short m_length; };
class String { public: ... short length; };
@class String ... short _length; @end
@class String ... short length; @end
bool isValid; bool didSendData;
bool valid; bool sentData;
void setCount(size_t); // sets m_count size_t count(); // returns m_count
void setCount(size_t); // sets m_theCount size_t getCount();
void getInlineBoxAndOffset(InlineBox*&, int& caretOffset) const;
void inlineBoxAndOffset(InlineBox*&, int& caretOffset) const;
bool convertToASCII(short*, size_t);
bool toASCII(short*, size_t);
void setCount(size_t); void doSomething(ScriptExecutionContext*);
void setCount(size_t count); void doSomething(ScriptExecutionContext* context);
doSomething(something, AllowFooBar); paintTextWithShadows(context, ..., textStrokeWidth > 0, isHorizontal()); setResizable(false);
doSomething(something, false); setResizable(NotResizable);
#define WBStopButtonTitle() \ NSLocalizedString(@"Stop", @"Stop button title")
#define WB_STOP_BUTTON_TITLE \ NSLocalizedString(@"Stop", @"Stop button title") #define WBStopButtontitle \ NSLocalizedString(@"Stop", @"Stop button title")
// HTMLDocument.h #ifndef HTMLDocument_h #define HTMLDocument_h
// HTMLDocument.h #ifndef _HTML_DOCUMENT_H_ #define _HTML_DOCUMENT_H_
MyClass::MyClass(Document* doc) : MySuperClass() , m_myMember(0) , m_doc(doc) { } MyOtherClass::MyOtherClass() : MySuperClass() { }
MyClass::MyClass(Document* doc) : MySuperClass() { m_myMember = 0; m_doc = doc; } MyOtherClass::MyOtherClass() : MySuperClass() {}
size_t frameViewsCount = frameViews.size(); for (size_t i = 0; i < frameViewsCount; ++i) frameViews[i]->updateLayoutAndStyleIfNeededRecursive();
const Vector<RefPtr<FrameView> >::iterator end = frameViews.end(); for (Vector<RefPtr<FrameView> >::iterator it = frameViews.begin(); it != end; ++it) (*it)->updateLayoutAndStyleIfNeededRecursive();
Image* SVGStyledElement::doSomething(PaintInfo& paintInfo) { SVGStyledElement* element = static_cast<SVGStyledElement*>(node()); const KCDashArray& dashes = dashArray();
Image *SVGStyledElement::doSomething(PaintInfo &paintInfo) { SVGStyledElement *element = static_cast<SVGStyledElement *>(node()); const KCDashArray &dashes = dashArray();
void MyClass::getSomeValue(OutArgumentType& outArgument) const { outArgument = m_value; } void MyClass::doSomething(OutArgumentType* outArgument) const { doSomething(); if (outArgument) *outArgument = m_value; }
void MyClass::getSomeValue(OutArgumentType* outArgument) const { *outArgument = m_value; }
// RenderLayer.h #include "Node.h" #include "RenderObject.h" #include "RenderView.h"
// RenderLayer.h #include "config.h" #include "RenderObject.h" #include "RenderView.h" #include "Node.h"
// HTMLDivElement.cpp #include "config.h" #include "HTMLDivElement.h" #include "Attribute.h" #include "HTMLElement.h" #include "QualifiedName.h"
// HTMLDivElement.cpp #include "HTMLElement.h" #include "HTMLDivElement.h" #include "QualifiedName.h" #include "Attribute.h"
// ConnectionQt.cpp #include "ArgumentEncoder.h" #include "ProcessLauncher.h" #include "WebPageProxyMessageKinds.h" #include "WorkItem.h" #include <QApplication> #include <QLocalServer> #include <QLocalSocket>
// ConnectionQt.cpp #include "ArgumentEncoder.h" #include "ProcessLauncher.h" #include <QApplication> #include <QLocalServer> #include <QLocalSocket> #include "WebPageProxyMessageKinds.h" #include "WorkItem.h"
// wtf/Vector.h namespace WTF { class VectorBuffer { using std::min; ... }; } // namespace WTF
// wtf/Vector.h namespace WTF { using std::min; class VectorBuffer { ... }; } // namespace WTF
// wtf/Vector.h namespace WTF { } // namespace WTF using WTF::Vector;
// wtf/Vector.h namespace WTF { } // namespace WTF using namespace WTF;
// runtime/JSObject.h namespace WTF { } // namespace WTF using WTF::PlacementNewAdopt;
// HTMLBaseElement.cpp namespace WebCore { std::swap(a, b); c = std::numeric_limits<int>::max() } // namespace WebCore
// HTMLBaseElement.cpp using std::swap; namespace WebCore { swap(a, b); } // namespace WebCore
// HTMLBaseElement.cpp using namespace std; namespace WebCore { swap(a, b); } // namespace WebCore
// HTMLBaseElement.cpp namespace WebCore { using namespace HTMLNames; } // namespace WebCore
// HTMLBaseElement.cpp using namespace WebCore::HTMLNames; namespace WebCore { } // namespace WebCore
// HTMLSelectElement.cpp using namespace other; namespace WebCore { } // namespace WebCore
// HTMLSelectElement.cpp namespace WebCore { using namespace other; } // namespace WebCore
unsigned a; int b;
unsigned int a; // Doesn't omit "int". signed b; // Uses "signed" instead of "int". signed int c; // Doesn't omit "signed".
class LargeInt { public: LargeInt(int); ... class Vector { public: explicit Vector(int size); // Not a type conversion. PassOwnPtr<Vector> create(Array); // Costly conversion. ...
class Task { public: Task(ScriptExecutionContext*); // Not a type conversion. explicit Task(); // No arguments. explicit Task(ScriptExecutionContext*, Other); // More than one argument. ...
f(a, b); // This explains why the function call was done. This is another sentence.
int i; // This is a comment with several spaces before it, which is a non-conforming style. double f; // This is another comment. There are two spaces before this sentence which is a non-conforming style.
drawJpg(); // FIXME: Make this code handle jpg in addition to the png support.
drawJpg(); // FIXME(joe): Make this code handle jpg in addition to the png support.
drawJpg(); // TODO: Make this code handle jpg in addition to the png support.