The TreeLogic JavaScript Coding Standard

A Practical Approach

by Chris M. Balz                                                                                             2013-01-02

Forkable at: https://gist.github.com/3924208

Copyright (C)  Chris M. Balz.
   Permission is granted to copy, distribute and/or modify this document
   under the terms of the GNU Free Documentation License, Version 1.3
   or any later version published by the Free Software Foundation;
   with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
   A copy of the license is included in the section entitled "GNU
   Free Documentation License".

Table of Contents

The TreeLogic JavaScript Coding Standard

A Practical Approach

Table of Contents

Namespacing

Packages

Modules

Classes

What and Where to Use

Object Instantiation: Classes and Hashes

Constructor Format

Private Variables

Singletons

Class Properties

Avoid Parasitic Inheritance

Where to Define Classes

“Why”s Not Covered Above

Modules

Functions

Internals

Private Functions

Protected Functions

Invoking

As Data

‘var’ Declarations

Loop Counter Caching

Identifiers

Naming

Private and Protected Properties

‘that’

‘match’ vs. ‘test’

Access

Data Type Prefixing

Built-In Objects

Performance

Overview

Caching

Messaging Data Formats

Which Messaging Data Format to Use

Commenting JSON

Code Format

Purpose

Whitespace

Indenting

Curly Braces

Line Length

Line Breaks

Statement Terminators

Conditional Parentheses

Object Initializer Syntax

Testing for Equality

Documentation

Security

Overview

Various Measures

‘parseInt’

‘window.name’

Android

External Environments

Frameworks

Document Object Model

NodeJS

GNU Free Documentation License

0. PREAMBLE

1. APPLICABILITY AND DEFINITIONS

2. VERBATIM COPYING

3. COPYING IN QUANTITY

4. MODIFICATIONS

5. COMBINING DOCUMENTS

6. COLLECTIONS OF DOCUMENTS

7. AGGREGATION WITH INDEPENDENT WORKS

8. TRANSLATION

9. TERMINATION

10. FUTURE REVISIONS OF THIS LICENSE

11. RELICENSING

Namespacing

Packages

Namespace all identifiers from the global namespace with at least one three-character identifier, and prefer more characters.  This forms your JavaScript package namespace.  All characters must be lowercase, using the underbar where words meet.  

For example, com.tl.flfy would represent a for-profit business with the abbreviation ‘tl’ for the company name (although that could be the domain name too), and the project ‘flfy’ (say, for the “Fluffy” project at the company designated by “tl”).  Then underneath ‘flfy’, provide appropriate package namespacing, such as those found in a model-view-controller architecture: com.tl.flfy.ctrlr.  

Create a single directory for each package.  This allows directory browsing itself to reveal the system’s overall code structure.

Allow similarly-namespaced code to co-exist (such as code namespaced at the top-level with ‘com’) easily by never overwriting the top-level namespace (except of course with your sub-namespace).  If possible, observe that practice for the top two or three namespace levels.  These then become shared namespaces.  Never rely on properties (dot-properties) of shared namespaces, since other code may well be using them. Never use dot-properties other than other namespaces or module names on either one.  

Why: Namespace clashes are one of the worst, most avoidable hassles imaginable.  JavaScript code from different namespaces now commonly lives together on the same page, and this will become more common.  A descriptive namespace helps reduce the biggest drag on productivity, time spent reading and understanding code.  Keeping namespaces free of dot-properties allows all properties to be grouped under meaningful data types.

Modules

Name a JavaScript module this way: com.tl.flfy.ctrlr.proxy_server_module.  If sub-modules are provided, namespace them in this manner: com.tl.flfy.ctrlr.proxy_server_module.fail_over.reconnector_module. JavaScript modules must be completely contained in a function named with the fully-qualified package name with all dot characters replaced by underbars.

Why: Modules are fundamentally different kinds of objects than packages because they define a set of private variables sealed in a function closure.  But we want to be able to define a group of sub-modules, each in their own file.  So we can use modules as namespaces as well.  

Therefore, since we mix the two types of identifiers in the same namespace qualifier, we add the suffix ‘_module’ to distinguish between the two.  We avoid anonymous functions in order to have a function’s name be present for clarity when reading code and especially when reading code during the debugging process.  

