Identifiers

Computer Science: KS3, topic 2.3.10

Identifiers

Identifiers are the names given to variables, constants, and subroutines.

Variables

Variables

  • Variables should have lowercase names, with each word separated by an underscore. For example:
  • this_is_my_variable
  • user_money
  • Variable should also have descriptive names, for example user_money is much better than this_is_my_variable.
Constants

Constants

  • Constants should be named using the same rules as variables, but uppercase.
Subroutines

Subroutines

  • Subroutines should have lowercase names, with each word separated by an underscore. For example:
  • calculate_sum()
  • get_user_id()
  • Subroutines should have descriptive names where possible.
Global rules

Global rules

  • In general, all identifiers should be descriptive.
  • Characters which might be confused should be avoided, for example:
  • 0 and O.
  • 1 and l (lower case L).

Test yourself on Identifiers

  • Which character should separate each word in variable and constant identifiers?

  • Which of the following are suitable names for constants?

Practise this topic for free