File: codestyle.tex

package info (click to toggle)
ns2 2.35%2Bdfsg-2.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 78,780 kB
  • ctags: 27,490
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 816; awk: 525; csh: 355
file content (68 lines) | stat: -rw-r--r-- 2,259 bytes parent folder | download | duplicates (8)
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
\chapter{ns Code Styles}
\label{chap:codestyle}

We recommend the following coding guidelines for ns 

\section{Indentation style}
\label{sec:indentationstyle}

\begin{itemize}
\item We recommend using the BSD Kernel Normal Form coding style located at\\
http://cvsweb.netbsd.org/bsdweb.cgi/sharesrc/share/misc/style?rev=HEAD\&content-type=text/x-cvsweb-markup

\item Although KNF is specified for C, it also applies reasonably well to C++ and Tcl.
Most of ns already follows KNF and it is also extensively used for the BSD and
Linux kernels.

\item The high order bit is 8-space indents.
Using 8-space indents avoid confusion about what a "tab" character
represents.  A downside is it makes deeply nested looping structures
hard to fit in 80 columns.  (Some people consider this a feature. :-)
\end{itemize}


\section{Variable Naming Conventions}
\label{sec:variablenamingconventions}

\begin{itemize}
\item Instance variables of a class should all end in an underscore.
This helps distinguish instance variables from global and local
variables.

\item C++ and Tcl bound variables should have the same names
This helps identify the bound variables quickly and reduces complexity
\end{itemize}


\section{Miscellaneous}
\label{sec:miscellaneous}

\begin{itemize}
\item Avoid the use of C++ templates.
Ns is supported on multiple platforms and templates are not
very portable and are often difficult to debug.
Exception: This guideline has been relaxed for some imported code,
but the core of ns should build and run without templates.

\item For NsObjects, use the debug\_ instance variable to enable debugging functionality.
This avoids repetitive definations of debug statements and allows debugging a particular
Nsobject without recompilation.

Example:
To enable debugging in Queue object include the following statement in your tcl script.
\begin{program}
	Queue set debug_ true
\end{program}

Debugging statments can be inserted in the classes inheriting from Queue as follows:

\begin{program}
	debug("This is a debug statement %d",variable_to_debug);
\end{program}

All debugging statements are sent to stdout.


\item Error messages which cause the program to exit should be sent to stderr.
All other messages should be sent to stdout
\end{itemize}