UNPKG

@ciao-lang/ts-ciao-interface

Version:

Simple Ciao interface for node.

10 lines 5.4 kB
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><meta name="theme-color" content="#273f79"/><link rel="stylesheet" href="lpdoc.css" type="text/css"/><script type="text/javascript" src="lpdoc.js"></script><title>Coding Style &mdash; </title></head><body><div class="lpdoc-page fixleftbar"><a href="#" id="sidebar-toggle-button" class="lpdoc-navbutton"><span id="sidebar-button-arrow">&#9776;</span></a><div id="sidebar" class="lpdoc-sidebar"><div style="height: 40px; margin-left: auto; margin-right: auto"><img src="ciao-grimoire-128h_autofig.png" width=auto height=100%></div><div class="lpdoc-nav"><span class="lpdoc-on-right"><a class="lpdoc-navbutton" href="CiaoDevel.html">&#x2191;</a><a class="lpdoc-navbutton" href="ReportingBugs.html">&#x2190;</a><a class="lpdoc-navbutton" href="GitWorkflow.html">&#x2192;</a><a class="lpdoc-navbutton" href="CiaoDevelsearch.html">&#x1F50D;</a></span><span><a href="CiaoDevelfulltoc.html">TOC</a></span></div><hr></hr><ul class="lpdoc-itemize-sectpath"><li><a href="CiaoDevel.html">CiaoDevel Reference Manual</a> &raquo;<br/> </li><li><a href=""><strong>Coding Style</strong></a></li></ul><hr></hr><em>ON THIS PAGE</em><ul><li><a href="#Coding style for Ciao code">Coding style for Ciao code</a></li><li><a href="#Coding style for C Code">Coding style for C Code</a></li><li><a href="#Some helper Emacs tools">Some helper Emacs tools</a></li></ul></div><div class="lpdoc-main"><div id=""><h1>Coding Style</h1><a class="lpdoc-idx-anchor" href="CiaoDevelsearch.html#CodingStyle"></a> <strong>Author(s):</strong> <a class="lpdoc-idx-anchor" id="The Ciao Development Team" href="CiaoDevelsearch.html#The Ciao Development Team">The Ciao Development Team</a>.<p> <div id="Coding style for Ciao code"><h2>Coding style for Ciao code</h2> <ul> <li>Keep line width less than 80 characters (if possible). <li>Do not leave lines ending with spaces or tabs (trailing whitespace). <li>Any file should be ended by a new line. <li>Use spaces instead of tabulations. <li>Avoid predicates with the same name but different arity. <li>Use descriptive module names, specially in libraries (to avoid clash with user-defined modules, since module names are global). <li>Similarly use descriptive names for multifile predicates (they are global). <li>When possible enumerate imported predicates explicitly. <li>When contributing bug reports, they are typically stored at <tt>&lt;bundle&gt;/bugs/Pending</tt>. When fixed, bug entries are moved to <tt>&lt;bundle&gt;/bugs/Fixed</tt>. Place at <tt>&lt;bundle&gt;/bugs/Unclassified</tt> potential bugs whose status may be unknown. <li>Make sure that you make proper usage of clause indexing (in Ciao it is done by default on the first argument of predicates) and cuts (<tt>!/0</tt>), for the expected instantiation modes for each predicate. Doing unnecessary backtracking and leaving choice points can introduce nasty performance bugs that can be hard to debug. Assertions can help in this task. <li>Understand the algorithmic cost of operations (e.g., assert/consult is typically linear in the size of terms, var-nonvar unification is typically constant time, etc.) </ul> </div><div id="Coding style for C Code"><h2>Coding style for C Code</h2> <ul> <li>In general, avoid <tt>inline</tt> functions (see <a href="https://www.kernel.org/doc/Documentation/CodingStyle">Linux Kernel Coding Style</a>) -- unless you can collect evidence that they produce optimal code (size and speed) with the state of the art C compilers. <li>Use macros (even big ones) when you need to inline code. A macro is much better than duplicated code. <li>Do not use comma at the statement level (e.g. <tt>int a, b;</tt> or <tt>foo(), bar();</tt>) since that confuses the CPP macro expansion (when that code is wrapped inside <tt>{}</tt> and passed as argument). <li><tt>goto</tt> is not harmful for low level code (specially for automatically generated code). </ul> </div><div id="Some helper Emacs tools"><h2>Some helper Emacs tools</h2> To highlight trailing whitespaces you can either:<p><ul> <li>use the <tt>highlight-chars</tt> emacs package (available at MELPA) and add the following lines in your <tt>.emacs</tt>: </ul> <pre class="lpdoc-codeblock"><span class="comment-delimiter">;; </span><span class="comment">--------------------------------------------------------------------------- </span><span class="comment-delimiter">;; </span><span class="comment">highlight tabs and trailing whitespace </span>(<span class="keyword">require</span> '<span class="constant">highlight-chars</span>) (add-hook 'font-lock-mode-hook 'hc-highlight-tabs) (add-hook 'font-lock-mode-hook 'hc-highlight-trailing-whitespace)</pre> <ul> <li>toggle the <tt>Show Trailing Whitespace</tt> option on, which can be found at <tt>Options &gt; Customize Emacs &gt; Browse Customization Groups</tt> below: </ul> <pre class="lpdoc-codeblock">[-]-\ Group Emacs [-]-\ Group Editing | [-]-\ Group Editing Basics | `--- Option Show Trailing Whitespace</pre>It is not adviced to remove trailing whitespace automatically since this can mess up the diff of your changes (and potentially lead to merge conflicts later on).</div><br/></div><div class="lpdoc-footer">Generated with LPdoc using Ciao</div></div><div class="lpdoc-clearer"></div></div></body></html>