Names a string of
characters used to identify some entity in a program.
Design Issues for names:
What is the maximum length of
a name?
Can connector characters be
used in names?
Are names case sensitive?
Are the special words reserved words
or keywords?
Length of name:
FORTRAN I , FORTRAN 77
single character
FORTRAN 95, C
up to 31 characters
Ada, C#, Java
no length limit
C++
technically unlimited
reality limited by implements of language
(because of maintenance of symbol table)
Connector characters:
e.g. underscore ( _ )
Most contemporary languages allow connector characters in
names.
Special characters
PHP: all
variable names must begin with dollar signs
Perl: all
variable names begin with special characters, $, @, or %, which specify the
variable’s type ($variable, @array_name, %hash_variable)
Ruby:
variable names that begin with @
are instance variables; those that begin with @@
are class variables
Case sensitive:
apple is not same as Apple (They look same,
but not same. It hurts readability.)
C, C++, Java are case sensitive
e.g.. Java method for
converting a string to an integer value is parseInt,
not ParseInt, parseint.
(The above hurts writability.)
versions of FORTRAN prior to 90
only uppercase letters can be used in names
since card punches had only uppercase letters.
Special words
Keyword
special only in a certain contexts
FORTRAN:
REAL APPLE
(declarative statement)
REAL = 3.4
(variable name)
INTEGER REAL
REAL INTEGER
implicit type: I to N are integer,
others are real
Reserved word
cannot be used as a user-defined name. An aid to
readability; used to delimit or separate statement clauses
Predefined words are between
reserved words and user-defined names.
e.g. header files
Potential
problem with reserved words: If there are too many, many collisions occur
(e.g., COBOL has 300 reserved words!)