An identifier is what it literally means. It is like a unique identity for a class, variable, object, or a function, or anything needing an identifier. Some rules need to be followed while declaring an identifier:-
1) For a variable:-
Can have alphanumeric characters ((A-Z), (a-z), (0-9), ($, _))
It can start with $ or _, but it cannot start with a number.
No spaces allowed.
Below are some naming conventions that are recommended(not necessary to be followed).
IDEAL CONVENTIONS FOR NAMING VARIABLES
Keep the variable name as something sensible, not any random sequence. Preferably, the name should be related to the context the variable is being used in. For example, the variable storing the sum of two numbers can be called as sum. Variables like i, or j, or i, or i2 are recommended for throwaway variables like those used in loop constructs. The first letter should always be in lower case, and as no spaces are allowed, the subsequent words can be written using the Camel Case. For example, a variable for the sum of two integers can be as sumOfIntegers, the first letter of each new word being capital. Where we need to use two words, we can also use an _(underscore) as a separator. For example, money_obtained, credit_left, instead of moneyObtained or creditLeft, of which both are correct, too.
2) For a function:-
Can have alphanumeric characters ((A-Z), (a-z), (0-9), (_)).
Can't begin with a number.
No spaces allowed.
Below are some naming conventions that are recommended(not necessary to be followed).
IDEAL CONVENTIONS FOR NAMING FUNCTIONS
The naming conventions are the same for functions as they are for variables, first letter of first word in lowercase, and subsequent first letters of words in higher case, or underscores, which are less recommended by us. Name should ideally be a verb, or a verb-noun combination.
1) For a class:-
Can have alphanumeric characters ((A-Z), (a-z), (0-9), (_)).
Can't start with a number.
No spaces allowed.
Below are some naming conventions that are recommended(not necessary to be followed).
IDEAL CONVENTIONS FOR NAMING CLASSES
Same as functions, except the first letter should always be a capital letter, and the name should ideally be a noun.
No comments:
Post a Comment