C++ Tips: Difference between revisions

Jump to navigation Jump to search
115 bytes added ,  7 October 2009
Line 13: Line 13:
* Prefer early-return style. Don't make people scroll to see which code-path they're inside; use <tt>return</tt> to manage control flow, instead of deep nesting of <tt>if</tt> clauses. If you are nesting more than three level deep, consider making a helper function for the inner levels, or see if you can invert the logic to reduce indentation.
* Prefer early-return style. Don't make people scroll to see which code-path they're inside; use <tt>return</tt> to manage control flow, instead of deep nesting of <tt>if</tt> clauses. If you are nesting more than three level deep, consider making a helper function for the inner levels, or see if you can invert the logic to reduce indentation.


* Use exceptions. Exception support is not well developed, but they provide a clean way to handle genuinely unusual situations without (easily ignorable) bool or integer return codes. The main loop catches exceptions, so use the SimGear exception, provide good location and message strings when you throw, and all should be well.
* Use exceptions. Exception support is not well developed, but they provide a clean way to handle genuinely unusual situations without (easily ignorable) bool or integer return codes. The main loop catches exceptions, so use the SimGear exception classes, provide good location and message strings when you throw, and all should be well. Using exceptions can greatly simplify code, by removing continual failure / error checks in the main code.


== Standards ==
== Standards ==
580

edits

Navigation menu