blob: 461b0a4f9c92a2600e7653401732e8899699dde7 [file] [log] [blame]
<!DOCTYPE html>
<!--
Generated by Apache Maven Doxia at 2015-12-08
Rendered using Reflow Maven Skin 1.1.1 (http://andriusvelykis.github.io/reflow-maven-skin)
-->
<html xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
<title>Apache Trafodion C++ Coding Guidelines</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="" />
<meta http-equiv="content-language" content="en" />
<link href="http://netdna.bootstrapcdn.com/bootswatch/2.3.2/cerulean/bootstrap.min.css" rel="stylesheet" />
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css" rel="stylesheet" />
<link href="./css/bootswatch.css" rel="stylesheet" />
<link href="./css/reflow-skin.css" rel="stylesheet" />
<link href="http://yandex.st/highlightjs/7.5/styles/default.min.css" rel="stylesheet" />
<link href="./css/lightbox.css" rel="stylesheet" />
<link href="./css/site.css" rel="stylesheet" />
<link href="./css/print.css" rel="stylesheet" media="print" />
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body class="page-cplusplus-coding-guidelines project-trafodion" data-spy="scroll" data-offset="60" data-target="#toc-scroll-target">
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target="#top-nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="index.html">Apache <span class="color-highlight">Trafodion</span></a>
<div class="nav-collapse collapse" id="top-nav-collapse">
<ul class="nav pull-right">
<li ><a href="download.html" title="Download">Download</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">About <b class="caret"></b></a>
<ul class="dropdown-menu">
<li ><a href="index.html" title="Project Overview">Project Overview</a></li>
<li ><a href="new-features.html" title="New Features">New Features</a></li>
<li ><a href="roadmap.html" title="Roadmap">Roadmap</a></li>
<li ><a href="performance.html" title="Performance">Performance</a></li>
<li ><a href="http:divider" title=""></a></li>
<li ><a href="team-list.html" title="Team">Team</a></li>
<li ><a href="presentations.html" title="Presentations">Presentations</a></li>
<li ><a href="mail-lists.html" title="Mailing List">Mailing List</a></li>
<li ><a href="http:divider" title=""></a></li>
<li ><a href="source-repository.html" title="Source Repository">Source Repository</a></li>
<li ><a href="issue-tracking.html" title="Issue Tracking">Issue Tracking</a></li>
<li ><a href="license.html" title="License">License</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Using <b class="caret"></b></a>
<ul class="dropdown-menu">
<li ><a href="quickstart.html" title="Quick Start">Quick Start</a></li>
<li ><a href="download.html" title="Download">Download</a></li>
<li ><a href="install.html" title="Install">Install</a></li>
<li ><a href="management.html" title="Managing Trafodion">Managing Trafodion</a></li>
<li ><a href="http:divider" title=""></a></li>
<li ><a href="documentation.html" title="Documentation">Documentation</a></li>
<li ><a href="faq.html" title="FAQ">FAQ</a></li>
<li ><a href="release-notes.html" title="Release Notes">Release Notes</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Features <b class="caret"></b></a>
<ul class="dropdown-menu">
<li ><a href="architecture-overview.html" title="Architecture Overview">Architecture Overview</a></li>
<li ><a href="http:divider" title=""></a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/security-ansi-schemas" title="ANSI Schema Support" class="externalLink">ANSI Schema Support</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/ustat-automation" title="Automated Update Statistics" class="externalLink">Automated Update Statistics</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/bulkunload" title="Bulk Unload" class="externalLink">Bulk Unload</a></li>
<li ><a href="https://wiki.trafodion.org/wiki/index.php/Trafodion_Manageability#Logging_Events" title="Event Handling" class="externalLink">Event Handling</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/hybrid-query-cache" title="Hybrid Query Cache" class="externalLink">Hybrid Query Cache</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/identity-column" title="Identity Column" class="externalLink">Identity Column</a></li>
<li ><a href="https://wiki.trafodion.org/wiki/index.php/Creating_Statistics_During_Bulk_Load" title="Immediate Update Statistics" class="externalLink">Immediate Update Statistics</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/lob-support" title="Large Object (LOB)" class="externalLink">Large Object (LOB)</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/ddl-query-invalidation" title="Metadata Query Invalidation" class="externalLink">Metadata Query Invalidation</a></li>
<li ><a href="https://cwiki.apache.org/confluence/display/TRAFODION/Cmp-divisioning" title="Multi-Temperature Data" class="externalLink">Multi-Temperature Data</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/access-external-hbase-tables" title="Native HBase Tables" class="externalLink">Native HBase Tables</a></li>
<li ><a href="docs/Trafodion_odb_User_Guide.pdf" title="ODB">ODB</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/sql-query-cancel" title="Query Cancel" class="externalLink">Query Cancel</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/security-privilege-updates" title="Privilege Checking" class="externalLink">Privilege Checking</a></li>
<li ><a href="https://wiki.trafodion.org/wiki/index.php/Trafodion_Manageability" title="Repository" class="externalLink">Repository</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/enable-get-statistics-thru-rms" title="Runtime Management System" class="externalLink">Runtime Management System</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/sequence-numbers" title="Sequence Numbers" class="externalLink">Sequence Numbers</a></li>
<li ><a href="https://blueprints.launchpad.net/trafodion/+spec/skew-buster" title="Skew Buster" class="externalLink">Skew Buster</a></li>
<li ><a href="https://wiki.trafodion.org/wiki/index.php/Tutorial:_The_object-oriented_UDF_interface" title="Table-Oriented UDF" class="externalLink">Table-Oriented UDF</a></li>
<li ><a href="https://wiki.trafodion.org/wiki/index.php/Data_Loading#Trickle_Loading_Data_Into_Trafodion_Tables" title="Trickle Load" class="externalLink">Trickle Load</a></li>
<li ><a href="http:divider" title=""></a></li>
<li ><a href="https://wiki.trafodion.org/wiki/index.php/Backup_and_Restore" title="Backup/Restore Utility" class="externalLink">Backup/Restore Utility</a></li>
<li ><a href="https://wiki.trafodion.org/wiki/index.php/Metadata_Cleanup" title="Metadata Cleanup Utility" class="externalLink">Metadata Cleanup Utility</a></li>
</ul>
</li>
<li class="dropdown active">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contributing <b class="caret"></b></a>
<ul class="dropdown-menu">
<li ><a href="contribute.html" title="Contribute">Contribute</a></li>
<li ><a href="advocate.html" title="Advocate">Advocate</a></li>
<li ><a href="develop.html" title="Develop">Develop</a></li>
<li ><a href="testing.html" title="Test">Test</a></li>
<li ><a href="merge.html" title="Merge">Merge</a></li>
<li ><a href="release.html" title="Release">Release</a></li>
<li ><a href="http:divider" title=""></a></li>
<li ><a href="create-dev-environment.html" title="Create Dev Environment">Create Dev Environment</a></li>
<li ><a href="manage-dev-environment.html" title="Manage Dev Environment">Manage Dev Environment</a></li>
<li ><a href="setup-build-environment.html" title="Setup Build Environment">Setup Build Environment</a></li>
<li ><a href="build.html" title="Build Trafodion">Build Trafodion</a></li>
<li ><a href="http:divider" title=""></a></li>
<li ><a href="code.html" title="Modify Code">Modify Code</a></li>
<li ><a href="tests.html" title="Modify Tests">Modify Tests</a></li>
<li ><a href="document.html" title="Modify Documentation">Modify Documentation</a></li>
<li ><a href="website.html" title="Modify Web Site">Modify Web Site</a></li>
<li ><a href="wiki.html" title="Modify Wiki Pages">Modify Wiki Pages</a></li>
<li ><a href="http:divider" title=""></a></li>
<li class="active"><a href="" title="C++ Coding Guidelines">C++ Coding Guidelines</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Apache <b class="caret"></b></a>
<ul class="dropdown-menu">
<li ><a href="http://incubator.apache.org/projects/trafodion.html" title="Status Page" target="_blank" class="externalLink">Status Page</a></li>
<li ><a href="http://www.apache.org/foundation/how-it-works.html" title="Apache Foundation" target="_blank" class="externalLink">Apache Foundation</a></li>
<li ><a href="http://www.apache.org/licenses/" title="Apache License" target="_blank" class="externalLink">Apache License</a></li>
<li ><a href="http://www.apache.org/security/" title="Apache Security" target="_blank" class="externalLink">Apache Security</a></li>
<li ><a href="http:divider" title=""></a></li>
<li ><a href="http://www.apache.org/foundation/sponsorship.html" title="Sponsorship" target="_blank" class="externalLink">Sponsorship</a></li>
<li ><a href="http://www.apache.org/foundation/thanks.html" title="Thanks" target="_blank" class="externalLink">Thanks</a></li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container">
<!-- Masthead
================================================== -->
<header>
<div class="jumbotron subhead">
<div class="row" id="banner">
<div class="span12">
<div class="pull-left">
<a href="index.html" id="bannerLeft"><h1>Apache <span class="color-highlight">Trafodion</span></h1></a>
<p class="lead">Transactional SQL-on-Hadoop Database</p>
</div>
<div class="pull-right">
</div>
</div>
</div>
</div>
<div>
<ul class="breadcrumb">
<li><a href="index.html" title="Trafodion">Trafodion</a></li>
<li class="divider">/</li>
<li>C++ Coding Guidelines</li>
</ul>
</div>
<hr class="toc-separator" />
<div id="toc-bar" class="navbar" data-spy="affix" data-offset-top="250">
<div class="navbar-inner">
<div id="toc-scroll-target" class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target="#toc-nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<div class="nav-collapse collapse" id="toc-nav-collapse">
<ul id="toc" class="nav">
<li class="dropdown">
<a href="#header_files" title="Header Files" class="dropdown-toggle" role="button" data-toggle="dropdown" data-target="#">Header Files <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<!-- Repeat the item, otherwise it is not clickable as the dropdown root -->
<li><a href="#header_files" title="Header Files">Header Files</a></li>
<li class="divider"></li>
<li><a href="#Including_Standard_Header_Files" title="Including Standard Header Files">Including Standard Header Files</a></li>
<li><a href="#Include_Guards" title="Include Guards">Include Guards</a></li>
</ul>
</li>
<li class="divider-vertical"></li>
<li class="dropdown">
<a href="#variable_declaration_and_naming_standards" title="Variable Declaration and Naming Standards" class="dropdown-toggle" role="button" data-toggle="dropdown" data-target="#">Variable Declaration and Naming Standards <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<!-- Repeat the item, otherwise it is not clickable as the dropdown root -->
<li><a href="#variable_declaration_and_naming_standards" title="Variable Declaration and Naming Standards">Variable Declaration and Naming Standards</a></li>
<li class="divider"></li>
<li><a href="#Class_Member_Variable_Names" title="Class Member Variable Names">Class Member Variable Names</a></li>
<li><a href="#Function_Names" title="Function Names">Function Names</a></li>
<li><a href="#Enums" title="Enums">Enums</a></li>
<li><a href="#Boolean_Variables" title="Boolean Variables">Boolean Variables</a></li>
<li><a href="#Constants" title="Constants">Constants</a></li>
<li><a href="#Namespace_Names" title="Namespace Names">Namespace Names</a></li>
</ul>
</li>
<li class="divider-vertical"></li>
<li class="dropdown">
<a href="#indentation_and_formatting" title="Indentation and Formatting" class="dropdown-toggle" role="button" data-toggle="dropdown" data-target="#">Indentation and Formatting <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<!-- Repeat the item, otherwise it is not clickable as the dropdown root -->
<li><a href="#indentation_and_formatting" title="Indentation and Formatting">Indentation and Formatting</a></li>
<li class="divider"></li>
<li><a href="#Indentation" title="Indentation">Indentation</a></li>
</ul>
</li>
<li class="divider-vertical"></li>
<li class="dropdown">
<a href="#comments" title="Comments" class="dropdown-toggle" role="button" data-toggle="dropdown" data-target="#">Comments <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<!-- Repeat the item, otherwise it is not clickable as the dropdown root -->
<li><a href="#comments" title="Comments">Comments</a></li>
<li class="divider"></li>
<li><a href="#Comment_Style" title="Comment Style">Comment Style</a></li>
<li><a href="#WhenWhere_Comments_Should_Be_Used" title="When/Where Comments Should Be Used">When/Where Comments Should Be Used</a></li>
</ul>
</li>
<li class="divider-vertical"></li>
<li class="dropdown">
<a href="#error_handling" title="Error Handling" class="dropdown-toggle" role="button" data-toggle="dropdown" data-target="#">Error Handling <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<!-- Repeat the item, otherwise it is not clickable as the dropdown root -->
<li><a href="#error_handling" title="Error Handling">Error Handling</a></li>
<li class="divider"></li>
<li><a href="#Asserts" title="Asserts">Asserts</a></li>
<li><a href="#Error_ReturnRetrieval" title="Error Return/Retrieval">Error Return/Retrieval</a></li>
<li><a href="#Exception_Handling" title="Exception Handling">Exception Handling</a></li>
</ul>
</li>
<li class="divider-vertical"></li>
<li class="dropdown">
<a href="#" title="More&hellip;" class="dropdown-toggle" role="button" data-toggle="dropdown" data-target="#">&hellip; <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<li class="dropdown-submenu">
<a href="#general_guidelines" title="General Guidelines">General Guidelines</a>
<ul class="dropdown-menu" role="menu">
<li><a href="#Casting" title="Casting">Casting</a></li>
<li><a href="#Types" title="Types">Types</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
</header>
<div class="main-body">
<div class="row">
<div class="span12">
<div class="body-content">
<!-- Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the
License. -->
<p>These are the C++ coding guidelines that are part of the acceptance criteria for code submitted to the Trafodion. Trafodion reviewers use these guidelines when reviewing changes.</p>
<p>The guidelines describe practices that are either required or preferred. In addition, areas where there is no preference between two or more practices are described.</p>
<p>Trafodion is composed of several distinct sub-projects, some of which have coding guidelines that differ from the Trafodion standard; for example, a requirement in most areas of the code may be only preferred in others.</p>
<p>There may also be existing code that violates one or more of the published requirements. The intent is to correct these over time, and corrections are encouraged when changing code to make a fix or implement new functionality. However, changes that are solely coding guideline changes are not recommended since this places undue burden on the reviewers.</p>
<div class="page-header">
<h1 id="header_files">Header Files</h1>
</div>
<p>Keep <b><tt>#include</tt></b> directives to a minimum in header files. </p>
<p>You may forward declare classes and structs when the only use within the header file is a pointer or reference. While includes should be kept to a minimum, if something is used in a header file and cannot be forward declared, it must be explicitly included. </p>
<p>All files, headers and implementation, should include everything they need to be self-sufficient. They should never assume something will be pre-included. In other words, the contents of a header file should compile cleanly by itself. To help ensure this, all implementation files should include their respective header file first.</p>
<p>Header files should not contain declarations for public items that are only used by the implementation file. Public items that are require in the implementation file but not the header file should be declared in the implementation file. The preference is NOT to create header files that consist only of includes of other header files.</p>
<p>Declare as little as possible in the header file and keep as much of the actual implementation private as is reasonable. For instance, don’t include in a header file declarations of types, enums, and functions that are only referenced by the implementation file.</p>
<div class="section">
<h2 id="Including_Standard_Header_Files">Including Standard Header Files</h2>
<p>The preference is for C++ style includes over C style includes for standard header files.</p>
<div class="source">
<div class="source">
<pre>//Preferred
#include &lt;cstdio&gt;
//Accepted
#include &lt;stdio.h&gt;
</pre>
</div>
</div>
</div>
<div class="section">
<h2 id="Include_Guards">Include Guards</h2>
<p>All header files must use include guards. The name of the include guard <b><tt>#define</tt></b> should be the filename in all uppercase, with underscore used in place of periods.</p>
<p>For instance, if the header file is named <b><tt>ServerInterface_ODBC.h</tt></b>, the header file should begin and end as follows:</p>
<div class="source">
<div class="source">
<pre>#ifndef SERVERINTERFACE_ODBC_H
#define SERVERINTERFACE_ODBC_H
...
#endif /* SERVERINTERFACE_ODBC_H */
</pre>
</div>
</div>
<p>Comments following the <b><tt>#endif</tt></b> indicating the include guard are preferred.</p>
<h1 id="variable_declaration_and_naming_standards">Variable Declaration and Naming Standards</h1>
<p>Trafodion uses a combination of Pascal and Camel case. </p>
<ul>
<li>Pascal case means that the first letter in each word in an identifier is capitalized.</li>
<li>Camel case is similar except the first letter is in lower case.</li>
</ul>
<p>For both, underscores are <b>not</b> used to separate words. The general rule is that identifiers with local scope start with a lower case letter and identifiers with global scope start with an upper case letter.</p>
<div class="source">
<div class="source">
<pre>//Pascal case
class AuthenticationMessage;
//Camel case (aka lower Camel case or camelCase)
int logonCount;
Class Names
</pre>
</div>
</div>
<p>Class names should be Pascal case and should describe the object contents (not what it does), with as little abbreviation as possible. When names include acronyms, the acronyms should be in all upper case.</p>
<p><b>Acceptable Examples</b></p>
<div class="source">
<div class="source">
<pre>//Preferred
class SQLSessionContext; // an object that contains the context for a SQL session
class PrivilegeList; // a list of privileges
</pre>
</div>
</div>
<p><b>Poor Examples</b></p>
<div class="source">
<div class="source">
<pre>class OutputInfo; // Doesn’t describe class contents, no context
class ReadTableDef; // Describes what class does, not contents
class Cmdline_Args; // Prefer Pascal case, no underscore, for class names
</pre>
</div>
</div>
</div>
<div class="section">
<h2 id="Class_Member_Variable_Names">Class Member Variable Names</h2>
<p>Private member data variables should be suffixed with an underscore and should use Camel case. When names include acronyms, the acronyms should be in all upper or all lower case, dependent on which case the first letter should be.</p>
<p><b>Example</b></p>
<div class="source">
<div class="source">
<pre>class Employee
{
public:
Employee ();
private:
std::string firstName_;
std::string lastName_;
uint16_t departmentNumber_;
std::string departmentName_;
uint32_t irsSSN_;
}
</pre>
</div>
</div>
</div>
<div class="section">
<h2 id="Function_Names">Function Names</h2>
<p>Class member functions and static file functions should use Camel case. External non-class functions should use Pascal case. Except for constructors, destructors, and operators, the function name should include a verb that describes the action the function is performing.</p>
<p><b>Good Examples</b></p>
<div class="source">
<div class="source">
<pre>//Class member functions
int32_t getSalary() const;
int32_t setAuthID();
int32_t closeAllCursors();
</pre>
</div>
</div>
<p><b>Bad Examples</b></p>
<div class="source">
<div class="source">
<pre>// Is it setting break enabled, returning it or ???
int32_t SQLCLI_BreakEnabled();
</pre>
</div>
</div>
</div>
<div class="section">
<h2 id="Enums">Enums</h2>
<p>Enum types should use Pascal case and describe the class of enums. If the enum is declared outside of a class, the type name should include an indication of the scope of the enums.</p>
<p>Enums themselves should be declared as all upper case. The names may begin with a common prefix or be independent, depending on the usage.</p>
<p>When enums represent an arbitrary set of return values (that is, error codes, state codes, etc.), then avoid the values -1, 0, and 1 if using weakly typed enums, to reduce the chance of matches with Booleans or uninitialized variables.</p>
<p>The preference is to declare enums as strongly typed.</p>
<div class="source">
<div class="source">
<pre>enum class EnumName {...};
</pre>
</div>
</div>
</div>
<div class="section">
<h2 id="Boolean_Variables">Boolean Variables</h2>
<p>Boolean variables names should include a verb, state, and optionally a noun (object whose state is in question) indicating the nature of the Boolean. Any combination is acceptable, however verbState is the most common.</p>
<p><b>Good Examples</b></p>
<div class="source">
<div class="source">
<pre>bool isValid; // verbState
bool isValidTable; // verbStateNoun
bool tableIsDroppable; // nounVerbState
bool hasData; // verbState
</pre>
</div>
</div>
<p><b>Bad Examples</b></p>
<div class="source">
<div class="source">
<pre>bool valid;
bool tableState;
bool empty;
</pre>
</div>
</div>
<p>Functions that return a Boolean should also have names of the form verbState or verbStateNoun if the functions return state information. (This naming standard does not apply to functions returning Boolean as indication of success or failure.)</p>
<p><b>Good Examples</b></p>
<div class="source">
<div class="source">
<pre>bool isValidHbaseName();
bool isHostNameExcluded();
bool canUseCbServer();
</pre>
</div>
</div>
<p><b>Bad Examples</b></p>
<div class="source">
<div class="source">
<pre>// Don’t use get for Boolean accessors
bool getUDRAccessModeViolation();
// Don’t use integer return for Boolean functions
short existsInHBase();
// Function name implies it is sending settings to the compiler, but it is
// actually only returning an indication that settings should be sent.
// A better name would be shouldSendSettingsToCompiler().
bool sendSettingsToCompiler();
</pre>
</div>
</div>
<p>Parts of Trafodion code use one of two Boolean typedefs, <b><tt>NABoolean</tt></b> and <b><tt>ComBoolean</tt></b>, declared as follows:</p>
<div class="source">
<div class="source">
<pre>typedef int Int32;
typedef Int32 NABoolean;
typedef NABoolean ComBoolean;
const NABoolean TRUE = (1 == 1);
const NABoolean FALSE = (0 == 1);
</pre>
</div>
</div>
<p>Exercise care when mixing usage of bool and <b><tt>NABoolean</tt></b>/<b><tt>ComBoolean</tt></b> types, as the latter are not guaranteed to only contain values of TRUE and FALSE. The use of non-standard Boolean types is gradually being phased out.</p>
</div>
<div class="section">
<h2 id="Constants">Constants</h2>
<p>All constant names should be all upper case, regardless of how the constant is declared. That is, enums, defines, and variables with the <b><tt>const</tt></b> modifier should be named in all upper case.</p>
<p>Defines, enums, and const are all permitted and used throughout Trafodion, although most code in Trafodion uses enum for numerical constants and defines for character constants. </p>
<p>For new code, the use of const char or string is preferred for character constants instead of defines.</p>
</div>
<div class="section">
<h2 id="Namespace_Names">Namespace Names</h2>
<p>The preference is for namespaces to be all lower case, with preference to single words (note the exception to the rule that a name with global scope should start with an upper case). </p>
<p>If a namespace must be dual-worded, use underscores. If mixed case names are used, Pascal case is preferred.</p>
<p><b>Examples</b></p>
<div class="source">
<div class="source">
<pre>//Preferred
namespace compiler
//Accepted
namespace Compiler
</pre>
</div>
</div>
<h1 id="indentation_and_formatting">Indentation and Formatting</h1>
</div>
<div class="section">
<h2 id="Indentation">Indentation</h2>
<p>TAB characters are not permitted in source files except for text files (for example, makefiles) that require them.</p>
<p>Trafodion code uses several indenting depths, including 2, 3, 4, and 8 spaces. Most common is 2 and 3. </p>
<p>Use the style found in existing code, and when writing new code, use either 2, 3, or 4, and remain consistent.</p>
<p>A variety of control block indentation styles are used throughout Trafodion, most commonly Allman, Whitesmith, Stroustrup, and GNU. Follow the predominant style when making small to medium changes to existing code. For new code, the Allman style is preferred.</p>
<div class="source">
<div class="source">
<pre>//Allman
if (x &gt; 5)
{
error = doThis(x);
if (error != 0)
{
return false;
}
}
else
{
doThat(x);
}
//Whitesmith
if (x &gt; 5)
{
error = doThis(x);
if (error != 0)
{
return false;
}
}
else
{
doThat(x);
}
//Stroustrup
if (x &gt; 5) {
error = doThis(x);
if (error != 0) {
return false;
}
}
else {
doThat(x);
}
</pre>
</div>
</div>
<p>Note that the Stroustrup and the similar K&amp;R formats were popularized by usage in books where conservation of line count was a goal.</p>
<div class="source">
<div class="source">
<pre>//GNU
if (x &gt; 5)
{
error = doThis(x);
if (error != 0)
{
return false;
}
}
else
{
doThat(x);
}
</pre>
</div>
</div>
<h1 id="comments">Comments</h1>
</div>
<div class="section">
<h2 id="Comment_Style">Comment Style</h2>
<p>C++ style comments are preferred, but C comments are acceptable as well.</p>
<p>Some code uses Doxygen style comments, but this is not required.</p>
</div>
<div class="section">
<h2 id="WhenWhere_Comments_Should_Be_Used">When/Where Comments Should Be Used</h2>
<p>Every file should have a comment at the beginning describing the purpose of the file.</p>
<p>In header files where classes are declared, there should be a comment describing the class, including purpose and usage. Also describe anything out of the ordinary, such as the use of multiple inheritance.</p>
<p>Within implementation files, in addition to the comment at the beginning of the file, add comments for any global or static variables defined in the file, and how the variable is handled in a multi-threaded environment (if applicable).</p>
<p>Also, for each function defined, describe the purpose and intent of the function. For each parameter, list whether it is input or output (or both), how it is used, and any range restrictions imposed. For functions not returning void, describe the possible return values.</p>
<p>Within the body of the function, there is no need to write comments that document the obvious. But if there is any complexity to the logic, at a minimum document the intent, and consider documenting the details (assumptions, limits, unexpected side effects from function calls, etc.)</p>
<p>If a feature is only partially implemented, add a comment indicating at a high level what work remains. Prefix the comment with //TODO.</p>
<div class="source">
<div class="source">
<pre>//TODO Code is currently not thread safe. Need to protect allocation of ...
</pre>
</div>
</div>
<h1 id="error_handling">Error Handling</h1>
</div>
<div class="section">
<h2 id="Asserts">Asserts</h2>
<p>Trafodion uses asserts in the “debug” build. Use asserts freely, but ensure they do not contain any side effects as the code is not present in the “release” build.</p>
</div>
<div class="section">
<h2 id="Error_ReturnRetrieval">Error Return/Retrieval</h2>
<p>Avoid the use of integer return codes for success and error codes. Instead, use bool for simple succeeded/failed and enum types for returns with multiple conditions.</p>
</div>
<div class="section">
<h2 id="Exception_Handling">Exception Handling</h2>
<p>Trafodion code mixes usage of exceptions and error returns. When using try/catch blocks, keep the scope as small as possible. Ensure all exceptions thrown are handled, potentially in main() if nowhere else.</p>
<h1 id="general_guidelines">General Guidelines</h1>
</div>
<div class="section">
<h2 id="Casting">Casting</h2>
<p>Avoid using C-style casts. Use C++-style casts instead, as they are often safer and easier to search for.</p>
<div class="source">
<div class="source">
<pre>//Preferred
int x = static_cast&lt;int&gt;(shortVariable);
MyType *myVar = reinterpret_cast&lt;MyType *&gt;(voidPtr);
</pre>
</div>
</div>
<p>Don’t blindly cast to remove a compiler error or warning. Ensure the cast is safe.</p>
<p>Use const casting sparingly. Often the use of mutable or changing a function to be const correct is a better solution.</p>
</div>
<div class="section">
<h2 id="Types">Types</h2>
<p>Use standard types defined in <b><tt>&lt;cstdint&gt;</tt></b> or <b><tt>&lt;stdint.h&gt;</tt></b>. Note that Trafodion defines and uses many non-standard types (for example, <b><tt>Int32</tt></b>, <b><tt>Lng32</tt></b>), but this usage is being phased out.</p>
<p>Use types with explicit sizes (for example, <b><tt>int32_t</tt></b>, <b><tt>int64_t</tt></b>) when size is a factor in the code, such as an external API, or column in a table. </p>
<p>Where size is not a factor (counters, indexes) a non-sized type such as <b><tt>int</tt></b> or <b><tt>long</tt></b> may be used. However, in general, <b><tt>size_t</tt></b> and <b><tt>ssize_t</tt></b> are preferred for variables where fixed size is not required.</p>
</div>
</div>
</div>
</div>
</div>
</div><!-- /container -->
<!-- Footer
================================================== -->
<footer class="well">
<div class="container">
<div class="row">
<div class="span2 bottom-nav">
<ul class="nav nav-list">
<li class="nav-header">About</li>
<li >
<a href="index.html" title="Project Overview">Project Overview</a>
</li>
<li >
<a href="new-features.html" title="New Features">New Features</a>
</li>
<li >
<a href="roadmap.html" title="Roadmap">Roadmap</a>
</li>
<li >
<a href="performance.html" title="Performance">Performance</a>
</li>
<li >
<a href="http:divider" title=""></a>
</li>
<li >
<a href="team-list.html" title="Team">Team</a>
</li>
<li >
<a href="presentations.html" title="Presentations">Presentations</a>
</li>
<li >
<a href="mail-lists.html" title="Mailing List">Mailing List</a>
</li>
<li >
<a href="http:divider" title=""></a>
</li>
<li >
<a href="source-repository.html" title="Source Repository">Source Repository</a>
</li>
<li >
<a href="issue-tracking.html" title="Issue Tracking">Issue Tracking</a>
</li>
<li >
<a href="license.html" title="License">License</a>
</li>
</ul>
</div>
<div class="span2 bottom-nav">
<ul class="nav nav-list">
<li class="nav-header">Using</li>
<li >
<a href="quickstart.html" title="Quick Start">Quick Start</a>
</li>
<li >
<a href="download.html" title="Download">Download</a>
</li>
<li >
<a href="install.html" title="Install">Install</a>
</li>
<li >
<a href="management.html" title="Managing Trafodion">Managing Trafodion</a>
</li>
<li >
<a href="http:divider" title=""></a>
</li>
<li >
<a href="documentation.html" title="Documentation">Documentation</a>
</li>
<li >
<a href="faq.html" title="FAQ">FAQ</a>
</li>
<li >
<a href="release-notes.html" title="Release Notes">Release Notes</a>
</li>
</ul>
</div>
<div class="span2 bottom-nav">
<ul class="nav nav-list">
<li class="nav-header">Features</li>
<li >
<a href="architecture-overview.html" title="Architecture Overview">Architecture Overview</a>
</li>
<li >
<a href="http:divider" title=""></a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/security-ansi-schemas" title="ANSI Schema Support" class="externalLink">ANSI Schema Support</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/ustat-automation" title="Automated Update Statistics" class="externalLink">Automated Update Statistics</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/bulkunload" title="Bulk Unload" class="externalLink">Bulk Unload</a>
</li>
<li >
<a href="https://wiki.trafodion.org/wiki/index.php/Trafodion_Manageability#Logging_Events" title="Event Handling" class="externalLink">Event Handling</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/hybrid-query-cache" title="Hybrid Query Cache" class="externalLink">Hybrid Query Cache</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/identity-column" title="Identity Column" class="externalLink">Identity Column</a>
</li>
<li >
<a href="https://wiki.trafodion.org/wiki/index.php/Creating_Statistics_During_Bulk_Load" title="Immediate Update Statistics" class="externalLink">Immediate Update Statistics</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/lob-support" title="Large Object (LOB)" class="externalLink">Large Object (LOB)</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/ddl-query-invalidation" title="Metadata Query Invalidation" class="externalLink">Metadata Query Invalidation</a>
</li>
<li >
<a href="https://cwiki.apache.org/confluence/display/TRAFODION/Cmp-divisioning" title="Multi-Temperature Data" class="externalLink">Multi-Temperature Data</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/access-external-hbase-tables" title="Native HBase Tables" class="externalLink">Native HBase Tables</a>
</li>
<li >
<a href="docs/Trafodion_odb_User_Guide.pdf" title="ODB">ODB</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/sql-query-cancel" title="Query Cancel" class="externalLink">Query Cancel</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/security-privilege-updates" title="Privilege Checking" class="externalLink">Privilege Checking</a>
</li>
<li >
<a href="https://wiki.trafodion.org/wiki/index.php/Trafodion_Manageability" title="Repository" class="externalLink">Repository</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/enable-get-statistics-thru-rms" title="Runtime Management System" class="externalLink">Runtime Management System</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/sequence-numbers" title="Sequence Numbers" class="externalLink">Sequence Numbers</a>
</li>
<li >
<a href="https://blueprints.launchpad.net/trafodion/+spec/skew-buster" title="Skew Buster" class="externalLink">Skew Buster</a>
</li>
<li >
<a href="https://wiki.trafodion.org/wiki/index.php/Tutorial:_The_object-oriented_UDF_interface" title="Table-Oriented UDF" class="externalLink">Table-Oriented UDF</a>
</li>
<li >
<a href="https://wiki.trafodion.org/wiki/index.php/Data_Loading#Trickle_Loading_Data_Into_Trafodion_Tables" title="Trickle Load" class="externalLink">Trickle Load</a>
</li>
<li >
<a href="http:divider" title=""></a>
</li>
<li >
<a href="https://wiki.trafodion.org/wiki/index.php/Backup_and_Restore" title="Backup/Restore Utility" class="externalLink">Backup/Restore Utility</a>
</li>
<li >
<a href="https://wiki.trafodion.org/wiki/index.php/Metadata_Cleanup" title="Metadata Cleanup Utility" class="externalLink">Metadata Cleanup Utility</a>
</li>
</ul>
</div>
<div class="span2 bottom-nav">
<ul class="nav nav-list">
<li class="nav-header">Contributing</li>
<li >
<a href="contribute.html" title="Contribute">Contribute</a>
</li>
<li >
<a href="advocate.html" title="Advocate">Advocate</a>
</li>
<li >
<a href="develop.html" title="Develop">Develop</a>
</li>
<li >
<a href="testing.html" title="Test">Test</a>
</li>
<li >
<a href="merge.html" title="Merge">Merge</a>
</li>
<li >
<a href="release.html" title="Release">Release</a>
</li>
<li >
<a href="http:divider" title=""></a>
</li>
<li >
<a href="create-dev-environment.html" title="Create Dev Environment">Create Dev Environment</a>
</li>
<li >
<a href="manage-dev-environment.html" title="Manage Dev Environment">Manage Dev Environment</a>
</li>
<li >
<a href="setup-build-environment.html" title="Setup Build Environment">Setup Build Environment</a>
</li>
<li >
<a href="build.html" title="Build Trafodion">Build Trafodion</a>
</li>
<li >
<a href="http:divider" title=""></a>
</li>
<li >
<a href="code.html" title="Modify Code">Modify Code</a>
</li>
<li >
<a href="tests.html" title="Modify Tests">Modify Tests</a>
</li>
<li >
<a href="document.html" title="Modify Documentation">Modify Documentation</a>
</li>
<li >
<a href="website.html" title="Modify Web Site">Modify Web Site</a>
</li>
<li >
<a href="wiki.html" title="Modify Wiki Pages">Modify Wiki Pages</a>
</li>
<li >
<a href="http:divider" title=""></a>
</li>
<li class="active">
<a href="#" title="C++ Coding Guidelines">C++ Coding Guidelines</a>
</li>
</ul>
</div>
<div class="span4 bottom-description">
<blockquote><a href="http://trafodion.apache.org/">Apache Trafodion</a> is a webscale SQL-on-Hadoop solution enabling transactional or operational
workloads on Hadoop. <br /><br />The name &quot;Trafodion&quot; (the Welsh word for transactions, pronounced
&quot;Tra-vod-eee-on&quot;) was chosen specifically to emphasize the differentiation that
Trafodion provides in closing a critical gap in the Hadoop ecosystem.<br /><br />
Trafodion builds on the scalability, elasticity, and flexibility of Hadoop. Trafodion extends
Hadoop to provide guaranteed transactional integrity, enabling new kinds of big data
applications to run on Hadoop.</blockquote>
</div>
</div>
</div>
</footer>
<div class="container subfooter">
<div class="row">
<div class="span12">
<p class="pull-right"><a href="#">Back to top</a></p>
<p class="copyright">Copyright &copy;2015 <a href="http://www.apache.org">Apache Software Foundation</a>. All Rights Reserved.</p>
<hr/>
<div class="row span16">
<span>Disclaimer: Apache Trafodion is an effort undergoing incubation at the Apache Software Foundation (ASF), sponsored by the Apache Incubator PMC.
Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making
process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the
completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.</span>
<br/>
<br/>
<span>Apache, Apache Maven, Apache Maven Fluido Skin, the Apache feather logo, the Apache Maven project logo and the Apache Incubator project logo
are trademarks of The Apache Software Foundation.</span>
<br/>
<br/>
<span>
<a target="_blank" href="http://www.apache.org">
<img id="asf-logo" alt="Apache Software Foundation" src="images/logos/feather-small.gif"/>
</a>
<a target="_blank" href="http://incubator.apache.org/">
<img id="incubator-logo" alt="Apache Incubator" src="images/logos/egg-logo.gif"/>
</a>
</span>
</div> </div>
</div>
</div>
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<script src="./js/lightbox.min.js"></script>
<script src="./js/reflow-scroll.js"></script>
<script src="http://yandex.st/highlightjs/7.5/highlight.min.js"></script>
<script src="./js/reflow-skin.js"></script>
</body>
</html>