Classes

What and Where to Use

The term class here means “custom data type”.  Although JavaScript natively only supports prototypes, not classes, JavaScript can easily deliver class constructors.  Most systems should use instances of classes as their primary means of organizing their code.  By contrast to classes, prototypes present a unity of instance and data type.  

This does not serve programming-in-the-large well because objects that are inherited from may be inadvertently changed, polluting inheriting objects that intended to be what the prototype object used to be before it was changed.  Even if your project does not start out as programming-in-the-large, if it is successful it is likely to become so.  In this case, if you did not use techniques appropriate to programming-in-the-large, then you have a misfortune.

In fact, prototype inheritance was conceived of as an experiment in simplification by the creators of the ancestor language of JavaScript, Self.  And it served JavaScript’s original role in serving as a quick programming-in-the-small aid to adorners of early websites.  But the authors of “Self: The Power of Simplicity” observed in 1994 that “The absence of the class-instance distinction may make it too hard to understand which objects exist solely to provide shared information for

other objects.” (p. 4)

So most systems should be object-based, and classes will usually serve this best.  It is possible to work more strictly within object-based approaches: Object-oriented systems, by comparison, use only object-based design approaches.  To refine further: Almost all systems where computational load is low in terms of performance cost as compared to file i/o should be object-based, if not object-oriented.

Object Instantiation: Classes and Hashes

For imperative code (where, for example, we are not providing an input to a declarative mechanism such as a template transform, or passing a message as part of a true network protocol over the wire, such as json), mutable values (meaning, non-immutables: JavaScript objects; not strings, booleans, numbers, functions, or undefineds) must be created either:

  1. With a formal class constructor using the ‘new’ operator
  2. As parameterized hashes (meaning, with member variables all of the same data type)
  3. As static classes (defined most conveniently by using object initializer syntax (for example, com.tl.flfy.Proxy = { . . . }; )).

Do not hide ‘new’: The ‘new’ operator should not be buried as a convenience inside class constructors that can construct themselves, since this obfuscates the action taking place at the application level: It makes instantiations look like method calls or at best some kind of weird invocation of a static class.

Constructor Format

Class constructors must always be named with a capital letter.

When creating a class that may be inherited by another class, use a utility (such as a class engine) from a JavaScript framework that will enable you to follow a pattern that avoids unwanted shared objects among instances of the inheriting class.

Private Variables

Where useful, support private instance variables, which unfortunately only works out-of-the-box in JavaScript for immutable data types, by using the closure created by the class constructor to define ‘this’ methods that return ‘var’ variables.  For mutables (objects), use object cloning to produce a brand new object for each ‘get’ request for that object, if it is fast enough for your application. In essence, this provides a read-only object for clients.

Singletons

When creating a singleton, prefer a utility (such as a class engine) from a JavaScript framework that will inherently enforce the singleton from a declarative parameter.

Class Properties

All classes should have the instance property $DATA_TYPE with a value set to the fully-qualified name of the class, so that the reader can quickly see what they are working with, esp. when debugging.  The ‘$’ indicates meta information and also floats to the top of most property lists.

Avoid Parasitic Inheritance

Keep data types true to their definition by avoiding parasitic inheritance.  Instead of parasitic inheritance, use composition (“has-a”), since it preserves the identity of the object contexts used.

Where to Define Classes

Define all classes (static and nonstatic) in modules, with only one outer class per module.  This enables directory listings themselves to describe the code structure.

Why”s Not Covered Above

For imperative code, making instances from class constructors instead of using non-parameterized hashes (especially as parameters to other JavaScript functions increases code readability) localizes error checking, improves testability, and makes all of the above more portable.  Avoiding non-parameterized hashes in imperative code keeps the distinction between class, instance, and data clear.  Using the ‘new’ operator emphasizes the allocation of memory for an instance of a new data type.  Naming classes with a capital letter serves to differentiate them from other identifiers.  Avoiding parasitic inheritance avoids confusing dynamic changes in data types and allows humans to understand classes better when they read them and then try to recall them during debugging.

Modules

Modules should be constructed according the following pattern:

com.tl.flfy.ctrlr.proxy_server_module =

