-
Things to consider when designing variable names
- Length (max, min)
- Case sensitivity
- Type/form
-
Non case-sensitive languages
Pascal, basic
-
Examples of case sensitive languages
Java, C++
-
Characters with name length limits
- COBOL (30)
- FORTRAN 95 (31)
-
(six) Attributes associated with a variable
- Name
- Address
- Type
- Value
- Lifetime
- Scope
-
Examples of variables that don't have names
Arrays
-
Alias
- An alias if a variable with a different name, that points to the same memory location
- Pointers, references and unions are examples of aliases
- Aliases hurt readability
-
Types of binding
- Static - Binding occurs before program runtime and remains unchanged
- Dynamic - Binding occurs during program runtime and can change during runtime
-
Types of static type binding
-
How are explicit types declared
Either with a type, or an expression before the identifier
-
How are implicit types declared?
- Default conventions (i.e variables that begin with certain letters will have specific types)
- Don't need a type identifier
-
FORTRAN's declaration type
- Implicit
- Variables beginning with I, J, K, L, M or N (and lowercase too) are integers
- Other variables are real numbers
-
Perl declaration type
- Implicit
- $var is a scalar
- @var is an array
- %var is a hash structure
-
Type bindings for implicit and explicit declarations
Static
-
|
|