PEGWiki:Notational conventions

From PEGWiki
Revision as of 21:30, 14 November 2009 by Brian (Talk | contribs) (Created page with 'This page documents some conventions to be followed when writing pseudocode on PEGWiki. These are not binding policy on PEGWiki, but following them should minimize confusion and …')

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This page documents some conventions to be followed when writing pseudocode on PEGWiki. These are not binding policy on PEGWiki, but following them should minimize confusion and promote consistency across articles. Similarly, if you see unfamiliar notation in a pseudocode block, you may find its meaning here. Changes to these conventions should be discussed on the talk page.

All pseudocode

  • Structure should be indicated by indentation, as in Python. Adding braces {} as in C or words such as begin and end as in Pascal would introduce unnecessary clutter into pseudocode blocks. Do not use tabs for indentation. Five spaces is a good guideline. (In LaTeX pseudocode, this means five full-width spaces (a full-width space is "\ ").)
  • The for, if/else, and while statements should not be followed by words like "do" or "then"; pseudocode is intended for humans, not machines.
  • Indices into arrays should be placed in square brackets, []. The Pascal convention of separating indices by commas is preferred to the C convention of having a separate set of brackets for each index (simply by virtue of being nicer and more intuitive), but the latter may be occasionally appropriate to reinforce the interpretation of the array's structure. Use your common sense.
  • Parameter lists should be enclosed in parentheses, (), and parameters should be separated by commas.

Text-mode pseudocode

  • Variable assignment should occur through the use of a single equals sign, =, although the Pascal notation of := is also acceptable.
  • Equality testing should also occur through the use of a single equals sign, =, but is distinguished from variable assignment by context. For example, if it is preceded by if, it is an equality test, and if it stands alone, it is an assignment. The C notation of == should be avoided.
  • The symbols <=/>= and ≤/≥ are equally acceptable, but in most other cases a Unicode symbol should be used whenever both necessary and possible. For example, oo for is unacceptable.

Math-mode pseudocode

  • The LaTeX \sqrt command is almost always preferable to typing out \operatorname{sqrt}.
  • The vinculum (horizontal bar) to indicate division is usually best, but if the numerator or denominator is complex, a single slash / is preferable when it improves readability or overall aesthetic appeal.
  • Exponentiation should always occur in the form a^b rather than in the form a^b. When the exponent is so complex that superscripting makes the expression look ugly, use a temporary variable for the exponent. The exception is when the base is e: you can replace e^x with \exp(x) in that case.
  • Actual words, such as "if" and "and", should not be italicized. Use the \mathrm function to de-italicize them.
  • Equality testing should occur through the = symbol.
  • Variable assignment should occur through the \gets symbol (LaTeX code: "\gets")