1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.77 [en] (X11; U; Linux 2.4.10 i686) [Netscape]">
<meta name="Author" content="Ronan Collobert">
<title>Torch Coding Standards</title>
</head>
<body text="#000000" bgcolor="#999999" link="#0000EE" vlink="#551A8B" alink="#FF0000">
<center><font size=+4><b><i>Torch</i></b> coding standards</font>
<br><font size=+4>===================</font></center>
<p><font size=+3>1. The <tt>kernel</tt></font>
<blockquote>The library is divided in several subdirectories. The main
part of <b><i>Torch</i></b> is in "<tt>kernel</tt>". You should never change
anything in this directory. If you find a bug, just send me an email. If
you want to do your own algorithm, just create a new package (That is a
new directory). <i>I'll add in the kernel only well-known algorithms</i>.</blockquote>
<font size=+3>2. You said C++ ?</font>
<blockquote>I hate C++. Too complicated. At the beginning I was thinking
about writing the library in Objective C... unfortunately, only few people
are using this language. Here are the C++ keywords that you're allowed
to use in <b><i>Torch</i></b>:
<ul>
<li>
<tt>class</tt></li>
<li>
<tt>virtual</tt></li>
<li>
<tt>public</tt></li>
<li>
all C keywords</li>
<br>
<li>
<tt>const</tt>, but only if compilers give a warning when you don't use
it.</li>
<br>
<li>
<tt>new</tt> and <tt>delete</tt> for objects. If it's for table of standard
types like <tt>int</tt>, <tt>float</tt>... use <tt>xalloc</tt>() and <tt>free</tt>().</li>
</ul>
<ul>
<li>
<img SRC="images/new.jpg" ALT="[new!]" NOSAVE height=11 width=28><tt> namespace</tt>
for "<tt>namespace Torch {}</tt>" and "<tt>using namespace Torch;</tt>"
Indeed, the library is now embedded in the namespace "Torch".</li>
</ul>
In <b><i>Torch</i></b>, every class members are <tt>public</tt>.
<p>I <b><i><u>don't want</u></i></b> to see:
<ul>
<li>
<tt>string</tt>... no, no and no, please use <tt>char*</tt>.</li>
<li>
<tt>cin</tt> <tt>cout</tt>, and C++ streams: no, use <tt>message(), warning(),
error(), print() </tt>or even <tt>printf()</tt>. And use <tt>FILE*</tt>.</li>
<li>
Templates.</li>
<li>
STL library.</li>
<li>
Multiple inheritance.</li>
<li>
Operator overload.</li>
<li>
References: use pointers.</li>
</ul>
Okay ? In <b><i>Torch</i></b> we use C++ only for the object concept. The
rest of your code should be almost like C.</blockquote>
<font size=+3>3. Basic <b><i>Torch</i></b> Features...</font>
<blockquote><b>Text inputs/output</b>
<blockquote>Use <tt>message(), warning(), error(), print() </tt>instead
of <tt>printf().</tt>
<br>You should get inputs only from your main code, and you shoud use the
<tt>CmdLine</tt> class for that purpose.</blockquote>
<b>Types</b>
<blockquote>Use <tt>real</tt> instead of <tt>double</tt> or <tt>float</tt>
(except in very specific cases). The <tt>real</tt> type is defined to <tt>double</tt>
if the flag <tt>USEDOUBLE</tt> is defined by the user when he compiles
the library. Otherwise it's defined to <tt>float</tt>.
<p>Use <tt>sreal</tt> if you want to use the sparse format.
<p>You can use the <tt>List</tt> structure when you have simple chained-lists.</blockquote>
<b>Random functions</b>
<blockquote>Please, don't use the <tt>srandom()</tt> and <tt>random()</tt>
functions. Use instead functions provided by the library. (Have a look
to the <a href="manual/index.html">reference manual</a>)</blockquote>
<b>Inputs/ouputs on disk</b>
<blockquote>There are several functions which handle BigEndian and LittleEndian
formats for input and output on disk. Check the <a href="manual/index.html">reference
manual</a>.</blockquote>
</blockquote>
<font size=+3>4. Naming conventions</font>
<blockquote>Easy:</blockquote>
<blockquote>
<ul>
<li>
<tt>MyClassName</tt></li>
<li>
<tt>myMethodName()</tt></li>
<li>
<tt>my_variable_name</tt></li>
<li>
<tt>myGlobalFunction()</tt></li>
<li>
<tt>MY_CONSTANT</tt> (for <tt>#define</tt> constants or other)</li>
</ul>
<img SRC="images/new.jpg" ALT="[new!]" NOSAVE height=11 width=28> Note
that each class should be divided into two files: one include file (.h,
containing the class layout) and one source file (.cc, containing the implementation).
In the include file, you should provide some documentation, with the <a href="http://docpp.sourceforge.net/">DOC++</a>
format for comments. Moreover, for the class <tt>FooFoo</tt> the include
file should begin with
<blockquote>
<blockquote>
<blockquote><tt>#ifndef FOO_FOO_INC</tt>
<br><tt>#define FOO_FOO_INC</tt><tt></tt>
<p><tt>namespace Torch {</tt></blockquote>
</blockquote>
</blockquote>
and should end with
<blockquote>
<blockquote>
<blockquote><tt>}</tt>
<br><tt>#endif</tt>.</blockquote>
</blockquote>
</blockquote>
(The same applies for the .cc file, without, of course, the #ifndef/#define/#endif
lines))
<br> </blockquote>
</body>
</html>
|