music programming text book

valid identifiers


    Each language has its own rules for naming valid identifiers.

free computer programming text book project

table of contents
If you like the idea of this project,
then please donate some money.
more information on donating


valid identifiers

    Each language has its own rules for naming valid identifiers.

    Common kinds of identifiers:

    Asdf are named by a valid identifier.

    Quick summary of the rules for building valid identifiers in several major languages, using regular expressions:

ALGOL-68[a-z][a-z0-9 ]*
30 character maximum
Classic REXX[a-zA-Z!?@#][a-zA-Z0-9!?@#]*
Common Lispanything without a space and is not a number
maximum of six characters
Forthanything without a space and is not a number
Lispanything without a space and is not a number
Pliant[_a-zA-Z][_a-zA-Z0-9]* or '[^']*'
[^0-9[](){}":;/][^ \n\t[](){}":;/]*


    Identifiers in Pascal include the names of programs, names of variables, names of constants, and names of labels.

    In our first sample program, the name SampleProgram is an identifier that gives the name of the program.

program SimpleProgram (output);
    writeln ('Hello World')

    Pascal requires that all valid identifiers begin with a letter. After the first (initial) letter, the identifier may have any combination of letters and digits, but no other characters.

    Note that while the official Pascal standard forbids any characters other than digits and letters, many Pascal compilers do allow the underscore character (_) after the first character of an identifier.

    Pascal is case insensitive. That is, it makes no difference whether the letters or upper case or lower case. SAMPLEPROGRAM, sampleprogram, and SampleProgram are all the same identifier in pascal.

    Examples of valid Pascal identifiers:

    Lily    Frog32    Jump2Pad

    Examples of invalid (illegal, error) Pascal identifiers:

    9Lily    Kermit the Frog    Jump*over@me

    The first identifier (9Lily) is invalid because it starts with a number rather than a letter.

    The second identifier (Kermit the Frog) is invalid because it includes spaces.

    The third identifier (Jump*over@me) is invalid because it includes illegal characters (the * and the @) are neither letters nor digits.

    Note that you can not use any reserved word (such as program, begin, or end) as an identifier.

    While the official Pascal standard states that identifiers can be as long as you want (at least one character, but no upper limit), many pascal compilers have a shorter length used internally.

    Eight characters is a common limitation.


    With an eight character limit, the Pascal compiler would accept both of these names, but would treat them as the same identifier, not as different identifiers, because they share the same first eight characters. This may seem silly, but this can cause headaches if you don’t know about this problem because it is easy to have two or more identifiers that start with the same eight characters.

    As mentioned previously, it is very important to use meaningful identifiers. You want to be able to understand what everything does when you come back to make changes in the future (and most of the lifetime of any successful program is long term maintenance).

    Examples of meaningful identifiers:

    RunningSubTotal    ArtistName    CurrentSpeed

    Examples of unmeaningful (obscure, bad) identifiers:

    A    CTR    HSV205


    Identifiers in C include the names of programs, names of variables, names of constants, names of functions, and names of labels.

    Identifiers may be any number of letters (upper and lower case), digits, and the underscore character ( _ ). An identifier may not start with a digit.

    C is case sensitive, so identifiers that differ only in capitalization are different identifiers.

    None of the keywords in C may be used as an identifier. It is best to also avoid using any standard library function names as a programmer defined identifer. Note that because C is case sensitive, if is a keyword, while IF is not a keyword. Nonethless, it is unwise to use IF (uppercase ltters) as an identifier (variable, function name, etc.) because of the confusion this would cause.

    It is a common C programming convention to use lower case letters for variable names and to use upper case letters for constants. This convention is not enforced by the compiler, but it does make your programs more readable.

    Some C compilers only use the first six (6) or eight (8) characters of an identifer. For maximum portability, make sure that all identifiers are unique in just their first six characters.

Stanford C essentials

    Stanford CS Education Library This [the following paragraph] is document #101, Essential C, in the Stanford CS Education Library. This and other educational materials are available for free at This article is free to be used, reproduced, excerpted, retransmitted, or sold so long as this notice is clearly reproduced at its beginning. Copyright 1996-2003, Nick Parlante,

    Names in C are case sensitive so “x” and “X” refer to different variables. Names can contain digits and underscores (_), but may not begin with a digit. Multiple variables can be declared after the type by separating them with commas. C is a classical “compile time” language -- the names of the variables, their types, and their implementations are all flushed out by the compiler at compile time (as opposed to figuring such details out at run time like an interpreter).

    float x, y, z, X;


    Python programs are divided into tokens, which includes delimters, identifiers, keywords, literals, and operators.

    Python identifiers must begin with a capital or lower case letter (A to Z and a to z) or underscore (_). The intiial character may be followed by zero or moreletters, underscores, or digits, in any combination.

    The identifier of a single underscore character (_) is a special identifier that the Python interpreter binds to the most recently evaulated expression during an interactive session.

    By convention (not required, but a good idea for readability), class names start with a capital letter and most other identifiers start with a lower case letter.

    A private identifier is normally started with a single underscore character.

    A strongly private identifier is normally started with two underscore characters.

    A language-defined special name starts with two underscore characters and ends with two underscore characters.


    Constants must start with a capital letter and are usually written with all caps.

    Local variables must start with a lowercase letter or an underscore character (_).

    Instance variables must start with a single at sign (@).

    Class variables must start with two at signs (@@).

    Global varaiables must start with a dollar sign ($).

free music player coding example

    Coding example: I am making heavily documented and explained open source code for a method to play music for free — almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).

    View music player in action:

    Create your own copy from the original source code/ (presented for learning programming).

return to table of contents
free downloadable college text book

view text book
HTML file

Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.

previous page next page
previous page next page

free computer programming text book project

Building a free downloadable text book on computer programming for university, college, community college, and high school classes in computer programming.

If you like the idea of this project,
then please donate some money.

send donations to:
PO Box 1361
Tustin, California 92781

Supporting the entire project:

    If you have a business or organization that can support the entire cost of this project, please contact Pr Ntr Kmt (my church)

more information on donating

Some or all of the material on this web page appears in the
free downloadable college text book on computer programming.


Made with Macintosh

    This web site handcrafted on Macintosh computers using Tom Bender’s Tex-Edit Plus and served using FreeBSD .

Viewable With Any Browser

    †UNIX used as a generic term unless specifically used as a trademark (such as in the phrase “UNIX certified”). UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company Ltd.

    Names and logos of various OSs are trademarks of their respective owners.

    Copyright © 2010, 2011 Milo

    Created: October 30, 2010

    Last Updated: March 19, 2011

return to table of contents
free downloadable college text book

previous page next page
previous page next page