blob: 4954063d35b68c2068f135143f99f2eb0a77165a [file] [log] [blame]
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia Site Renderer 1.8.1 at 2020-11-23
| Rendered using Apache Maven Fluido Skin 1.5
-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="Date-Revision-yyyymmdd" content="20201123" />
<meta http-equiv="Content-Language" content="en" />
<title>Apache Phoenix Omid &#x2013; Coding Guide</title>
<link rel="stylesheet" href="./css/apache-maven-fluido-1.5.min.css" />
<link rel="stylesheet" href="./css/site.css" />
<link rel="stylesheet" href="./css/print.css" media="print" />
<script type="text/javascript" src="./js/apache-maven-fluido-1.5.min.js"></script>
</head>
<body class="topBarEnabled">
<div id="topbar" class="navbar navbar-fixed-top ">
<div class="navbar-inner">
<div class="container" style="width: 100%;"><div class="nav-collapse">
<ul class="nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Home <b class="caret"></b></a>
<ul class="dropdown-menu">
<li> <a href="index.html" title="Overview">Overview</a>
</li>
<li> <a href="licenses.html" title="Licenses">Licenses</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Download <b class="caret"></b></a>
<ul class="dropdown-menu">
<li> <a href="https://github.com/apache/phoenix-omid" title="Omid Source Repository">Omid Source Repository</a>
</li>
<li> <a href="https://dist.apache.org/repos/dist/release/incubator/omid/" title="Apache Releases for version 1.0.1 and earlier">Apache Releases for version 1.0.1 and earlier</a>
</li>
<li> <a href="https://dist.apache.org/repos/dist/release/phoenix/" title="Apache Releases for version 1.0.2 and later">Apache Releases for version 1.0.2 and later</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">User Guide & API <b class="caret"></b></a>
<ul class="dropdown-menu">
<li> <a href="quickstart.html" title="Quickstart">Quickstart</a>
</li>
<li> <a href="basic-examples.html" title="API and Code Examples">API and Code Examples</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Technical Docs <b class="caret"></b></a>
<ul class="dropdown-menu">
<li> <a href="basic-concepts.html" title="Basic Concepts">Basic Concepts</a>
</li>
<li> <a href="omid-components.html" title="Omid Components">Omid Components</a>
</li>
<li> <a href="basic-algorithm.html" title="Basic Algorithm">Basic Algorithm</a>
</li>
<li> <a href="client-failure-management.html" title="Management of Client Failures">Management of Client Failures</a>
</li>
<li> <a href="http://yahoohadoop.tumblr.com/tagged/HBase" title="Blog Entries">Blog Entries</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contribute <b class="caret"></b></a>
<ul class="dropdown-menu">
<li> <a href="https://gitbox.apache.org/repos/asf/phoenix-omid.git" title="Source Code">Source Code</a>
</li>
<li> <a href="https://issues.apache.org/jira/browse/Omid" title="JIRA">JIRA</a>
</li>
<li> <a href="mailing-lists.html" title="Mailing Lists">Mailing Lists</a>
</li>
<li> <a href="coding-guide-and-style.html" title="Coding Guide and Style">Coding Guide and Style</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Project Reports <b class="caret"></b></a>
<ul class="dropdown-menu">
<li class="dropdown-submenu">
<a href="project-info.html" title="Project Information">Project Information</a>
<ul class="dropdown-menu">
<li> <a href="dependency-convergence.html" title="Dependency Convergence">Dependency Convergence</a>
</li>
<li> <a href="dependency-info.html" title="Dependency Information">Dependency Information</a>
</li>
<li> <a href="dependency-management.html" title="Dependency Management">Dependency Management</a>
</li>
<li> <a href="distribution-management.html" title="Distribution Management">Distribution Management</a>
</li>
<li> <a href="index.html" title="About">About</a>
</li>
<li> <a href="licenses.html" title="Licenses">Licenses</a>
</li>
<li> <a href="mailing-lists.html" title="Mailing Lists">Mailing Lists</a>
</li>
<li> <a href="modules.html" title="Project Modules">Project Modules</a>
</li>
<li> <a href="plugin-management.html" title="Plugin Management">Plugin Management</a>
</li>
<li> <a href="plugins.html" title="Plugins">Plugins</a>
</li>
<li> <a href="scm.html" title="Source Code Management">Source Code Management</a>
</li>
<li> <a href="summary.html" title="Summary">Summary</a>
</li>
<li> <a href="team.html" title="Team">Team</a>
</li>
</ul>
</li>
<li class="dropdown-submenu">
<a href="project-reports.html" title="Project Reports">Project Reports</a>
<ul class="dropdown-menu">
<li> <a href="xref/index.html" title="Source Xref">Source Xref</a>
</li>
<li> <a href="xref-test/index.html" title="Test Source Xref">Test Source Xref</a>
</li>
<li> <a href="checkstyle-aggregate.html" title="Checkstyle">Checkstyle</a>
</li>
<li> <a href="cpd.html" title="CPD">CPD</a>
</li>
<li> <a href="pmd.html" title="PMD">PMD</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<form id="search-form" action="https://www.google.com/search" method="get" class="navbar-search pull-right" >
<input value="omid.incubator.apache.org" name="sitesearch" type="hidden"/>
<input class="search-query" name="q" id="query" type="text" />
</form>
<script type="text/javascript" src="https://cse.google.com/brand?form=search-form"></script>
<ul class="nav pull-right"><li>
<a href="https://twitter.com/apacheomid" class="twitter-follow-button" data-show-count="true" data-align="right" data-size="large" data-show-screen-name="true" data-lang="en">Follow apacheomid</a>
<script type="text/javascript">!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</li></ul>
</div>
</div>
</div>
</div>
<div class="container">
<div id="banner">
<div class="pull-left">
<a href="./" id="bannerLeft">
<img src="images/omid-logo.png" alt="Omid" width="200"/>
</a>
</div>
<div class="pull-right"> </div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li id="publishDate" class="pull-right">Last Published: 2020-11-23</li>
</ul>
</div>
<div id="bodyColumn" >
<!--
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.
-->
<h1>Coding Guide</h1>
<p>The basic principle is to always write code that is testable, easy to understand, extensible, resistant to bugs. Code is written once but read by many people so we need to focus also on the next person that will read it:</p>
<ul>
<li>Keep it simple</li>
<li>Test your code</li>
<li><a class="externalLink" href="http://programmer.97things.oreilly.com/wiki/index.php/The_Single_Responsibility_Principle">Single responsibility principle</a></li>
<li>Try to maintain components <a class="externalLink" href="http://programmer.97things.oreilly.com/wiki/index.php/Cohesion_and_Coupling_matter">loosely coupled</a></li>
<li>Do not abuse of comments:
<ul>
<li>Choose names that reveal intent for modules, packages, classes, methods, variables, constants, etc.</li>
<li>Do not use comments for excuse bad code or when appropriate naming is enough</li>
<li>Comments are good when they provide context (Explain why, not how) or explain things that happen in the real world</li>
</ul>
</li>
<li>Follow the <a class="externalLink" href="http://programmer.97things.oreilly.com/wiki/index.php/The_Boy_Scout_Rule">Boy Scout Rule</a></li>
<li>Don&#x2019;t reinvent the wheel:
<ul>
<li>Use patterns when possible</li>
<li>Use proven libraries for (e.g. Apache commons, guava, etc.)</li>
</ul>
</li>
<li>Refactor when necessary
<ul>
<li>When adding a new feature and the context is not appropriate, refactor first in a separate commit/s</li>
</ul>
</li>
<li>Use <a class="externalLink" href="http://testng.org/">TestNG</a> for testing instead of JUnit</li>
</ul>
<h1>Coding Style</h1>
<p>Omid coding style should follow general rules found in <a class="externalLink" href="https://google.github.io/styleguide/javaguide.html">Google&#x2019;s Code Style for Java</a>, with the following modifications:</p>
<ul>
<li>Lines can be up to 120 characters long</li>
<li>Block indentation should be:
<ul>
<li>4 spaces</li>
<li>Tabs not allowed</li>
</ul>
</li>
<li>Always use curly braces for code blocks, even for single-line &#x2018;ifs&#x2019; and &#x2018;elses&#x2019;</li>
<li>Do not include @author tags in any javadoc</li>
<li>Import ordering and spacing:
<ul>
<li>Try to organize imports alphabetically in blocks with this format:
<ul>
<li>A first block of imports from external libraries</li>
<li>A second block of imports from Java libraries</li>
<li>Finally a third block with <tt>static</tt> imports</li>
</ul>
</li>
<li>Example:</li>
</ul>
</li>
</ul>
<div>
<div>
<pre class="source"> import com.google.common.base.Charsets;
import com.yahoo.omid.zk.ZKUtils.ZKException;
import com.yahoo.statemachine.StateMachine.Event;
import com.yahoo.statemachine.StateMachine.Fsm;
import com.yahoo.statemachine.StateMachine.State;
import org.apache.commons.configuration.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
...
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.ArrayDeque;
...
import static com.yahoo.omid.ZKConstants.CURRENT_TSO_PATH;
import static com.yahoo.omid.zk.ZKUtils.provideZookeeperClient;
...
</pre></div></div>
<p>The complete rules (specified with <a class="externalLink" href="https://github.com/checkstyle/checkstyle">Checkstyle</a>) can be found in the <tt>misc/omid_checks.xml</tt> file. A summary of the current status of the style in the Omid project can be found in the <a href="checkstyle-aggregate">checkstyle-aggregate</a> page.</p>
</div>
</div>
<hr/>
<footer>
<div class="container">
<div class="row">
<p >Copyright &copy; 2011&#x2013;2020
<a href="http://www.apache.org">Apache Software Foundation</a>.
All rights reserved.
</p>
</div>
<p id="poweredBy" class="pull-right">
<a href="http://maven.apache.org/" title="Maven" class="builtBy">
<img class="builtBy" alt="Maven" src="http://maven.apache.org/images/logos/maven-feather.png" />
</a>
</p>
</div>
</footer>
</body>
</html>