Thisguideline is a part of the English Wikipedia'sManual of Style. Editors should generally follow it, thoughexceptions may apply.Substantive edits to this page should reflectconsensus. When in doubt, discuss first onthis guideline's talk page. |
| Manual of Style | ||||
|---|---|---|---|---|
By topic area
| ||||
This manual contains some suggestions which aim to contribute towards writing clear, pleasant looking, and hopefully interestingcomputer science articles. This guide is a complement to the generalManual of Style.
Probably the hardest part of writing any technical article is the difficulty of addressing the level of technical knowledge on the part of the reader. A general approach is to start simple, and then move toward more formal and technical statements as the article proceeds. The following structure is merely recommended; editorial discretion and consensus might find an alternative structure more appropriate for some subjects.
The article should start with anlead section of length appropriate to the article content, which describes the subject in general terms and properly summarizes the article. This opening material should give the casual reader a quick understanding of the concept. Name the field(s) of computer science this concept belongs to and describe the context in which the term is used.Write thearticle title and any alternative names in bold. Include the historical motivation, provide some names and dates, etc. Here is an example:
It is a good idea to begin the main part of the article with an informal introduction, commonly titled "Background" though "Overview" has also been used, that gives the non-technical reader a basic understanding of the fundamental concepts of the topic being presented. If the concept in question is somewhat theoretical, it is helpful to describe itspurpose orapplied use(s) toward the top of the article, either concisely in the lead section or in a post-lead introductory section. It is also useful to have some representativeexamples, which could serve both to expand on the concept in question and to provide some context as towhy one might want to use that concept.
A picture is a great way of bringing a point home, and often it could even precede the technical discussion of a concept.WP:How to create graphs for Wikipedia articles has some hints on how to create graphs and other pictures, and how to include them in articles.
If not included in the introductory material, a section about thehistory of the concept is often useful and can provide additional insight. This often forms its own "History" section.
Computer science is a broad field which encompasses a number of different kinds of ideas. The structure of the main part of an article will vary with the type of article. Here are some general guidelines for structuring a few different classes of computer science articles. Where possible, these guidelines include one or two examples of a "good" article,i.e. an article demonstrates the style we're aiming for in that particular class of article. Always keep in mind that these areguidelines, not hard-and-fast rules: some articles will need to deviate from this structure; some articles will be hard to classify; some won't fit into these classifications at all. Use common sense in applying these guidelines.
An article on an algorithm should generally consist of:
A good example isbinary search algorithm, afeatured article.
An article on a data structure should consist of:
An article describing a classic problem should generally consist of:
An example is thedining philosophers problem.
The structure of an article describing asoftware design pattern or otherdesign pattern in computer science (includingcreational patterns,structural patterns,behavioral patterns, andconcurrency patterns) should draw on industry best-practice models provided by reliable sources on the subject. Some of these include:
An article describing a field of study within computer science should include:
An article describing some kind of formalism should contain:
A good example islambda calculus.
An article describing a programming construct should generally include:
Examples includecontinuation,closure (computer programming), andexception handling.
An article describing a programming language should generally include at least:
A good example is theRust (programming language) article.
An article describing theorems or conjectures should generally contain at least:
As many computer science theorems and conjectures are often stated informally in popular literature it may also be beneficial to provide some discussion of common misconceptions or misinterpretations of the theorem or conjecture.
The names of such thingsare not capitalized except where they contain a proper name (e.g. a surname).
Good examples includehalting problem andChurch–Turing thesis.
An article describing a class of tools should generally contain:
Examples includecompiler,text editor, andautomated theorem proving.
SeeWP:Manual of Style/Layout § Standard appendices and footers for use of "See also", "Notes", "References", "External links" sections, and navigation templates.
Samples of actual sources get included in articles for a variety of reasons, although the most typical reasons are to demonstrate the "look" of a particular language, to provide examples of language-specific constructs or features, and to provide examples of algorithms not easily expressed in pseudocode. While there's nothing inherently wrong with including sample code, excessive amounts of it can detract from the content of the article itself; avoid writing sample code unless it contributes significantly to a fundamental understanding of the encyclopedic content.
Wikipedia is not a source code repository. Code that is not relevant to encyclopedic content should be moved out of Wikipedia. WikiBooks is the appropriate Wikimedia project for existing GFDL-compatible code; in particularWikibooks:Algorithm Implementation. The externalLiteratePrograms andRosetta Code wikis are appropriate places to putnew sample implementations, along with descriptions of how those implementations work.Important note: existing implementations on Wikipediacannot be transferred to the LiteratePrograms wiki because Wikipedia content is licensed under theGFDL and/orCC-BY-SA, while LiteratePrograms uses the more liberalMIT/X11 license; relicensing existing code from GFDL/CC-BY-SA to MIT/X11 would require the permission of all copyright holders
Some general guidelines on code samples:
<code>...</code> or<syntaxhighlight lang="x" inline><syntaxhighlight lang="x"> or<pre>...</pre> tagsint main(void) { printf("hello, world\n"); return 0;}<pre>...</pre>, with a specificlang attribute specifying the language name (the valuewikitext is used for MediaWiki markup). SeeExtension:SyntaxHighlight for supported languages. The following is syntax-highlighted Java code, for example, using<syntaxhighlight lang="java">:classHelloWorld{publicstaticvoidmain(String[]args){System.out.println("Hello World!");// Print "Hello World!"}}
There are no universally accepted standards for presenting algorithms on Wikipedia. Below, we adot the invisible "pre" method described above. A past attempt at standardized pseudocode is archived atUser:Dcoetzee/Wikicode, though "[t]he author advises that such a proposal not be advanced again, as it is unlikely to gain consent". WithinWikiProject Computer science, the consensus has generally been that where possible, algorithms should be presented in pseudocode. The use of pseudocode is completely language agnostic, and is more NPOV with respect to programming languages in general. Pseudocode also provides far more flexibility with regard to the level of implementation detail, allowing algorithms to be presented at however high a level is required to focus on the algorithm and its core ideas, rather than the details of how it is implemented. Finally, suitably high-level pseudocode provides the mostaccessible presentation of an algorithm, particularly for non-programmers.
algorithm ford-fulkersonisinput: GraphG with flow capacityc, source nodes, sink nodetoutput: Flowf such thatf is maximal froms tot(Note that f(u,v) is the flow from node u to node v, and c(u,v) is the flow capacity from node u to node v)for each edge (u,v)inGEdof(u,v) ← 0f(v,u) ← 0while there exists a pathp froms totin the residual networkGfdo letcf be the flow capacity of the residual networkGfcf(p) ← min{cf(u,v) | (u,v)inp}for each edge (u,v)inpdof(u,v) ←f(u,v) +cf(p)f(v,u) ← −f(u,v)returnf| Operator | Result | Entity | Example |
|---|---|---|---|
| Assignment | ← or := | ←, := | c ← 2πr,c := 2πr |
| Comparison | =, ≠, <, >, ≤, ≥ | =, ≠, <, >, ≤, ≥ | |
| Arithmetic | +, −, ×, /, mod | +, −, ×, /, mod | |
| Floor/ceiling | ⌊, ⌋, ⌈, ⌉ | ⌊, ⌋, ⌈, ⌉ | a ← ⌊b⌋ + ⌈c⌉ |
| Logical | and,or | '''and''', '''or''' | a ≥banda ≤c |
| Sums | ∑ ∏ | ∑ ∏ | h ← ∑a∈A 1/a |
if conditionthencode pathelse if conditionthencode pathelsecode pathend if
while conditiondocode blockrepeat
for loop_controldocode blockrepeat
loop_control is any suitable clause to control a for loop, such asitemin list or1 ≤ i ≤ n etc.function function_nameiscode blockreturn variableend function
function_name is any reasonable format of function name and arguments. Alternatively, inputs and outputs can be specified within the function block:function function_nameisinput:description of inputsoutput:description of outputscode blockreturn variableend function
An example of pseudocode roughly hewing to these guidelines is provided as the example on theAlgorithm page, and inBucket sort,Topological sort, andPollard's rho algorithm.
:'''Inputs'''''description of input arguments'':'''Output'''''description of outputs'':#''(description of a step in the algorithm)'':#''(the next step in the algorithm)'':##''(substep)'':#''(etc.)''
Examples of algorithms in this format includeBuchberger's algorithm,Pohlig–Hellman algorithm,Itoh–Tsujii inversion algorithm,Baby-step giant-step, andPollard'sp − 1 algorithm.
It isessential for article content to be verifiable with reliable sources, a well-chosen list of references and pointers to the literature. Any quotation, any material challenged or likely to be challenged, and any claim that involves a living personmust be supported by aninline citation to a reliable secondary source. Some additional reasons for citing high-quality sources are the following:
Primary sources must be used with care. They aregenerally permissible for non-controversial and non-promotional claims about the subject or its author(s). Examples: referencing a blog post from theRust programming language development team is sufficient for a point about the internal architecture of the Rust compiler, or the motivation behind a specific decision about the Rust language design. However, such a source cannot be used for providing Rust benchmarks, or contrasting Rust's features versus those of another language, since such claims from the developers may have a promotional element and involve analysis, evaluation, interpretation, or synthesis of facts and evidence, whichrequires a secondary source.
Wikipedia does not enforce a specific reference and citation style; just use one consistently within a particular article.