Seneca

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 case should variable names use?

  • Pick the correct rule for naming identifiers.

  • Which type of identifier follows the same naming rules as a subroutine?

  • A variable can be named user_money or this_is_my_variable. Why is user_money the better name?

  • A variable is named m0ney, using the number 0 instead of the letter O. Why does this break the naming rules?

Practise this topic for free