(function com_tl_flfy.ctrlr.proxy_server_module() {

   'use strict';

   var fs = require('fs'),

       url = require("url");

   // Constructor (optional).

   // Public functions (optional).

   // Private functions (optional).

   . . .

})();

Define only one outermost module per file.  This enables directory browsing itself to reveal code structure.  Define only a single, if any, public class per module.  Keep module length to less than 400 lines.

Why: ‘use strict’ saves us from some of the most pernicious JavaScript pitfalls, without reducing expressiveness or power by much in comparison.  See above about namespacing.  See below about the other aspects.  Defining only one module per file enables the developer to use the directory browsing facility of their operating system to quickly understand the high-level structure of your code.  Consensus of experience generally shows that readability and understandability begins to greatly decrease when modules exceed about 300 lines of code.

Functions

Internals

All parameters should have a 'p_' prefix: ‘p_sName’.

Offer the highest-level functions at the top, working down.  This enables human readers to get the context of your code, before optionally diving into the details.

Always return the same data type from any part of a function that returns a value.

Keep function length (excepting the outermost module wrapper function) to less than 60 lines, for readability and modularity.

Private Functions

Leverage private (inner) functions for increased readability and modularity.  It makes rewriting functions much easier.  See the section on invoking functions for how to invoke these functions.

Protected Functions

Offer protected (in the Java sense of package-protected) functions by prefixing their identifiers with an underbar character: ‘this._my_protected’.

Invoking

Code that invokes a function should either use a ‘new’ operator, a ‘this’ prefix, or where there is no local ‘var’ such as ‘that’ representing ‘this’, a ‘.call’ or ‘.apply’ invocation with the ‘this’ identifier.  

Where a private function is called from an instance context, ‘.call’ or ‘.apply’ should be used with the ‘this’ identifier if that function is over twenty lines in length.  This helps to improve code readability.  Always prefer ‘call’ over ‘apply’ where possible, as it requires the listing of the parameters individually, providing a greater opportunity for naming.

Why: The ‘new’ operator emphasizes the fact that we are allocating a significant amount of memory in the operation.  Controlling function ‘this’ scope keeps one from being stuck wondering what instance the current closure belongs to when debugging minified, concatenated production code.  Tools such as source-maps can avoid this, but in practicality are not always available.

As Data

Avoid callbacks across class and class instance boundaries where possible, in favor of a true event system.  Callbacks carry with them their lexical scope, which if transported across significant, different formations of code, can make code not only hard to read but practically untestable, as encapsulation is broken by the transferred scope.  

‘var’ Declarations

  1. Define only a single ‘var’ statement per function, and keep it at the very top of the function.  This way, the reader can easily see what variables your function works with.  If the list becomes hard to read, it is a sign you need to break out some of your existing code a new (or, occasionally, just a different) function.
  2. Avoid excess code by using the comma operator to make a ‘var’ list, rather than repeating ‘var’.  ‘use strict’ mode will make sure you don’t accidentally declare a global variable by missing a comma: It will throw a hard error that you’ll see.
  3. Define each assignment on its own line, and unassigned variables at the bottom of the ‘var’ statement on a single line.
  4. Within each section (assigned variables, and unassigned ones), offer the highest-level variables first.  This enables human readers to get the context of your code, before optionally diving into the details.  

Loop Counter Caching

Due to the apparent fact that JavaScript engines translate ‘for’ loops to iterators (traversed by ‘next’), there is no benefit to caching the length limit of your loops: http://jsperf.com/loops-caching-length-of-array-that-is-out-of-function-s/4  And there is the disadvantage that if your JavaScript ‘Array’ instance length changes while the loop is running, you will either hit an undefined value or not reach the end of your ‘Array’.

Identifiers

Naming

Before naming something, put yourself in the shoes of someone new to the code who must fix a critical bug quickly.  

Adhere to terseness, but always err on the side of verbosity when balancing verbosity and terseness.

For non-package, non-module identifiers, use all-capital letters for constants (called “final” in Java), with underbars where camelCase would be used.  

For non-package, non-module identifiers, use use camelCase for non-constants.

Avoid redefining, except to cache locally, identifiers that have an identity with the global object in important JavaScript programming environments.  Examples of such environments include the browser object model (bom).  One of these identifiers is ‘self’, and another one that is not used in the bom but is popular in other JavaScript implementations is ‘global’.  See http://dev.w3.org/html5/spec/browsers.html#the-window-object. 

