We have moved to https://dokuwiki.librecad.org/

Lots of content was already moved to the new wiki, but there is still work to do. If you want to contribute, please register a new account at https://dokuwiki.librecad.org/

This wiki will be kept for a while to keep search engine results valid. Moved sites may be deleted here in future.

Difference between revisions of "LibreCAD 3 - LibreCAD 3 - code style"

From LibreCAD wiki
Jump to: navigation, search
(Created page with "== Code style guide == '''Accessor naming:''' <pre>use foo->layer() </pre> instead of <pre> foo->getLayer(); </pre> '''Exceptions:''' Only throw exceptions in rare situa...")
 
Line 19: Line 19:
 
<pre>
 
<pre>
 
document->entityByID(...); // return null if a entry does not exists
 
document->entityByID(...); // return null if a entry does not exists
 +
</pre>
 +
 +
'''Shared pointer passing:''
 +
never pass shared_ptr by reference
 +
 +
Good:
 +
<pre>
 +
Line::Line(const geo::Coordinate& start, const geo::Coordinate& end, const shared_ptr<Layer> layer) : CADEntity(layer), Vector(start, end) {..}
 +
</pre>
 +
 +
Bad:
 +
<pre>
 +
Line::Line(const geo::Coordinate& start, const geo::Coordinate& end, const shared_ptr<Layer> &layer) : CADEntity(layer), Vector(start, end) {..}
 
</pre>
 
</pre>

Revision as of 02:53, 23 April 2014

Code style guide

Accessor naming:

use foo->layer()

instead of

 foo->getLayer();


Exceptions:

Only throw exceptions in rare situations that are effectively unreasonable.

For example:

document->entityByID(...); // return null if a entry does not exists

'Shared pointer passing: never pass shared_ptr by reference

Good:

Line::Line(const geo::Coordinate& start, const geo::Coordinate& end, const shared_ptr<Layer> layer) : CADEntity(layer), Vector(start, end) {..}

Bad:

Line::Line(const geo::Coordinate& start, const geo::Coordinate& end, const shared_ptr<Layer> &layer) : CADEntity(layer), Vector(start, end) {..}