1/118
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Imperative
functional
programs are constructed by applying and composing
functions (output from one function call serves as an argument to
another function call).
declarative
programs are (logic) statements that express what the
program must do, without specifying how to do it
Object oriented
based on concept of objects that contain data and
classes with methods (code) to apply to data; objects inherit properties from class definitions
Markup
chatbot
compilation
translate source code to machine language to be executed directly on computer's CPU
interpretation
source code commands are executed by an interpreter program
Hybrid
translate source code to intermediate code that can interpreted quickly/easily
Readability
ease with which programs can be read and understood in the context of the problem domain
Writability
Reliability
Cost
the sum of costs of training programmers, effort in writing programs, compiling programs, executing programs, relying on programs, and maintaining programs
Simplicity
has a small number of constructs and clear rules for using them
Orthogonality
An orthogonal language has a relatively small set of primitive constructs, and these can be combined in a relatively small number of ways to build all the control and data structures of the language
expressivity
how convenient or cumbersome is it to specify computation in the language?
Syntax design
how complex are the forms of the language, and how obvious are the meanings of these forms?
data types
the adequacy of facilities for defining data types and data structures
Abstraction support
ability to define and use complicated structures or operations in ways that allow details to be ignored
type checking
what kind of testing for type errors does the language support at compile time and runtime?
Aliasing restriction
does the language limit or eliminate possibilities for more than one reference to the same memory cell to exist?
Exception handling
how does a language support interception of runtime errors, take corrective measures, and continue?
Name
a string that represents an entity in a program
special word
symbol that aids readability by naming predefined actions/programming structures
keyword
word that is special in certain contexts
reserved word
special word that cannot be used as a name
variable
an abstraction of a memory cell
name, value, lifetime, address, type, scope
characterized by a sextuple of attributed
name
identifier used to refer to a variable
address
memory location associated with a variable
value
contents in the variable's location
type
determines variable's values & permitted operations
binding
an association between a variable and an attribute
binding time
time at which a binding is made
language design time
language implementation time
compile time
link/load time
execution time
static binding
a binding is static if it occurs before run time
and remains unchanged throughout program execution
dynamic binding
a binding is dynamic if it occurs during
execution OR can change during program execution
stack-dynamic binding
explicit heap-dynamic binding
implicit heap-dynamic binding
Program call stack
(THE Stack) memory set aside by process to keep track of calls to program units as the program runs.
the heap
memory set aside for process to store and dynamically maintain data as the program runs
stack storage
bound to memory address before execution, and remains bound to same cell throughout execution
static storage
Advantage: efficiency (direct addressing)
Disadvantage: lack of flexibility (no recursion)
stack-dynamic storage
Storage allocated on stack for variable when its declaration statement is elaborated (executed)
All attributes except address are statically bound
advantage:
disadvantage: overhead of allocation and deallocation;
inefficient references (indirect addressing)
explicit heap-dynamic storage
allocation and deallocated by explicit directives during execution
Advantage: dynamic storage management
Disadvantage: occasionally unreliable
Implicit heap-dynamic storage
allocation and deallocation caused by assignment statements
advantage: flexibility
disadvantages: inefficient, all attributes are dynamic, loss of error detection
A language's type binding rules define
how types are specified
when type bindings take place
Types are specified by explicit or implicit declarations
explicit: stated in program source code
implicit:
type
determined at compile time
static type binding
Advantage: readability, safety, reliability
Disadvantages: long compile times, coding can be inflexible
Dynamic type binding
Advantage: programming flexibility, writability
• Disadvantages: dynamic type checking takes a lot of time during interpretation (run time); type error detection by compiler is difficult
lifetime of a variable
the time during which the variable is bound to a particular memory cell
allocation
get a cell from some
pool of available cells
deallocation
put a cell back in the free pool
visibility of a variable
where in a program that a variable's value can be accessed
scope of a variable
the range of code statements over which it is visible
local variables of a program unit
declared in the unit
nonlocal variables of a program unit
visible in the unit but not declared there
global variables
nonlocal variables visible over all code
static scope
Based on program’s text (source code)
dynamic scope
Based on calling sequences of program units (methods,
functions, etc), not their textual layout.
dynamic scope
Advantage: Convenience in Writing
• Disadvantages: While a subprogram unit is executing, its variables are visible to all subprograms it calls, Impossible to do static type checking, Poor readability - not possible to determine the type of a variable statically
java
local: vars defined inside methods; these are created
at function call, not at function definition
nonlocal: members of objects passed into a method "this" to reference members of a class class prefix to reference members, global: vars defined as members of program class
Python
uses the "namespace" model
Local: any variable defined inside a function; these
are created at function call, not function definition
Global: all variables defined at topmost level in a
program (outside defs); need to use "global"
keyword when accessing inside a function.
Nonlocal: for nested functions; vars defined in
enclosing function are visible to the code in the
enclosed function using "nonlocal".
referencing environment
the collection of all names that are visible in the statement
In static-scoped languages, it’s the local variables plus all visible variables in all of the enclosing scopes
In dynamic-scoped languages, it’s the local variables plus all variables in all active subprograms
“active subprogram” = execution has begun but
has not yet terminated
named constants
A variable that is bound to a value only ONCE.
Advantages: readability and modifiability
Advantage: parameterizes programs
data type
a collection of data objects and a set of predefined operations on those objects
object
an instance of a user-defined (abstract data) type
descriptor
the collection of attributes of a variable
primitive data types
A data type that is not defined in terms of other
data types
integer
Almost an exact reflection of the hardware, so mapping is trivial
There may be as many as eight different integer types in a language
EX: Java has byte, short, int, and long
Sizes:
floating point
Meant to model real numbers, as approximations
For scientific use, languages support at least two types: float and double, sometimes more
Usually a direct mapping to hardware, but not always
rationals
a ratio of integers, represented as pairs of integers
Size:
Advantage: supports precise rational arithmetic
complex
Each value consists of two floats, the real part and the imaginary part
EG: literal form in Python: (7 + 3j)
EG: literal form in Lisp: #C(7 3)
decimal
(NOT INTEGERS) For business applications
Available in COBOL and C#
Stores a fixed number of decimal digits, in BCD (binary
coded decimal) form
Advantage: Accuracy (includes decimal-point values)
Disadvantage: limited range, wastes memory
boolean
Simplest of all
Range of values: two elements
one for “true” and one for “false”
Could be implemented as bits, but
often as bytes
character
Values ==> stored as numeric codings
ASCII (8-bit, 7-bit) is most common
16-bit unicode
includes characters from many human languages
first supported in Java
C#, JavaScript, Python 3, and Lisp and Swift also support Unicode
32-bit unicode
Fortran, starting in 2003
C and C++
Not primitive; uses char arrays + library
SNOBOL4 (a string manipulation language)
Primitive; many ops, elaborate pattern matching
Fortran and Python and Lisp
Primitive; assignment and several ops
Java
Primitive via String class
static length
COBOL, Java String
limited dynamic length
(C and C++) a special character code (0) indicates end of a string’s content
dynamic (no maximum) length
SNOBOL, Perl, JavaScript, Lisp, Python
benefits and cost of character string type
Aid to writability
Implementation Issues
user-defined ordinal types
An ordinal type is one in which the range of possible values can be readily associated with the set of positive integers
enumeration types
All possible values, which are named constants, are provided in the definition
pros of enumeration types
Aid to readability (no need for magic numbers to
represent non-obvious meanings, e.g. color names)
Aid to reliability — better than constants, compiler can
check stuff
operator validity (e.g. don’t let colors be multiplied)
no enumeration variable can be assigned a value
outside of its defined range
Ada, C#, and Java have better support for
enumeration than C: they do not allow enumeration
type variables to be coerced into integer types.
cons of enumeration types
Problem with writability: Some languages require
writing of extra code for reading/writing the values of
an enumeration-typed variable
subrange type
An ordered contiguous subsequence of an ordinal type
Aids readability: make it clear to reader that variables of subrange can store only certain range of values
• Aids reliability: assigning a value to a subrange variable that is outside the specified range is detected as an error
• Natively available in Algol68, Pascal, Python, and Ada.
array
a homogeneous aggregate of data elements in which an individual element is identified by its position in the aggregate, relative to the first element
array indexing