Private and Protected Properties

See the section on private properties in constructors for information on non-function private properties, and see the section on functions for information on private functions and on protected functions.  

Where it is not desirable to maintain truly private objects by cloning them upon ‘get’ method invocations, simply name them with a double-underbar prefix: ‘this.__my_precious’.

As with functions that are methods, name package-protected (in the Java sense) non-method properties with a single underbar prefix: ‘this._my_protected’.

‘that’

Use var that = this; to conveniently provide access to the ‘this’ scope from private functions.  See the notes elsewhere on use of ‘self’.

‘match’ vs. ‘test’

Use the RegExp object ‘test’ method when you simply want to check if a regular expression matches some text or not.  If you want more information than that, then use the String object ‘match’ method.

Access

Always use '.' notation instead of '[' notation where a dynamic key is not required.

Be explicit if your code is accessing the global scope:

  1. For initial access in a JavaScript scope to non-GUI globals, use ‘self’’ if available.  Unfortunately, some JavaScript implementations do not provide ‘self’; in that case, use ‘global’.  
  2. For initial access in a JavaScript scope to non-GUI globals, use ‘window’’ if available.  
  3. There is an insignificant performance drawback to using ‘self’ and ‘window’ prefixes: http://jsperf.com/global-lookup-with-self-window-and-neither  While the difference comparitively is large, the slowest case is around two million lookups per second.  So in absolute terms, for anything JavaScript will be used for, the difference is negligible.

This not only aids in readability but opens the code up for optimization to compilers that would prefer to avoid excess scope-chain lookups.

Data Type Prefixing

With the exception of integer loop counters, all identifiers should have data type prefixes.  Use:

  1. 's' for string ('sName')
  2. ‘b’ for boolean (‘bGo’)
  3. 'i' for integer ('iNumber')
  1. Except for highly idiomatic uses such as a loop counter, where no data type prefix is necessary.
  1. 'fl' for floating-point ('flSomeDecimalNumber')
  2. 'o' for an 'object' that is not used as a hash
  3. 'h' for an object that is used as a hash
  4. ‘r’ for a regular expression object
  5. ‘w’ for a window object
  6. ‘d’ for a document object
  7. ‘e’ for an HTMLElement
  8. 'fn' for a function that is passed as an argument (such as a callback function ('fnHandleRequest'), but not, for example, a class constructor, a method, or a module name).

While JavaScript was created with an intentionally low barrier to entry, and therefore is loosely typed, code that respects basic data types is much faster to work with because the developer’s intent can be discerned almost instantly by others who read the code.  Using type prefixes enables us to  read and modify code faster.

Built-In Objects

Unless you are writing for an absolutely performance-critical environment where you are sure no other JavaScript will run, do not modify built-in objects or their prototypes.  This will enable your code to co-exist with minimal effort with other code, and will avoid providing unwelcome surprises for other developers.

Performance

Overview

Performance in JavaScript is largely driven by the underlying techniques used by the JavaScript interpreter/just-in-time-compiler engines.  Due to the high-level nature of JavaScript, its performance characteristics can be counterintuitive.  

For example, tests show that loops written with syntax accessing the ‘.length’ of an array that lives outside of function scope on every iteration are actually, on some browsers, slightly faster than those that cache the array length.  This must be due to the underlying optimizations in the JavaScript interpreter, which are likely done according to what kind of code commonly written by the JavaScript user base most needs optimization: http://jsperf.com/loops-caching-length-of-array-that-is-out-of-function-s/7

However, happily, short loops do optimize as expected: http://jsperf.com/loop-length-caching/2  But the operations per second are so high, that it’s hard to imagine very many practical use-cases for this kind of optimization.

And in the same vein, notably, heap access no longer slows down appreciably with respect to the growth in heap size, as shown by this test: http://jsperf.com/js-performance-under-memory-load/5

The Rule of Thumb is: Write JavaScript code that is succinct and readable first and foremost, above performance considerations.  Because JavaScript today is so fast, outside of rare circumstances, many optimizations don’t make much (if any) difference.

The Golden Rule is: Before you commit code that is harder to read because of its optimizations, challenge your assumptions about JavaScript performance at http://jsperf.com.

