blob: 3a0a856771a6d082ca81ec7a7020e4da3091b705 [file] [log] [blame]
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Conventions &mdash; Apache Arrow v2.0.0</title>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<!--[if lt IE 9]>
<script src="../../_static/js/html5shiv.min.js"></script>
<![endif]-->
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="canonical" href="https://arrow.apache.org/docs/developers/cpp/conventions.html" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="Fuzzing Arrow C++" href="fuzzing.html" />
<link rel="prev" title="Developing on Windows" href="windows.html" />
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setDoNotTrack", true]);
_paq.push(["disableCookies"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://analytics.apache.org/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '20']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home" alt="Documentation Home"> Apache Arrow
</a>
<div class="version">
2.0.0
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Specifications and Protocols</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../format/Versioning.html">Format Versioning and Stability</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../format/Columnar.html">Arrow Columnar Format</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../format/Flight.html">Arrow Flight RPC</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../format/Integration.html">Integration Testing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../format/CDataInterface.html">The Arrow C data interface</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../format/CStreamInterface.html">The Arrow C stream interface</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../format/Other.html">Other Data Structures</a></li>
</ul>
<p class="caption"><span class="caption-text">Libraries</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../status.html">Implementation Status</a></li>
<li class="toctree-l1"><a class="reference external" href="https://arrow.apache.org/docs/c_glib/">C/GLib</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../cpp/index.html">C++</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/apache/arrow/blob/master/csharp/README.md">C#</a></li>
<li class="toctree-l1"><a class="reference external" href="https://godoc.org/github.com/apache/arrow/go/arrow">Go</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../java/index.html">Java</a></li>
<li class="toctree-l1"><a class="reference external" href="https://arrow.apache.org/docs/js/">JavaScript</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/apache/arrow/blob/master/matlab/README.md">MATLAB</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../python/index.html">Python</a></li>
<li class="toctree-l1"><a class="reference external" href="https://arrow.apache.org/docs/r/">R</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/apache/arrow/blob/master/ruby/README.md">Ruby</a></li>
<li class="toctree-l1"><a class="reference external" href="https://docs.rs/crate/arrow/">Rust</a></li>
</ul>
<p class="caption"><span class="caption-text">Development</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../contributing.html">Contributing to Apache Arrow</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">C++ Development</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="building.html">Building Arrow C++</a></li>
<li class="toctree-l2"><a class="reference internal" href="development.html">Development Guidelines</a></li>
<li class="toctree-l2"><a class="reference internal" href="windows.html">Developing on Windows</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Conventions</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#file-naming">File Naming</a></li>
<li class="toctree-l3"><a class="reference internal" href="#comments-and-docstrings">Comments and Docstrings</a></li>
<li class="toctree-l3"><a class="reference internal" href="#memory-pools">Memory Pools</a></li>
<li class="toctree-l3"><a class="reference internal" href="#error-handling-and-exceptions">Error Handling and Exceptions</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="fuzzing.html">Fuzzing Arrow C++</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../python.html">Python Development</a></li>
<li class="toctree-l1"><a class="reference internal" href="../archery.html">Daily Development using Archery</a></li>
<li class="toctree-l1"><a class="reference internal" href="../crossbow.html">Packaging and Testing with Crossbow</a></li>
<li class="toctree-l1"><a class="reference internal" href="../docker.html">Running Docker Builds</a></li>
<li class="toctree-l1"><a class="reference internal" href="../benchmarks.html">Benchmarks</a></li>
<li class="toctree-l1"><a class="reference internal" href="../documentation.html">Building the Documentation</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Apache Arrow</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html" class="icon icon-home"></a> &raquo;</li>
<li><a href="index.html">C++ Development</a> &raquo;</li>
<li>Conventions</li>
<li class="wy-breadcrumbs-aside">
<a href="../../_sources/developers/cpp/conventions.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="conventions">
<h1>Conventions<a class="headerlink" href="#conventions" title="Permalink to this headline"></a></h1>
<p>This section provides some information about some of the abstractions and
development approaches we use to solve problems common to many parts of the C++
project.</p>
<div class="section" id="file-naming">
<h2>File Naming<a class="headerlink" href="#file-naming" title="Permalink to this headline"></a></h2>
<p>C++ source and header files should use underscores for word separation, not hyphens.
Compiled executables, however, will automatically use hyphens (such that
e.g. <code class="docutils literal notranslate"><span class="pre">src/arrow/scalar_test.cc</span></code> will be compiled into <code class="docutils literal notranslate"><span class="pre">arrow-scalar-test</span></code>).</p>
<p>C++ header files use the <code class="docutils literal notranslate"><span class="pre">.h</span></code> extension. Any header file name not
containing <code class="docutils literal notranslate"><span class="pre">internal</span></code> is considered to be a public header, and will be
automatically installed by the build.</p>
</div>
<div class="section" id="comments-and-docstrings">
<h2>Comments and Docstrings<a class="headerlink" href="#comments-and-docstrings" title="Permalink to this headline"></a></h2>
<p>Regular comments start with <code class="docutils literal notranslate"><span class="pre">//</span></code>.</p>
<p>Doxygen docstrings start with <code class="docutils literal notranslate"><span class="pre">///</span></code>, and Doxygen directives start with <code class="docutils literal notranslate"><span class="pre">\</span></code>,
like this:</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="c1">/// \brief Allocate a fixed size mutable buffer from a memory pool, zero its padding.</span>
<span class="c1">///</span>
<span class="c1">/// \param[in] size size of buffer to allocate</span>
<span class="c1">/// \param[in] pool a memory pool</span>
<span class="n">ARROW_EXPORT</span>
<span class="n">Result</span><span class="o">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">unique_ptr</span><span class="o">&lt;</span><span class="n">Buffer</span><span class="o">&gt;&gt;</span> <span class="n">AllocateBuffer</span><span class="p">(</span><span class="k">const</span> <span class="kt">int64_t</span> <span class="n">size</span><span class="p">,</span>
<span class="n">MemoryPool</span><span class="o">*</span> <span class="n">pool</span> <span class="o">=</span> <span class="n">NULLPTR</span><span class="p">);</span>
</pre></div>
</div>
<p>The summary line of a docstring uses the infinitive, not the indicative
(for example, “Allocate a buffer” rather than “Allocates a buffer”).</p>
</div>
<div class="section" id="memory-pools">
<h2>Memory Pools<a class="headerlink" href="#memory-pools" title="Permalink to this headline"></a></h2>
<p>We provide a default memory pool with <code class="docutils literal notranslate"><span class="pre">arrow::default_memory_pool()</span></code>.</p>
</div>
<div class="section" id="error-handling-and-exceptions">
<h2>Error Handling and Exceptions<a class="headerlink" href="#error-handling-and-exceptions" title="Permalink to this headline"></a></h2>
<p>For error handling, we return <code class="docutils literal notranslate"><span class="pre">arrow::Status</span></code> values instead of throwing C++
exceptions. Since the Arrow C++ libraries are intended to be useful as a
component in larger C++ projects, using <code class="docutils literal notranslate"><span class="pre">Status</span></code> objects can help with good
code hygiene by making explicit when a function is expected to be able to fail.</p>
<p>A more recent option is to return a <code class="docutils literal notranslate"><span class="pre">arrow::Result&lt;T&gt;</span></code> object that can
represent either a successful result with a <code class="docutils literal notranslate"><span class="pre">T</span></code> value, or an error result
with a <code class="docutils literal notranslate"><span class="pre">Status</span></code> value.</p>
<p>For expressing internal invariants and “cannot fail” errors, we use <code class="docutils literal notranslate"><span class="pre">DCHECK</span></code> macros
defined in <code class="docutils literal notranslate"><span class="pre">arrow/util/logging.h</span></code>. These checks are disabled in release builds
and are intended to catch internal development errors, particularly when
refactoring. These macros are not to be included in any public header files.</p>
<p>Since we do not use exceptions, we avoid doing expensive work in object
constructors. Objects that are expensive to construct may often have private
constructors, with public static factory methods that return <code class="docutils literal notranslate"><span class="pre">Status</span></code> or
<code class="docutils literal notranslate"><span class="pre">Result&lt;T&gt;</span></code>.</p>
<p>There are a number of object constructors, like <code class="docutils literal notranslate"><span class="pre">arrow::Schema</span></code> and
<code class="docutils literal notranslate"><span class="pre">arrow::RecordBatch</span></code> where larger STL container objects like <code class="docutils literal notranslate"><span class="pre">std::vector</span></code> may
be created. While it is possible for <code class="docutils literal notranslate"><span class="pre">std::bad_alloc</span></code> to be thrown in these
constructors, the circumstances where they would are somewhat esoteric, and it
is likely that an application would have encountered other more serious
problems prior to having <code class="docutils literal notranslate"><span class="pre">std::bad_alloc</span></code> thrown in a constructor.</p>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="fuzzing.html" class="btn btn-neutral float-right" title="Fuzzing Arrow C++" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="windows.html" class="btn btn-neutral float-left" title="Developing on Windows" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2016-2019 Apache Software Foundation
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
<script type="text/javascript" src="/docs/_static/versionwarning.js"></script></body>
</html>