Algorithms - EduqasIdentifiers and annotation

Algorithms are step-by-step plans for solving problems. They are a starting point when writing a program. Algorithms can be designed using pseudo-code and flowcharts.

Part ofComputer ScienceUnderstanding Computer Science

Identifiers and annotation

Identifiers

Choosing meaningful names for the , and makes it easier for the next person to work on the code to understand it.

These names are called and they usually follow certain rules:

  • They can contain letters and numbers but must start with a letter.
  • They must contain at least one letter (at the start of the name).
  • They must not contain special characters such as !@£$%&* or punctuation characters. However, an underscore can be used.
  • Spaces are not allowed.
  • They will normally contain lower case letters. However, upper case letters can be used if a variable name comprises more than one word joined together.
  • The name should be meaningful - it should represent the value it is holding.
Acceptable variable identifiersUnacceptable variable identifiers
highScorehigh score
high_score$core
highScore123123highScore
Acceptable variable identifiershighScore
Unacceptable variable identifiershigh score
Acceptable variable identifiershigh_score
Unacceptable variable identifiers$core
Acceptable variable identifiershighScore123
Unacceptable variable identifiers123highScore

Constants follow the same naming conventions as variables except that they are conventionally written in upper case.

Annotation

Annotations help other programmers make sense of the program. They are helpful notes that are put into the code to add explanations that will be ignored by the

Generally, annotations in are added using curly brackets.

if counter < 10 output counter {The counter will be printed if under 10} else output “Too high” end if

Each language has its own way of indicating annotations. Java uses the notation displayed below:

/** The counter will be printed if under 10 */