Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Guidelines Pseudocode

darcy-camargo edited this page Apr 21, 2021 · 1 revision

PSEUDOCODE BEST PRACTICE

Pseudocode, as the name suggests, is a high-level representation of code written in such a manner that other developers (or even laymen with some school-level programming knowledge) could comprehend the algorithm. There are no strict rules to write pseudocode, and thus, the programmer could write it as (s)he wishes. For the sake of coherence, in this document we provide here the guidelines on how to write pseudocode for any Coordicide spec file.

DO’S

  1. Use appropriate naming conventions. We suggest to use the following sentence casings:
    • CamelCase (with uppercase initial): for functions and procedures (e.g., RateSetting, GetMana)
    • camelCase (with lowercase initial): for variable names (e.g., nodeID, scheduleTime)
    • UPPER CASE, for commands (e.g., IF, WHILE) and constants (e.g., MAX_DEFICIT)
    • In order to differentiate between commands and constants, we suggest using the directive ‘vbnet’ when introducing the coding environment in the markdown language.
  2. Write only one statement per line.
  3. Use standard programming structures. Use structures such as ‘if-then’, ‘for’, ‘while’, ‘cases’ the way we use it in programming. If you are describing a function or data structure that a typical student will know about (e.g., sorting, a hash table) there is no need to describe its implementation in detail. In fact, doing so will actually make your pseudocode less readable, as you will be including unnecessary extra stuff that your reader will need to go through.
  4. Include enough details such that a developer can implement your algorithm. Check whether all the sections of a pseudo code are complete, finite and clear to understand and comprehend. Elaborate everything which is going to happen in the actual code. Don’t make the pseudo code abstract.
  5. Indentation. Use indentation for the block body (e.g., for ‘if-else’, ‘for’, ‘while’ loops). It keeps the body of every component isolated and indenting different pieces of each block will indicate that those pieces of pseudocode go under a less intended section.

DON’TS

  1. Don't use language-specific syntax. If your readers are not intimately familiar with the language you are using, they will struggle to follow what you are doing.
  2. Avoid unnecessary code-related details. For example, avoid the use of curly braces or ‘endif’/’endfor’ to end your conditional and loop statements. Your pseudocode will be easier to read if you indent it clearly enough that someone can tell just by looking at it where the conditional/loop block ends. You also should not use things like #include statements, import statements, etc.
  3. Don’t be unnecessarily wordy. It is generally better to provide shorter pseudocode fragments that include all the information you need, than to provide needlessly long pseudocode.

OPERATORS

  • Assignment Operator: =
  • Comparison Operator: == (equal), != (not equal), < (less), > (greater), <= (less or equal), >= (greater or equal)
  • Arithmetic Operator: + (plus), - (minus), * (multiply), / (divide), MOD (modulo), SUM (sum), PROD (product), MIN (minimum), MAX (maximum)
  • Logical Operator: AND, NOT and OR
  • Other special keywords: INPUT (list inputs from the user), PRINT (print the output on the screen), RETURN (output value of the function)

CONDITIONAL AND LOOP STATEMENTS

  • IF
IF <condition>
<body>
  • FOR LOOP
FOR <initial_value> TO <end_value>
<body>
FOR <iteration_bounds>
<body>
  • WHILE LOOP
<body>
  • FUNCTION
FUNCTION <output> (if any) = < FunctionName(parameters) >
< body >
RETURN <value>
  • EXAMPLE
IF value == -1
    IF GetDeficit(nodeId) < MAX_DEFICIT
  mana = GetAccessMana(nodeId)
  SetDeficit(nodeId, MIN(GetDeficit(nodeId) + mana, MAX_DEFICIT))
ELSE
    SetDeficit(nodeId, MAX(GetDeficit(nodeId)- value, 0))```