Places/Coding Style: Difference between revisions

Jump to navigation Jump to search
no edit summary
(Created page with 'As a general rule we follow conventions reported in the global coding style page: https://developer.mozilla.org/En/Developer_Guide/Coding_Style With some differences: if/else…')
 
No edit summary
Line 22: Line 22:
catch(ex) {}
catch(ex) {}


</pre>
</pre>  
Oneliners statements inside if/elseif/else conditions can avoid braces, but if any side of the condition uses braces then all sides will take them:<br>
Oneliners statements inside if/elseif/else conditions can avoid braces, but if any side of the condition uses braces then all sides will take them:<br>  
<pre>if (condition)
<pre>if (condition)
   statement;
   statement;
Line 36: Line 36:
   statement2;
   statement2;
}
}
</pre>
</pre>  
When instantiating services in cpp use this form:<br>  
When instantiating services in cpp use this form:<br>  
<pre>nsCOMPtr&lt;nsIAnnotationService&gt; annoSvc =
<pre>nsCOMPtr&lt;nsIAnnotationService&gt; annoSvc =
   do_GetService(NS_ANNOTATIONSERVICE_CONTRACTID);
   do_GetService(NS_ANNOTATIONSERVICE_CONTRACTID);
NS_ENSURE_TRUE(annoSvc, NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(annoSvc, NS_ERROR_OUT_OF_MEMORY);
</pre>
</pre>  
To null check other objects use NS_ENSURE_STATE(obj);<br>
To null check other pointers use NS_ENSURE_STATE(something);<br>  


When defining cpp methods opening brace goes in new line:<br>
When defining cpp methods opening brace and type are in new lines:<br>  
<pre>type*&nbsp;newMethod(type param)
<pre>type*
newMethod(type param)
{
{
   impl;
   impl;
}
}
</pre>
</pre>  
Constructors params are inited like this (notice order of inited params should be the same as they are defined in the class definition, otherwise GCC will warn)<br>
Constructors params are inited like this (notice order of inited params should be the same as they are defined in the class definition, otherwise GCC will warn)<br>  
<pre>nsNavHistory::nsNavHistory()
<pre>nsNavHistory::nsNavHistory()
: mBatchLevel(0)
: mBatchLevel(0)
Line 68: Line 69:
   impl;
   impl;
}
}
</pre>
</pre>  
Use namespace mozilla::places where possible, or anonymous namespace for file scope.
Use namespace mozilla::places where possible, or anonymous namespace for file scope.  


Add Places or nsPlaces in front of components or modules names, so that they are easily recognizeable in components/modules folders and also to prevent naming conflicts.
Add Places or nsPlaces in front of components or modules names, so that they are easily recognizeable in components/modules folders and also to prevent naming conflicts.
Confirmed users
595

edits

Navigation menu