Caching

Make use of caching where possible, noting the above section on the futility of caching the ‘.length’ property of JavaScript arrays.  Here is an example of the utility (though not of great magnitude) of caching regular expression objects: http://jsperf.com/caching-regex-objects .

Messaging Data Formats

Which Messaging Data Format to Use

Use XML where the data is complex and the payload is under 100 kilobytes.  Use JSON in all other cases.

Commenting JSON

Until JSON supports comments, comment JSON by inserting keys named “json-comment”.

Code Format

Purpose

Code format should make the code look consistent.  It should not try to make it look correct.  “Correct” does not exist in matters of style.  Consistent code is much faster to work with.

Whitespace

Because code indented with single spaces looks the same everywhere, while code formatted with tabs does not, use spaces only.  Although this may be the fault of the tools, it is a practical limitation.

Indenting

Indent four spaces for every level of code indenting.

Curly Braces

Preserve valuable vertical screen real estate by keeping a curly brace on the same line as the code that originates it.

Line Length

Format the line length to be as long as commonly available monitors on portable notebook computers will allow.

Line Breaks

Ensure that there are three line breaks (two blank lines) before:

  1. A function declaration that is not a wrapper function for a module.  (This allows the single line breaks in a function to clearly appear within their function).

Ensure that there are two line breaks (one blank line) before:

  1. A control statement such as ‘return’, ‘break’, or ‘continue’.

Ensure that there are two line breaks (one blank line) after:

  1. The closing curly brace of function declaration that is not a wrapper function for a module.

Provide a single line break after:

  1. A statement terminator (‘;’).
  2. Code that creates a block (such as an opening curly brace).

Optionally break lines after:

  1. A conditional operator (including ‘?’ and ‘:’)
    A ‘case:’ statement
  2. A mathematical operator

Do not use line-breaks in place of semi-colons (see ‘Statement Terminators’, below).

Statement Terminators

Use only semi-colons for this, not line breaks.  Follow such semi-colons with line-breaks.  The only reason to do so is to avoid ambiguity to human code readers, but such ambiguity can be challenging.  

For example, no semi-colon is automatically inserted in place of a line break after a function assignment that has as its next non-whitespace, non-comment program text a pair of function-invocation parentheses, as shown in this example.

Conditional Parentheses

