+2014-02-27 Darin Adler <darin@apple.com>
+
+ Some small modernizing tweaks to the coding style guide
+ https://bugs.webkit.org/show_bug.cgi?id=129427
+
+ Reviewed by Alexey Proskuryakov.
+
+ My intent here was originally to do the nullptr style guide update, but that was already done.
+ I did some other improvements. There's still quite a bit to do -- the guide is out of date in
+ a number of subtle ways.
+
+ * coding/coding-style.html: Change "left side operator" example to be a more modern example
+ without non-WebKit-style abbreviations and such. Use auto& instead of const auto& in for loop
+ example, since that's normally preferred. Changed section title to say "zero" instead of "0".
+ Use words instead of abbreviations in code examples. Show that a modern C++ for loop is preferred
+ over index iteration in vector iteration example and also showed use of unsigned rather than
+ size_t since that is almost always what we want. Eliminated the use of PassOwnPtr in the "return
+ a newly created object" example. Use references instead of pointers in one example.
+
2014-02-26 Julien Brianceau <jbriance@cisco.com>
Add Cisco to team.html
<h4 class="right">Right:</h4>
<pre class="code">
-if (attr->name() == srcAttr
- || attr->name() == lowsrcAttr
- || (attr->name() == usemapAttr && attr->value().domString()[0] != '#'))
- return;
+return attribute.name() == srcAttr
+ || attribute.name() == lowsrcAttr
+ || (attribute.name() == usemapAttr && attribute.value().string()[0] != '#');
</pre>
<h4 class="wrong">Wrong:</h4>
<pre class="code">
-if (attr->name() == srcAttr ||
- attr->name() == lowsrcAttr ||
- (attr->name() == usemapAttr && attr->value().domString()[0] != '#'))
- return;
+return attribute.name() == srcAttr ||
+ attribute.name() == lowsrcAttr ||
+ (attribute.name() == usemapAttr && attr->value().string()[0] != '#');
</pre>
</li>
<h4 class="right">Right:</h4>
<pre class="code">
Vector<PluginModuleInfo> plugins;
-for (const auto& plugin : plugins)
+for (auto& plugin : plugins)
registerPlugin(plugin);
</pre>
<h4 class="wrong">Wrong:</h4>
<pre class="code">
Vector<PluginModuleInfo> plugins;
-for (const auto& plugin: plugins)
+for (auto& plugin: plugins)
registerPlugin(plugin);
</pre>
</li>
</li>
</ol>
-<h3 id="zero">Null, false and 0</h3>
+<h3 id="zero">Null, false and zero</h3>
<ol>
<li id="zero-null">In C++, the null pointer value should be written as <code>nullptr</code>. In C, it should be written as <code>NULL</code>. In Objective-C and Objective-C++, follow the guideline for C or C++, respectively, but use <code>nil</code> to represent a null Objective-C object.</li>
<h4 class="right">Right:</h4>
<pre class="code">
-MyClass::MyClass(Document* doc)
+MyClass::MyClass(Document* document)
: MySuperClass()
, m_myMember(0)
- , m_doc(doc)
+ , m_document(document)
{
}
<h4 class="wrong">Wrong:</h4>
<pre class="code">
-MyClass::MyClass(Document* doc) : MySuperClass()
+MyClass::MyClass(Document* document) : MySuperClass()
{
m_myMember = 0;
- m_doc = doc;
+ m_document = document;
}
MyOtherClass::MyOtherClass() : MySuperClass() {}
</pre>
-<li id="punctuation-vector-index">Prefer index over iterator in Vector iterations for a terse, easier-to-read code.
+<li id="punctuation-vector-index">Prefer index over iterator in Vector iterations for terse, easier-to-read code.
<h4 class="right">Right:</h4>
<pre class="code">
-size_t frameViewsCount = frameViews.size();
-for (size_t i = 0; i < frameViewsCount; ++i)
+for (auto& frameView : frameViews)
+ frameView->updateLayoutAndStyleIfNeededRecursive();
+</pre>
+
+<h4 class="right">OK:</h4>
+<pre class="code">
+unsigned frameViewsCount = frameViews.size();
+for (unsigned i = 0; i < frameViewsCount; ++i)
frameViews[i]->updateLayoutAndStyleIfNeededRecursive();
</pre>
#include "Attribute.h"
#include "HTMLElement.h"
#include "QualifiedName.h"
-
</pre>
<h4 class="wrong">Wrong:</h4>
class Vector {
public:
explicit Vector(int size); // Not a type conversion.
- PassOwnPtr<Vector> create(Array); // Costly conversion.
+ Vector create(Array); // Costly conversion.
...
</pre>
<pre class="code">
class Task {
public:
- Task(ScriptExecutionContext*); // Not a type conversion.
+ Task(ScriptExecutionContext&); // Not a type conversion.
explicit Task(); // No arguments.
- explicit Task(ScriptExecutionContext*, Other); // More than one argument.
+ explicit Task(ScriptExecutionContext&, Other); // More than one argument.
...
</pre>
</li>