12.07.2015 Views

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 28<strong>ns</strong> Code StylesWe recommend the following coding guidelines for <strong>ns</strong>28.1 Indent<strong>at</strong>ion style• We recommend using the BSD Kernel Normal Form coding style loc<strong>at</strong>ed <strong>at</strong>http://cvsweb.netbsd.org/bsdweb.cgi/sharesrc/share/misc/style?rev=HEAD&content-type=text/x-cvsweb-markup• Although KNF is specified for C, it also applies reasonably well to C++ <strong>and</strong> Tcl. Most of <strong>ns</strong> already follows KNF <strong>and</strong>it is also exte<strong>ns</strong>ively used for the BSD <strong>and</strong> Linux kernels.• <strong>The</strong> high order bit is 8-space indents. Using 8-space indents avoid confusion about wh<strong>at</strong> a "tab" character represents. Adow<strong>ns</strong>ide is it makes deeply nested looping structures hard to fit in 80 colum<strong>ns</strong>. (Some people co<strong>ns</strong>ider this a fe<strong>at</strong>ure.:-)28.2 Variable Naming Conventio<strong>ns</strong>• I<strong>ns</strong>tance variables of a class should all end in an underscore. This helps distinguish i<strong>ns</strong>tance variables from global <strong>and</strong>local variables.• C++ <strong>and</strong> Tcl bound variables should have the same names This helps identify the bound variables quickly <strong>and</strong> reducescomplexity28.3 Miscellaneous• Avoid the use of C++ templ<strong>at</strong>es. Ns is supported on multiple pl<strong>at</strong>forms <strong>and</strong> templ<strong>at</strong>es are not very portable <strong>and</strong> areoften difficult to debug. Exception: This guideline has been relaxed for some imported code, but the core of <strong>ns</strong> shouldbuild <strong>and</strong> run without templ<strong>at</strong>es.• For NsObjects, use the debug_ i<strong>ns</strong>tance variable to enable debugging functionality. This avoids repetitive defin<strong>at</strong>io<strong>ns</strong>of debug st<strong>at</strong>ements <strong>and</strong> allows debugging a particular Nsobject without recompil<strong>at</strong>ion.247

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!