C++ Tips: Difference between revisions

Jump to navigation Jump to search
711 bytes added ,  9 October 2009
no edit summary
No edit summary
Line 34: Line 34:
** Any required includes, again grouped by kind as discussed for header files - generally 'simplest first'
** Any required includes, again grouped by kind as discussed for header files - generally 'simplest first'
** Any namespace, forward declarations or <tt>using</tt> declarations. It's important that these occur after including all headers, to ensure the environment see by the headers is not polluted, which may conceal or cause problems.
** Any namespace, forward declarations or <tt>using</tt> declarations. It's important that these occur after including all headers, to ensure the environment see by the headers is not polluted, which may conceal or cause problems.
* Respect the 80-column rule (and enable the right-hand margin in your editor if it supports one). This is not just pedantry, it makes comparing diffs side-by-side easier, or viewing code in other UI tools (eg debuggers). The most important reason is readability though - if your line is that long, perhaps you need to be using a typedef, wrapping some boolean logic in a predicate helper, or some other syntactic change.
* Break long functions and methods. Ideally, functions should fit on one screen - scrolling back up a function to check scope or variable naming harms readability. Sometimes longer methods do make sense, but the longer the method gets, the better your local variable naming needs to be.


== Standards ==
== Standards ==
580

edits

Navigation menu