Use a single space to bracket the contents of conditional parentheses.  This reduces clutter around the central subject, the condition.  The opening curly brace can follow an ‘if’ directly, as the distinction between the letter (in this case, ‘f’) and the opening parenthesis needs no extra emphasis.  That lack of space in turn serves to emphasize the central subject.  Also, keep the closing smooth parenthesis and the following curly brace from visually colliding by using a space there.  Examples:

  1. if( foo === bar ) { . . . 
  2. while( foo-- ) { . . .

Object Initializer Syntax

Keep a balance between compactness and readability.  Examples (json would only add double-quotes around all the keys):

  1. { foo: bar, bat: baz }
  2. [ ‘a’, ‘b’, ‘c’ ]

Testing for Equality

For readability and efficiency, test for identity instead of equality wherever convenient.  This means using the operator ‘===’ instead of the operator ‘==’.  

Documentation

For very reusable API, follow the Javadoc standards, mapping them over to JavaScript data types as needed.  Document the data type of parameterized hashes: @param hFoo<string>.  In the class file header, document all class (@class) and instance (@object) properties.

Security

Overview

Never keep secrets on the client.  If you follow this golden rule, you’ve done all you can to make your client-side JavaScript secure.  As for making client-side JavaScript harder to crack, please see the section below called “Various Measures”.  

Regarding server-side JavaScript, the same “harder to crack” measures apply.  Additionally, on the server (regardless of language) be sure to filter out code that would allow cross-site scripting (XSS) attacks.

Various Measures

‘parseInt’

Specify the base you intend to use (usually 10), to avoid making it easy for an attacker to convert your base to 8 by prepending a “0” to the first argument to parseInt.

‘window.name’

Avoid storing any private values in this property, because it is preserved from one page to another and from one domain to another.

Android

JavaScript values set from Android native Java will persist across page loads.  So only non-sensitive info should be set there, or it should be cleaned up on page unload.

External Environments

JavaScript is commonly used for working with the document object model (dom) on the Web browser, and for server-side handling of the Web front tier, such as with NodeJS.  Therefore, a JavaScript standard should include best practices where there is substantial gain in these areas.

Frameworks

If you are doing programming-in-the-large, avoid JavaScript frameworks that will make this difficult, such as jQueryUI.  Keep in mind that most of the vast audience of JavaScript frameworks is doing programming-in-the-small.  Reflect first upon what you are doing.

Document Object Model

Use cascading style sheet class names (css) instead of directly setting cascading style sheet properties except where unavoidable (such as in some animation code).  This maintains a separation between presentation and logic.  

Do not develop code to uniquefy document object model element ‘id’ attribute values.  Use css classnames or html5 attributes instead.  ‘id’ attribute values should already be unique enough to support their use anywhere.

Outside of dedicated templating mechanisms and template input written in JavaScript, avoid writing html in JavaScript wherever possible.  Use a template mechanism such as handlebars to keep html out of your JavaScript.  

Keep your custom code separate from the ‘this’ scope of dom objects.  This will help keep your code encapsulated and when debugging, recognizable.

NodeJS

For performance reasons, NodeJS must use callbacks extensively.  This is a JavaScript web server pattern, not a JavaScript web application pattern.  Steer out of this in your code where possible.  

Recall that NodeJS files add to the whole context.  Therefore, avoid polluting the global namespace by keeping your code entirely within modules.


GNU Free Documentation License

Version 1.3, 3 November 2008

Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc. <http://fsf.org/>

Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

0. PREAMBLE

The purpose of this License is to make a manual, textbook, or other functional and useful document "free" in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others.

This License is a kind of "copyleft", which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software.

We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference.

1. APPLICABILITY AND DEFINITIONS

This License applies to any manual or other work, in any medium, that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. Such a notice grants a world-wide, royalty-free license, unlimited in duration, to use that work under the conditions stated herein. The "Document", below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as "you". You accept the license if you copy, modify or distribute the work in a way requiring permission under copyright law.

A "Modified Version" of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language.

A "Secondary Section" is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document's overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (Thus, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them.

The "Invariant Sections" are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License. If a section does not fit the above definition of Secondary then it is not allowed to be designated as Invariant. The Document may contain zero Invariant Sections. If the Document does not identify any Invariant Sections then there are none.

The "Cover Texts" are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License. A Front-Cover Text may be at most 5 words, and a Back-Cover Text may be at most 25 words.

A "Transparent" copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, that is suitable for revising the document straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup, or absence of markup, has been arranged to thwart or discourage subsequent modification by readers is not Transparent. An image format is not Transparent if used for any substantial amount of text. A copy that is not "Transparent" is called "Opaque".

Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML, PostScript or PDF designed for human modification. Examples of transparent image formats include PNG, XCF and JPG. Opaque formats include proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML, PostScript or PDF produced by some word processors for output purposes only.

The "Title Page" means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, "Title Page" means the text near the most prominent appearance of the work's title, preceding the beginning of the body of the text.

The "publisher" means any person or entity that distributes copies of the Document to the public.

A section "Entitled XYZ" means a named subunit of the Document whose title either is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in another language. (Here XYZ stands for a specific section name mentioned below, such as "Acknowledgements", "Dedications", "Endorsements", or "History".) To "Preserve the Title" of such a section when you modify the Document means that it remains a section "Entitled XYZ" according to this definition.

The Document may include Warranty Disclaimers next to the notice which states that this License applies to the Document. These Warranty Disclaimers are considered to be included by reference in this License, but only as regards disclaiming warranties: any other implication that these Warranty Disclaimers may have is void and has no effect on the meaning of this License.

2. VERBATIM COPYING

You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3.

You may also lend copies, under the same conditions stated above, and you may publicly display copies.

3. COPYING IN QUANTITY

If you publish printed copies (or copies in media that commonly have printed covers) of the Document, numbering more than 100, and the Document's license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects.

If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages.

If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a computer-network location from which the general network-using public has access to download using public-standard network protocols a complete Transparent copy of the Document, free of added material. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public.

It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document.

4. MODIFICATIONS

You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version:

  1. A. Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission.
  2. B. List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at least five of the principal authors of the Document (all of its principal authors, if it has fewer than five), unless they release you from this requirement.
  3. C. State on the Title page the name of the publisher of the Modified Version, as the publisher.
  4. D. Preserve all the copyright notices of the Document.
  5. E. Add an appropriate copyright notice for your modifications adjacent to the other copyright notices.
  6. F. Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below.
  7. G. Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document's license notice.
  8. H. Include an unaltered copy of this License.
  9. I. Preserve the section Entitled "History", Preserve its Title, and add to it an item stating at least the title, year, new authors, and publisher of the Modified Version as given on the Title Page. If there is no section Entitled "History" in the Document, create one stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence.
  10. J. Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the "History" section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission.
  11. K. For any section Entitled "Acknowledgements" or "Dedications", Preserve the Title of the section, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein.
  12. L. Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles.
  13. M. Delete any section Entitled "Endorsements". Such a section may not be included in the Modified Version.
  14. N. Do not retitle any existing section to be Entitled "Endorsements" or to conflict in title with any Invariant Section.
  15. O. Preserve any Warranty Disclaimers.

If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version's license notice. These titles must be distinct from any other section titles.

You may add a section Entitled "Endorsements", provided it contains nothing but endorsements of your Modified Version by various parties—for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard.

You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one.

The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version.

5. COMBINING DOCUMENTS

You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice, and that you preserve all their Warranty Disclaimers.

The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work.

In the combination, you must combine any sections Entitled "History" in the various original documents, forming one section Entitled "History"; likewise combine any sections Entitled "Acknowledgements", and any sections Entitled "Dedications". You must delete all sections Entitled "Endorsements".

6. COLLECTIONS OF DOCUMENTS

You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects.

You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document.

7. AGGREGATION WITH INDEPENDENT WORKS

A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, is called an "aggregate" if the copyright resulting from the compilation is not used to limit the legal rights of the compilation's users beyond what the individual works permit. When the Document is included in an aggregate, this License does not apply to the other works in the aggregate which are not themselves derivative works of the Document.

If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one half of the entire aggregate, the Document's Cover Texts may be placed on covers that bracket the Document within the aggregate, or the electronic equivalent of covers if the Document is in electronic form. Otherwise they must appear on printed covers that bracket the whole aggregate.

8. TRANSLATION

Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License, and all the license notices in the Document, and any Warranty Disclaimers, provided that you also include the original English version of this License and the original versions of those notices and disclaimers. In case of a disagreement between the translation and the original version of this License or a notice or disclaimer, the original version will prevail.

If a section in the Document is Entitled "Acknowledgements", "Dedications", or "History", the requirement (section 4) to Preserve its Title (section 1) will typically require changing the actual title.

9. TERMINATION

You may not copy, modify, sublicense, or distribute the Document except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, or distribute it is void, and will automatically terminate your rights under this License.

However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.

Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.

Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, receipt of a copy of some or all of the same material does not give you any rights to use it.

10. FUTURE REVISIONS OF THIS LICENSE

The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See http://www.gnu.org/copyleft/.

Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License "or any later version" applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation. If the Document specifies that a proxy can decide which future versions of this License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Document.

11. RELICENSING

"Massive Multiauthor Collaboration Site" (or "MMC Site") means any World Wide Web server that publishes copyrightable works and also provides prominent facilities for anybody to edit those works. A public wiki that anybody can edit is an example of such a server. A "Massive Multiauthor Collaboration" (or "MMC") contained in the site means any set of copyrightable works thus published on the MMC site.

"CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0 license published by Creative Commons Corporation, a not-for-profit corporation with a principal place of business in San Francisco, California, as well as future copyleft versions of that license published by that same organization.

"Incorporate" means to publish or republish a Document, in whole or in part, as part of another Document.

An MMC is "eligible for relicensing" if it is licensed under this License, and if all works that were first published under this License somewhere other than this MMC, and subsequently incorporated in whole or in part into the MMC, (1) had no cover texts or invariant sections, and (2) were thus incorporated prior to November 1, 2008.

The operator of an MMC Site may republish an MMC contained in the site under CC-BY-SA on the same site at any time before August 1, 2009, provided the MMC is eligible for relicensing.