music |
OSdata.com |
valid identifiers
summary
Each language has its own rules for naming valid identifiers.
free computer programming text book projecttable of contents
|
music |
OSdata.com |
Each language has its own rules for naming valid identifiers.
free computer programming text book projecttable of contents
|
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:
Ada | [a-zA-Z](_?[a-zA-Z0-9])* |
---|---|
ALGOL-68 | [a-z][a-z0-9 ]* |
Awk | [_a-zA-Z][_a-zA-Z0-9]* |
B | [_a-zA-Z][_a-zA-Z0-9]* |
BourneShell | [_a-zA-Z0-9]+ |
C | [_a-zA-Z][_a-zA-Z0-9]* |
C# | [_a-zA-Z][_a-zA-Z0-9]* |
C++ | [_a-zA-Z][_a-zA-Z0-9]* |
COBOL | [a-zA-Z][a-zA-Z0-9-]* 30 character maximum |
Classic REXX | [a-zA-Z!?@#][a-zA-Z0-9!?@#]* |
Common Lisp | anything without a space and is not a number |
E | [_a-zA-Z][_a-zA-Z0-9]* |
Eiffel | [a-zA-Z][_a-zA-Z0-9]* |
F# | [_a-zA-Z][_a-zA-Z0-9']* |
FORTRAN | [A-Z][A-Z0-9]* maximum of six characters |
Forth | anything without a space and is not a number |
GNU-bc | [a-z][a-z0-9_]* |
Haskell | [_a-z][_a-zA-Z0-9']* |
Java | [_a-zA-Z$][_a-zA-Z0-9$]* |
JavaScript | [_a-zA-Z$][_a-zA-Z0-9$]* |
Lisp | anything without a space and is not a number |
Maple | [_a-zA-Z][_a-zA-Z0-9]* |
Mathematica | [a-zA-Z][a-zA-Z0-9]* |
Matlab | [a-zA-Z][_a-zA-Z0-9]* |
Mercury | [_a-z][_a-zA-Z0-9']* |
merd | [_a-z][_a-zA-Z0-9]*[!?']* |
Modula-3 | [a-zA-Z][_a-zA-Z0-9]* |
MUMPS | [a-zA-Z%][a-zA-Z0-9]* |
OCaml | [_a-z][_a-zA-Z0-9']* |
Pascal | [a-zA-Z][a-zA-Z0-9]* |
Perl | [_a-zA-Z0-9]+ |
Perl6 | [_a-zA-Z0-9]+ |
PHP | [_a-zA-Z][_a-zA-Z0-9]* |
PL/I | [a-zA-Z][a-zA-Z0-9]* |
Pliant | [_a-zA-Z][_a-zA-Z0-9]* or '[^']*' |
Prolog | [_A-Z][_a-zA-Z0-9]* |
Python | [_a-zA-Z][_a-zA-Z0-9]* |
Rebol | [_a-zA-Z?!.'+*&|=~-][_a-zA-Z0-9?!.'+*&|=~-]* or [^0-9[](){}":;/][^ \n\t[](){}":;/]* |
Ruby | [_a-z][_a-zA-Z0-9]* |
Scheme | [_a-zA-Z!0&*/:<=>?^][_a-zA-Z!0&*/:<=>?^0-9.+-]* |
SmallTalk | [a-zA-Z][a-zA-Z0-9]* |
SML | [_a-z][_a-zA-Z0-9']* |
Tcl | [_a-zA-Z][_a-zA-Z0-9]* |
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);
begin
writeln ('Hello World')
end.
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.
GeorgeWashington
GeorgeWashingtonCarver
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 dont 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 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 http://cslibrary.stanford.edu/. 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, nick.parlante@cs.stanford.edu.
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 ($).
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: www.musicinpublic.com/.
Create your own copy from the original source code/ (presented for learning programming).
return to table of contents
free downloadable college text book
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 |
Tweets by @osdata |
free computer programming text book projectBuilding 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, 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) free downloadable college text book on computer programming. |
This web site handcrafted on Macintosh computers using Tom Benders Tex-Edit Plus and served using FreeBSD .
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 |