Certain rules must be followed when assigning names to your constants.

PHP, C++, C#

  • The name can contain only Latin characters (English uppercase or lowercase characters), numbers, and the underscore character ( _ ). Moreover, even though lowercase letters are permitted, it is advisable to use only uppercase letters. This helps you to visually distinguish constants from variables. Examples of constant names are VAT and COMPUTER_NAME.
  • Constant names are case sensitive, which means there is a distinct difference between uppercase and lowercase characters. For example, the myCONST, myconts, MYCONST, and MyConst are actually four different constants.
  • No space characters are allowed. If a constant is described by more than one word, you can use the underscore character ( _ ) between the words. For example, the constant name COMPUTER NAME is wrong. Instead, you might use COMPUTER_NAME, or even COMPUTERNAME.
  • A valid constant name can start with a letter or an underscore. Numbers are allowed, but they cannot be used at the beginning of the constant name. For example, the constant name 1COMPUTER_NAME is not properly written. Instead, you might use something like COMPUTER_NAME1 or COMPUTER1_NAME.
  • A constant name is usually chosen in a way that describes the meaning and the role of its contained data. For example, a constant that holds the Value Added Tax might be named VAT, or VALUE_ADDED_TAX.

Java

  • The name can contain only Latin characters (English uppercase or lowercase characters), numbers, the dollar sign ( $ ), and the underscore character ( _ ). Moreover, even though lowercase letters are permitted, it is advisable to use only uppercase letters. This helps you to visually distinguish constants from variables. Examples of constant names are VAT and COMPUTER_NAME.
  • Constant names are case sensitive, which means there is a distinct difference between uppercase and lowercase characters. For example, the myCONST, myconts, MYCONST, and MyConst are actually four different constants.
  • No space characters are allowed. If a constant is described by more than one word, you can use the underscore character ( _ ) between the words. For example, the constant name COMPUTER NAME is wrong. Instead, you might use COMPUTER_NAME, or even COMPUTERNAME.
  • A valid constant name can start with a letter or an underscore. Numbers are allowed, but they cannot be used at the beginning of the constant name. For example, the constant name 1COMPUTER_NAME is not properly written. Instead, you might use something like COMPUTER_NAME1 or COMPUTER1_NAME.
  • A constant name is usually chosen in a way that describes the meaning and the role of its contained data. For example, a constant that holds the Value Added Tax might be named VAT, or VALUE_ADDED_TAX.

 

Visual Basic

  • The name can contain only Latin characters (English uppercase or lowercase characters), numbers, and the underscore character ( _ ). Moreover, even though lowercase letters are permitted, it is advisable to use only uppercase letters. This helps you to visually distinguish constants from variables. Examples of constant names are VAT and COMPUTER_NAME.
  • Constant names are not case sensitive, which means there is no difference between uppercase and lowercase characters. For example, the myCONST, myconts, MYCONST, and MyConst names are actually referring to the same constant.
  • No space characters are allowed. If a constant is described by more than one word, you can use the underscore character ( _ ) between the words. For example, the constant name COMPUTER NAME is wrong. Instead, you might use COMPUTER_NAME, or even COMPUTERNAME.
  • A valid constant name can start with a letter or an underscore. Numbers are allowed, but they cannot be used at the beginning of the constant name. For example, the constant name 1COMPUTER_NAME is not properly written. Instead, you might use something like COMPUTER_NAME1 or COMPUTER1_NAME.
  • A constant name is usually chosen in a way that describes the meaning and the role of its contained data. For example, a constant that holds the Value Added Tax might be named VAT, or VALUE_ADDED_TAX.

Python

Unfortunately, Python does not support constants. So, variables are all you have. You can use a variable in place of a constant, but take care not to accidentally change its initial value each time you use this variable in your program. It is also advisable to use only uppercase letters. This helps you to visually distinguish those variables that are used as constants  from the actual variables.

Leave a Reply

Your email address will not be published. Required fields are marked *

This article is taken from a book of mine. If you enjoyed it, please visit my author's page inand check out all of my books!