333_20240624123259 Flashcards

1
Q

Why should Concepts of programming languages be studied?

A

Programming is new.
General language concept knowledge helps.
Increased ability to express ideas.
“ “ to learn new languages.
Helps choose appropriate languages.
Understand tradeoffs.
Overall advancement of computing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the Language Evaluation Criteria?

A

Readability, Writability, Reliability, Cost

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is Readability defined as?

A

The ease with which programs can be read and understood

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Writability defined as?

A

The ease with which a language can be used to create programs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Reliability defined as?

A

Whether a language performs to its specifications under all conditions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Cost defined as?

A

cost of using the language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the Evaluation Criteria for Readability?

A

Overall simplicity: Manageable set of features and constructs(minimal feature multiplicity, minimal operator overloading)

Orthogonality: small set of primitive constructs can be combined in small number of ways

Data types; if types are missing, they must be simulated

Syntax considerations: Lack of naming restrictions increase readability (Identifier forms). More special words = more readable (Special words). meaningful keywords, avoid language constructs with same name and different meaning(Form and meaning)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why is a lack of orthogonality bad?

A

It can lead to exceptions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why is too much orthogonality bad?

A

bad for readability

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the problem with too much simplicity?

A

Can be bad for readability

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the Evaluation Criteria for Writability?

A

Simplicity and orthogonality: few constructs, small number of primitives, small set of rules for combining them

Support for abstraction: define and use complex structures/operations.(Process abstraction and Data abstraction)

Expressivity: convenient ways of specifying operations. Strength + number of operators and predefined functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is process abstraction?

A

Provision for subprograms

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is data abstraction?

A

classes, pointer & dynamic memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the Evaluation Criteria for Reliability?

A

Type checking: Test for type errors. Compile time checking > run time checking

Exception handling: intercept run time errors and correct it

Aliasing: Presence of 2+ distinct referencing names for same memory location. (dangerous feature)

Readability and writability: non-natural ways of expressing algorithms = unnatural approaches = reduced reliability

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the Evaluation Criteria for Cost?

A

Training new programmers.
Writing programs
compiling programs
Executing programs
Language implementation system (availability of free compilers)
Reliability(poor = high cost)
Maintaining programs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are some extra Evaluation Criteria?

A

Portability : ease of moving from on implementation to another
Generality: applicability to a wide range of applications
Well-definedness: Completeness + precision of of language’s official definition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are the Language Design trade-offs

A

Reliability vs cost of execution

Readability vs writability

Writability(flexibility) vs reliability

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are the programming domains?

A

Scientific Applications
Business Applications
AI
System Programming
Web Software

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What influences the Design of a Language?

A

Computer Architecture
Programming Methodologies (eg OOP led to new programming paradigms)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What influenced Programming Methodologies?

A

1950/60: simple applications (machine efficiency)
1960s: Efficiency + readability + better control structures (structured programming + top-down design + step-wise refinement)
1970: Process- oriented -> data-oriented (data abstraction
1980: OOP (Abstraction + inheritance + polymorphism)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are the Language Categories?

A

Imperative: Variables, assignment statements, iteration. has OOP languages. Includes visual languages. (c++ Java C ..)

Functional : Main means of computation, applying functions to parameters (LIST, Scheme)

Logic: Rule based (Prolog)

Markup/hybrid (XSLT, JSTL)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What are the Implementation Methods

A

Compilation: programs translated to ML

Pure Interpretation: Programs are interpreted by another program known as an interpreter

Hybrid: compromise between compilers and pure interpreters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What are the phases of Compilation

A

Lexical analysis: converts source characters to lexical units

Syntax Analysis: Transforms lexical units to parse trees

Semantics analysis: Generate intermediate code

Code generation: Machine code is generated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Is Compiled or Pure Interpreted programs faster

A

Compiled.
Interpreted programs are 10-100 times slower

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Does Interpreted or compiled programs use more space
Interpreted.
26
What is an example of a Hybrid Implementation System
Perl, typical Java programs
27
What is Just-In-Time Implementation Systems
Translate programs to intermediate language Compile the intermediate language into machine code when they are called
28
What uses JIT systems?
.NET languages
29
What are the different Programming environments?
UNIX, Microsoft Visual Studio.NET,NetBeans
30
When was Zuse's Plankakul designed?
1945. Never implemented. Not published until 1972
31
What was the environment for the development of Zuse's. and what was it used for
Environment = limited hardware,limited impact Use = wasnt implemented
32
Pseudocode environment and use
No specific environment use = break bigger problems down into smaller ones
33
What was speedcoding created for?
IBM 701
34
Was Fortran 0 implemented?
no
35
What was the environment for Fortran 1 and use?
IBM 704 had little memory. Machine efficiency was very important. use = business software/scientific computing
36
How was fortran II different from Fortran I?
More reliable and bug fixes
37
What was important about Fortran 77
It became the new standard in 1978
38
Why was Fortran important?
It changed how computers are used
39
Why was LISP created?
AI research needed a language to support
40
Why was LISP important?
It pioneered functional programming
41
Why was Scheme created and where is it used?
Created to promote functional programming. used in computer science courses
42
What is COMMON LISP
Feature rich dialect of LISP (it combines features of several LISP dialects) (almost opposite of scheme)
43
Environment of development for ALGOL 60
No universal language for communicating algorithms. No portable languages Needed to design a universal language
44
What was the goal for ALGOL
it must be close to mathematical notation. good for describing algorithms must be translatable
45
When was ALGOL 58 implemented?
It was never implemented but variations of it was
46
Environment of development for COBOL
Only few proprietary business languages at the time
47
On what programming language is COBOL based on?
FLOW-MATIC
48
what is COBOL used for?
Transaction processing, Data security (business application language)
49
What was the environment of development for BASIC
Time sharing systems was on the rise
50
What was BASIC used for?
A general programming language. first widely used language with time sharing
51
What was the environment of development for PL/I
Scientific users needed better I/O Business users needed floating point + arrays
52
What was PL/I used for?
Business, Scientific and Engineering applications
53
What was bad about PL/I?
poorly designed. Too large and too complex
54
What was the 2 early dynamic languages?
APL and SNOBOL
55
What was APL designed as?
A hardware description language
56
What is orthogonality?
the ability to "mix" different data types and perform operations with them
57
What was SNOBOL originally used for?
Writing text editors
58
What was SIMULA 67 designed for?
system simulation
59
How did SIMULA 67 advance programming?
It introduced coroutines and the beginnings of data abstraction
60
What was the design of the ALGOL 68 based on?
Orthogonality
61
What did ALGOL 68 contribute?
user-defined data structures. reference types. dynamic arrays
62
For what was C developed?
systems programming at Bell Labs
63
What is Prolog based on?
Formal logic
64
What was history's largest design effort?
Ada
65
What was Ada developed for?
US DoD
66
How many languages were in use by the DoD before Ada?
450+
67
What was Ada intended for?
Embedded system development
68
What did Ada contribute?
Packages, Exception handling, Generic Program units, Concurrency
69
What language had the first full implementation of true OO
Smalltalk
70
What did Smalltalk bring to the table?
Promoted GUI design and OOP paradigm
71
From where did C++ evolve from?
C + SIMULA 67
72
What was Java based on?
C++ without struct union and enum(enum is implemented as classes) or pointers
73
What is perl uses?
UNIX system text file processing, CGI programming. UNIX general system administration
74
What is PHP often used for?
Form processing + database access via the web
75
What is JavaScript used for?
Dynamic HTML documents
76
What was the 1st Japanese language to be widely used in US and what did it replace?
Ruby Perl and Python
77
What is imperative language design based on?
von Neumann architecture with efficiency as primary concern
78
What is functional language design based on?
Mathematical functions
79
What are functional side effects?
When a function changes a parameter or a global variable
80
What is the problem with functional side effects?
Unpredictable, Concurrency issues
81
How to solve functional side effects?
1) No 2 way parameters, No non-local references in functions. but it is very inflexible 2) Demand fixed operand evaluation order. limits some complier optimizations
82
When does a program have referential transparency?
Any 2 expressions that are equivalent can be substituted for one another and it doesn't affect the action. There are no functional side effects
83
What is the advantage of referential transparency?
semantics are easier to understand
84
Are Pure Functional Languages referentially transparent? and why?
Yes. No global variables. parameter values are constants. functions cannot have state, value of function depends only on parameters
85
What is the objective of functional language designs?
mimic math functions as closely as possible
86
What are the LISP Data Objects and Structures?
Only consists of atoms and lists 2 types of atoms (symbols and numeric literals) List = sequence of atoms or sublists
87
What does Scheme and Lisp have in common?
They use the same atoms and lists
88
What is Scheme interpreter interactive mode?
Mode that allows you to type code in line by line rahter than programming in an editor
89
Scheme interpreter is just a Scheme function?
Yes
90
How are functions evaluated?
Parameters (in no order) values of parameters substituted into the function body Value of last expression evaluated in the body is the value that the function defines
91
What are the Primitive Numeric Functions
+,-,*,/,abs,sqrt,remainder,min,max
92
Which primitive numeric functions cannot accept multiple parameters?
abs,sqrt,remainder
93
What are lambda functions used for?
Nameless functions
94
how many parameters can lambda functions have?
any number of parameters
95
how do you bind names to lambda expressions?
(define (square x) (* x x))
96
how do you bind a name to the value of an expression
(define pi 3.142) or (define two_pi (* 2 pi))
97
Hoe is the evaluation process for defined different?
Since the 1st parameter is a name and not a parameter it is not evaluated (otherwise it would be evaluated as undefined)
98
How do you output a expression in Scheme?
(display expression)
99
what is used for true and false in scheme?
#t and #f (or () for false)
100
What are the predicate values for numbers with multiple parameters?
=, <>, > ,<, >= and <=
101
Predefined predicate functions for numbers, single value test.
even?,odd?,zero?,negative?,positive?
102
what does <> mean?
not equals
103
how does a if function look like?
(if predicate then_exp else_exp) example (define (divide number denom) (if (<> denom 0) (/ number denom) // returns this if true 0 // returns this if false ) )
104
what is the cond function?
conditional control flow function
105
how does the cond function work?
"Accepts" the 1st expression that evaluates to true. if no expression is true it goes to the else expression if there is one
106
how is repetition handled?
through recursion
107
how is a list created?
'(A B) or (quote (A B))
108
how does "list" work in scheme?
(list 'A 'B 'C) yields (A B C) (list 'A 'B '(C D)) yields (A B (C D ))
109
How do you get the 1st element of a list?
(car list)
110
how do you get the remainder of a list after its 1st element has been removed?
(cdr list)
111
what does cons do?
outs the 1st oarameter into the 2nd parameter (a list) to make a new parameter
112
examples of cons
(cons 'A '(B C)) = (A B C) (cons '(A B) '(C D)) = ((A B) C D) (cons '() '(A B)) = (() A B) (cons 'A 'B) = (A . B) (cons '(A B) 'C) = (( A B) .C)
113
How many parameters does list? take?
1
114
What does the null? predicate function do?
Checks if the list is empty ( (()) is not an empty list)
115
what does eqv? do?
checks if 2 values are the same. Doesnt work for lists but does work for (eqv? 'A 'A)
116
what does eq? check?
if the 2 parameters are the same object in memory (for 2 list parameters or numeric atoms the result is not reliable)
117
What is the general form of let?
(let ((name1 exp1)(name2 exp2))body that uses the names in the bindings)
118
what does the let construct yield?
the value of the last application
119
What does the member function do?
Checks if an atom is in a simple list
120
With which function do you check if 2 lists are equal?
equalsimp
121
how is equal different from equalsimp?
equalsimp = atoms, equal = atoms + lists
122
What does (append lis1 lis2) yield?
all elements of list 1 followed by all elements of list 2
123
When is a recursive function tail recursive?
When the recursive call is the last operation in the function
124
What does mapcar do?
"Does" the function to everything in the list (define (add-two number) (+ number 2)) (mapcar add-two '(1 3 5 7)) results in (2 5 7 9)
125
What is a function that builds code
A function that can build code that can be executed
126
What is LISP used for?
AI
127
What is scheme used for?
To teach intro to programming
128
Other name for Logic programming languages
Declarative Programming languages
129
How are logic programs expressed?
Form of symbolic logic
130
Is it declarative or procedural?
Declarative: Only specify the form of results
131
What is a proposition?
Logical statement that can be true or false
132
What does a proposition consist of?
1+ objects and Relationships among objects
133
What are the 3 basic needs of formal logic?
Express propositions Express relationships between propositions Describe how new propositions can be inferred from other propositions
134
What is 1st order predicate calculus.
Form of symbolic logic that is used for logic programming
135
Object representation in predicate calculus
Represent objects in propositions.
136
What is a constant in predicate calculus?
A symbol that represents a particular object
137
What is a variable in predicate calculus?
A symbol that can represent different objects at different times
138
Is variables in imperative languages the same as in predicate calculus?
No
139
What are the 2 types of propositions?
Atomic propositions Compound propositions
140
How does atomic propositions differ from compound propositions?
Compound propositions represent mathematical relations (written like mathematical functions) Atomic propositions are represented by compound terms
141
What are the 2 parts of a compound term?
Functor (function symbol that names the relation) Ordered list of parameters (tuples)
142
Example of a compound term:
student(jon) like(seth, osx)
143
What are the 2 forms of propositions?
Fact: (assumed to be true) Query: Truth of a proposition is to be determined
144
Example of fact and query
Fact = Jon is a student Query = Can you prove that Jon is a student?
145
What are compound propositions?
2+ atomic propositions where atomic propositions are connected by operators
146
What are the 5 logical Operators?
negation conjunction disjunction equivalence implication
147
How many logical operators are there?
5
148
What are the quantifiers and and what do they mean?
Universal (upside down A) AX.P -> For all X, P is True Existential (Backwards E) EX.P -> There exists a value of X such that P is true
149
How do we infer facts from known propositions?
Using resolution since resolution is an inference principle
150
What does the unification process do?
Finds values for variables in propositions that allow the matching process to succeed
151
What is instantiation?
Assigning temporary values to variables to allow unification to succeed
152
What happens if matching fails when instantiating a variable?
You backtrack and instantiate the variable with a different value
153
Steps of Proof by Contradiction
Hypotheses (set of assumed propositions) Theorem (new proposition we want to infer) Goal (Negation of theorem stated as a proposition) Proof by contradiction (Theorem proved by finding an inconsistency with the goal)
154
What are Horn Clauses?
An "if-then" statement
155
What are the different types of Horn Clauses?
Headed (single atomic propositions on the left) Headless (Empty left side)
156
Headed Horn Clause example
Rich(X) ∨ WorksHard(X) ∧ OwnsBusiness(X) Rich(X) (Someone is rich) is true if WorksHard(X) (they work hard) and OwnsBusiness(X) (they own a business) are both true.
157
Headless Horn Clause
father(bob, jake) bob is the father of jake
158
What type of clauses are 1) Facts 2) Queries 3) Rules
1+2) Headless 3) Headed
159
Which is simpler, Logic programming semantics or imperative language semantics?
Logic programming
160
Overview of logic programming
Programs only state the form of the result (not how its computed) Uses predicate calculus (descriptive
161
Difference between imperative and logic using a "Sort the list" example
imperative = Describe Alg. to sort the list. Computer executes the steps of the Alg Logic = describe the characteristics of a sorted list
162
Why was prolog designed?
For natural language processing
163
When was prolog designed?
1970s
164
A constant, variable or structure describes what in prolog?
A term
165
What is a constant in prolog?
An atom on int
166
What do atoms consist of in Prolog?
string of letters, digits and underscores starting with a lowercase letter
167
What do variables consist of in Prolog?
String of letters, digits and underscores starting with a uppercase letter
168
What are the kind of statements in prolog?
Fact, Rule and Goal statements
169
Example of a fact statement:
male(bill)
170
Example of a specific rule statement:
(right side = if part, left = then part) ancestor(mary, shelly) :- mother(mary, shelly).
171
Example of a general rule
parent(X,Y) :- mother(X,Y). X is parent of Y if X is mother of Y or sibling(X,Y) :- mother (M,X), mother, (M,Y), father(F,X), father(F,Y).
172
Example of a goal statement (the statement that you want to prove)
?- man(fred)
173
What are the different inferencing approaches in prolog?
Bottom-up/"forward chaining" = begin with facts and rules. attempt to find sequence of matches that leads to goal (building toward goal) Top-down/backward chaining = begin with goal, attempt to find sequence of matches that leads to facts (break down)
174
What is used when there are multiple sub goals in prolog?
Breadth-first search and DFS
175
What is the problem with backtracking?
Can take lots of time and space
176
What does the tracing model do in prolog?
Display variable instantiations at each step
177
What are the 4 events of the tracing model?
Call (beginning of attempt to satisfy goal) Exit (When a goal has been satisfied) Redo (when backtracking occurs) Fail (when goal fails)
178
What does the "is" operator do in prolog?
Assigns variable a value A is B/17 + C
179
What is the difference between the LHS and RHS of the "is" operator in prolog?
RHS must be instantiated LFS must NOT be instantiated
180
Is Sum is Sum + number legal in prolog?
No. 1) it is not an assignment statement 2) LHS and RHS cannot be both instantiated and not instantiated
181
Simple Arithmetic Example in Prolog
distance(X,Y) :- speed(X,Speed),time(X,Time), Y is Speed * Time.
182
What are the different types of list structures in Prolog?
Simple list: [apple, prune] Complex list: [[a,b],son(x,bob)] Empty list: [] List with head x and tail y: [X|Y]
183
What is "_" in prolog?
An anonymous variable (is used to "ignore" something like the head of a list for example)
184
What does the "member" proposition do in prolog?
Checks if X is a member of Y (member(X,Y)) It is also built in "function"
185
What does append do in prolog?
Appends X to Y and makes list Z append(X,Y,Z)
186
What does the reverse proposition do in Prolog?
Reverses the list X and stores it in Y reverse(X, Y)
187
What are the deficiencies of Prolog?
Resolution order control Closed-world assumption The negation problem Intrinsic limitations
188
Why is resolution order control a deficiency of Prolog?
It has a unpredictable execution. (the order of execution isnt constant so it might take unexpected routes to the goal) Programmer can affect efficiency by placing more likely success rules higher up in program
189
Why is the negation problem a deficiency of Prolog?
It relies on Horn Clauses. If info is missing the closed-world assumption cant determine truth or falsehood. Which can lead to incomplete negation
190
How is a cut denoted in prolog and what does it do?
Denoted by ! and subgoals to the left of the cut cannot be re-satisfied through backtracking
191
What is the problem with closed world assumptions?
If the program answers false it isnt necessarily false but could also maybe just not be proven
192
What is the problem with intrinsic limitations?
Some tasks are impossible to specify efficiently
193
What are some applications of Logic Programming?
RDMS Expert systems Natural language processing
194
What are variables an abstraction of?
Memory cells that are characterized by attributes
195
What are some common problems with Names/identifiers?
What form can names take and are there special words reserved (keywords)
196
What are the aspects of a name?
Length use of special characters Case sensitivity
197
What is the problem when names are too short?
They cannot be connotative
198
How does Fortran, C99, C++, C#, Ada and Java handle name length?
Fortran = 6 in F1, 31 in F95 and 63 in F 2003 C99 = No limit but only 1st 63 are significant, external names are limited to a max of 31 C++ = No limit but implementers often impose one C# + ADA + Java = No limit and all are significant
199
Special Characters in PHP, Perl and Ruby
PHP = All variable names need to start with $ Perl = Scalars use $ arrays use @ and hashes use a % Ruby = Instance variable names begin with @, Class variables names begin with @@
200
What is the disadvantages Of case sensitivity?
Decreased readability and write-ability
201
Why are there special words?
To aid in readability by naming actions
202
Can reserved words be user-defined?
Nope
203
What is the problem with an excess in special words?
Name collisions are more likely to occur (COBOL has 300 reserved words)
204
What are the 6 attributes of a variable?
Name Address Value Type Lifetime Scope
205
All variables have names? T/F
F
206
Can there be different addresses at different execution times for variables?
Yes
207
What is a alias?
When 2 variables can be used to access the same memory locations (pointers, references, and unions)
208
Are aliases good for readibility or bad?
Bad (readers must remember all of them)
209
What is the Value of a variable
Stores the content of a memory location is associated with
210
What is the l-value of a variable?
The address (l-value = location value)
211
What is the r-value?
Value of a variable (real value)
212
What does the type define for variables?
How a value is stored in memory
213
What are the possible binding times?
Language design time(binding operators symbols to operations) Language implementation time (binding floating point type to a representation) Compile time(Binding variable to type in C or Java) Load time (Binding C++ local static to memory cell) Runtime (binding nonstatic local variable to a memory cell)
214
Whats the difference between static binding and Dynamic binding?
Static = occurs before run time Dynamic = during execution
215
What is type binding and what are the issues?
Binding of a variable to a type How is a type specified and when does the binding take place
216
What is explicit declaration?
statement used to declare types of variables. (int var )
217
What is implicit declaration?
A default mechanism for specifying variable types. Used in BASIC, Perl,Ruby, JS, PHP
218
What is the Advantage and Disadvantage of Static type binding?
Adv: Writability DisAdv : typographic errors cant be picked up by compiler
219
What is type inferencing?
Determining the types of variables form context (C#, Visual B 9.0+, Haskell, ML, F#)
220
What is the advantage + disAdv of dynamic type binding?
Adv: Flexibility DisAdv: Cost + type error detection by compiler/interpreter is difficult (JS,Python,ruby,PHP,C# (limited))
221
What are the 3 stages of Storage bindings and lifetime?
Allocation, Deallocation, and lifetime of a variable
222
What are the different categories of Variables by Lifetime?
Static Stack-dynamic Explicit heap-dynamic Implicit heap-Dynamic
223
What is Stack-dynamic variables?
Storage bindings created for variables when their declaration statements are elaborated
224
Adv + DisAdv of Stack-dynamic variables
Adv: Allows recursion + conserves storage DISAsv: Overhead of allocation + deallocation Subprograms cannot be history sensitive inefficient references
225
How is Explicit heap-dynamic variables allocated?
By explicit directives, specified by the programmer, which takes effect during execution (The variables are nameless) (int * p = new int(12))
226
If Explicit heap-dynamic variables are nameless how are they referenced?
Through separate pointers or references
227
Adv + DisAdv of explicit heap-dynamic variables?
Adv: Custom dynamic storage management DisAdv: unreliable (difficult to use correctly) inefficient Difficult to implement
228
How is Implicit heap-dynamic variables allocated?
Assignment (all strings and arrays in JS, PHP and Perl)
229
Adv + DisAdv of Implicit heal-dynamic variables?
Adv: Flexible DisAdv: Inefficient (most attribute binding is dynamic) Loss of error detection
230
What is the scope of a variable?
The range of statements over which it is visible
231
What are the scope rules of a language?
The definition of how name references are associated with variables
232
What are the approaches to scoping rules?
Static scope Dynamic scope
233
How does static scope work?
It is based on program text to connect name reference to a variable (compiler + reader must find the declaration)
234
How do you find the declaration in a static scope?
Start at program local unit and continue search in increasingly larger enclosing scopes . Stop when found void f(){ int i = 10; // declaration for(...){ if(){i++; // local program unit} } }
235
What are enclosing static scopes called?
Static ancestors(nearest static ancestor is called a static parent)
236
In what languages are variable hiding in blocks?
C and C++
237
What are the 2 parts of a let construct?
Part that binds names to values 2nd part uses the names defined in the first part
238
What is the Declaration Order of C99,C++ and Java and C#?
C99,C++,Java C# = variable declarations can appear anywhere a statement can C99 C++ and Java = Scope of local variables is from declaration to end of block C++ Java and C# = Loop control variables can be declared in for loop header and scope restricted
239
what is the variable scope in C#
The whole block that the variable appears in
240
in which languages is this allowed? {{int x} int x}
C99, C++, and Java but not C#
241
What is the scope of variables in PHP?
The scope is from the declaration to end of program.
242
How can global variables be accessed in PHP?
Through the $GLOBALS array and declaring it "global" in the function
243
When can a global variable be assigned to in a function
When the variable is declared as global in the function
244
What is the advantages and DisAdv of static scoping?
Adv: Works well in many situations DisAdv: too much access is possible. local variables tend to gravitate towards becoming global. Subprograms also gravitate toward becoming global rather than nested
245
What is Dynamic Scope based on?
The calling sequence of program units (not text layout like global scope) To connect a variable reference to a declaration: Search through chain of subprogram calls that brought execution to the variable reference
246
Advantage and DisAdv of Dynamic scoping:
Adv: Convenience DisAdv: When a subprogram is executing, its variables are visible to all subprograms it calls. impossible to statically type check. Access to non-local variables is slower
247
What is the referencing environment of a statement
The collection of all names that are visible in the statement
248
When a language uses a static scope what variables are visible?
Local variables + all the visible variables in all of the active subprograms
249
When a language uses a dynamic scope what variables are visible?
static scope + active subprograms have started execution and have not yet terminated
250
How many times is a name bound to a value for names constants?
Only once
251
What is the Adv of Named constants
Readability and reliability
252
How is named constant bound statically vs dynamically?
Static : const int SIZE = 10 + 5 Dynamic: const int SIZE Size = a + 1
253
What are the 2 kind of named constant in C#
const <- static readonly <- dynamic
254
What does a data type define?
Collection of data objects with a range of value and how they are stored in memory.
255
What does an object represent?
The instance of a programmer-defined type
256
What is another name for a programmer-defined type?
Abstract data type
257
Do all languages provide primitive data type?
Almost all of them
258
What is special about Integers?
It is an exact reflection of the hardware therefore mapping is trivial
259
How many different integer types are there?
May be as many as eight
260
What are the advantages of unsigned integers?
It cant go below 0. So you can store a lot more data into the field
261
Do Floating points model real numbers?
Yes but only as approximations
262
What are the 2 floating point types?
float and double
263
What is the standard for floating points?
IEEE Floating-Point Standard 754
264
How many bits does double and float use?
double = 64 bits float = 32 bits for both 1 bit = signed bit
265
in complex data types, what makes up each value?
a real part and an imaginary part (7 + 3j where 7 = real and 3 = imaginary
266
Whats the advantages and DisAdv of decimals
Adv : accuracy DisAdv : waste memory and limited range
267
Why is an advantage of boolean values readability?
Simplicity and clear representation
268
How is the primitive data type character stored?
numeric codings with most common being ASCII
269
What are the different types of character encodings of primitive data types?
ASCII, UCS-2 (16 bit),32-bit Unicode(UCS-4)
270
How are lists represented and what do they hold?
ordered sequence of (often) heterogeneous values Typically represented as a linked list
271
How does lists look like in F#?
[1;2;3]
272
What does F# list functions have in common with Scheme?
List.head [1;2;3] is equal to car (only returns the 1st element = 1) List.tail [1;2;3] is equal to cdr in scheme (returns the rest of the list besides the head = [2;3]
273
Are Python lists mutable and what does it mean?
Yes. allows [3, 5.8 ,"grape"]
274
How do you delete list elements in Python?
del myList[1]
275
How does list comprehensions look like in Python?
list = [x ** 2 for x in range(12) if x % 3 == 0]
276
Where is Type theory studied in?
Math, Logic, CS, Philosophy
277
What is a union?
A type whose variables can store values of different types at different times during execution
278
How many values can be assigned to a union at once?
1
279
What are union types used for?
Representing Values with Multiple Possibilities
280
What is the difference between Discriminated vs Free Unions
Disc = type checking, higher type safety, runtime errors less likely, clearer readability. free = no type checking, lower type safety, runtime errors more likely, less clear readability
281
union example in C
union flexType{ int intEl; float floatEl; }; union flexType u1; u1.intEl = 12; u1.floatEl = 22.8; float x = u1.floatEl; int y = u1.intEl;
282
Example of Discriminant
type Shape is (Circle, Triangle, Rectangle); type Colors is (Red, Green, Blue); type Figure (Form: Shape) is record Filled: Boolean; Color: Colors; case Form is when Circle => Diameter: Float; when Triangle => Leftside, Rightside: Integer; Angle: Float; when Rectangle => Side1, Side2: Integer; end case; end record; "Form" is the discriminant
283
Why are free unions unsafe?
They do not allow type checking
284
Are Ada's discrimination unions safe?
Yes
285
What are pointer type variables?
memory addresses that reference a memory (nil/null = doesnt refer to a memory cell)
286
What are the 2 uses of pointers?
power of indirect addressing manage dynamic memory
287
What is the scope and lifetime of a pointer?
Scope = if declared inside function == only accessible in that function. if declared globally == anywhere lifetime = until memory location it is pointing to isnt valid anymore
288
What is the lifetime of a heap-dynamic variable?
Until the user deletes it, otherwise it will result in memory leaks declared using "new" in c++
289
Are pointers restricted as to the type of value to which they can point?
Yes. For type safety and memory management
290
Are pointers used for dynamic storage management, indirect addressing, or both?
Both
291
Should the language support pointer types, reference types, or both?
Depends. If type safety needed = reference types
292
What are the 2 fundamental operations for pointers?
Assignment and dereferencing int *p = &val; j = *ptr <- deref
293
What is the problem with pointers?
Dangling pointers (seg-faults/memory corruption) Lost heap-dynamic variable (allocated heap-dynamic variable that is no longer accessible = memory leaks)
294
What are reference type?
Similar to pointers but no pointer arithmetic allowed
295
Is reference types or pointers safer?
Reference types
296
What is the main purpose of reference types?
For parameters void f(int &p){...}
297
How does Java extend C++ reference variables?
Allows them to replace pointers entirely references can refer only to object and not primitives
298
What need to be done on pointers if they are used for dynamic storage management?
manual heap management is necessary
299
Why cant pointers and references not be avoided?
need them for dynamic data structures
300
What is type checking?
ensuring operands of an operator are of compatible types
301
What is a compatible type?
Type that is either legal for the operator or is allowed under language rules to be converted by compiler
302
What is a type error?
Application of operator to an operand of inappropriate type
303
If all type bindings are static can nearly all type checking be static and why?
Yes. It tells the compiler the types upfront
304
What is the Adv of a strongly typed language?
Detects all variable misuses causing type errors
305
Out of the following languages which are strongly typed? C C++ Java C# ML and F#?
Java C# ML and F# with ML and F# being very strongly typed
306
What are coercion and what does it do to typing
converts operands to same type and it causes type weakening since it can cause accidental type mismatches go undetected
307
Which languages use coercions?
C++ Ada and Java
308
What is type equivalence?
It defines when operands of 2 types can be substitutable with no coercion
309
When are 2 variable name type equivalent?
Same declaration or declarations that use the same type name
310
When are 2 variable structure type equivalent?
If their types have identical structures
311
What are the 2 branches of type theory?
Practical (data types in commercial languages) Abstract (typed lambda calculus and of interest only to theoretical computer scientists)
312
What is a type system?
A set of types and rules that govern type use in programs
313
What are expressions?
Fundamental means of specifying computations in a programming language
314
What is needed to understand expression evaluation?
The orders of operator and operand evaluation
315
What do arithmetic expressions consist of?
Operators Operands Parentheses Function calls
316
What are some design issues with Arithmetic expressions?
Operator precedence rules Operator associativity rules Order of operand evaluation Are operand evaluation side effects restricted Is user-defined operator overloading allowed? What type mixing is allowed
317
How many operators does a Unary/Binary/Ternary operand have?
Unary = 1 Binary = 2 Ternary = 3
318
Typical precedence levels of a language
Parentheses. Unary operators. ** or ^. * and /. + and -
319
Operator associativity rules
Define order in which adjacent operators with the same precedence level are evaluated
320
Typical associativity rules
Left to right (** = right to left)
321
How are operators implemented in Ruby?
As methods (Arith, relational, assignment)
322
Can you overwrite operators in Ruby?
Yes because they are methods
323
Scheme and Common LISP arithmetic and logic operations are implemented as?
Explicitly called subprograms
324
Operand Evaluation Order
Variables, Constants, Parenthesized expressions
325
Problematic operator overloading
& in C and C++. Loss of readability and loss of compiler error detection
326
Can user-defined overloaded operators increase readability?
Yes but only when sensibly used (+)
327
What is narrowing conversions in Type Conversions
Converts an object to a type that cannot include all of the values of the origin type (float to int)
328
What is widening conversion in Type Conversions
Converts an object to a type including at least approximations of all the original type's values. May lose accuracy (int to float)
329
What is Mixed-mode expression?
Expression that has operands of different types. ( a is int, b is float. a + b = mixed mode)
330
What is Coercion in Type Conversions?
The auto type conversion of operands. Decreases compiler's type error detection ability.
331
What is explicit type conversion?
Programmer-specified type conversions. Can be either narrowing or widening? Compiler may give warnings. ( (int) in C languages)
332
What causes errors in expressions with type conversions?
Type checking and coercion. Limitations of arithmetic, Inherent and computer. Run time errors can be ignored but may require exception handling mechanisms
333
What do relational expressions evaluate to?
Booleans
334
What does short circuit evaluation do?
Doesnt evaluate all operands and operators (13*a)*(b) if a = 0 b isnt evaluated
335
When can short circuit evaluation be a problem?
When there are side effects in expressions.
336
What is the problem with = overloading
There is ambiguity between assignment and equality
337
What are conditional targets?
Similar to conditional expressions ($flag ? $total : $subtotal
338
How does a compound assignment operator look like?
A += B
339
Can assignments also be mixed-mode?
Yes
340
What is a control structure?
A control statement and the statements whose execution are controlled
341
What is the most important design question for control structures?
Should a control structure have multiple entries
342
What does a selection statement provide?
A choice between 2+ execution paths
343
What are the 2 categories for selection statements?
2 way selectors and Multiple way selectors.
344
What is the general form of a 2 way selection statements
if then else
345
How are compound statements usually delimited as?
Square braces
346
Are statement sequences contained in blocks?
No.
347
To disambiguate nested selectors:
Match else with nearest if. Force semantics ({})
348
What are the design issues with multiple way selectors?
What is the control expression's form and type. How are selectable segments specified. Is execution in structure only a single selection How are case values specified How are unrepresented expression values handled (switch case in c c++ Java and JS)
349
Can a if statement be a multiple way selector?
Yes. if elif elif elif ...
350
What are the 2 types of iterative statements?
Iteration Recursion
351
What are the design issues for iterative statements?
How are the iterations controlled Where is the control mechanism in the loop
352
What do Counting iterative statement have?
Loop variable. variables intial, terminal and stepsize values
353
What is the design issues for counter controlled loops design issues?
Type + scope of loop variable Can loop variable be changed in loop body. Should the loop parameters be evaluated only once? What is the loop variable after the loop
354
What is logically controlled loops?
Repetition control using Boolean expressions
355
Which is more general? Counter or logical loops
Logical
356
What are the design issues with logically controlled loops?
Should the control be pretest or posttest. Should the loop be a special case of a count loop?
357
What are user located loop control mechanisms?
Something like "break"
358
What are iteration controlled data structures?
Iterations are controlled by number of elements in a data structure.
359
How are iteration based structures controlled?
By a iterator
360
What is unconditional branching?
Transferring control to specific place in program
361
What are guarded comments?
If the order of evaluation is not important the program should not specify an order
362
What is the form of a guarded loop?
do bool1->statment1 [] bool2 -> statment2 [] ... od
363
What are the 2 types of abstraction?
Process abstraction Data abstraction
364
What are the fundamentals of subprograms?
Single point of entry If subprogram is called, calling program is suspended After execution control is returned to the caller
365
Basic definition for subprograms
Defines interface and action Interface specifies how the subprogram is used + name + parameters +... Actions: Specify hat it does (body)
366
What is a subprogram header?
The 1st part of the subprogram definition. Name kind parameters
367
What is the difference between formal parameters and actual parameters?
Formal: Dummy variable in header. Used in subprogram Actual: Values being passed in
368
What is a parameter profile(signature)?
Number, order and types of parameters
369
What is a protocol?
Parameter profile with function return types
370
What is a subprogram declaration?
Provides subprogram protocol, but not its body (prototype (void doSomething(int);)
371
What is the Parameter correspondence?
for a subprogram call we must match actual parameters to formal parameters.
372
What is the advantage of Positional parameters?
1st parameter = 1st parameter etc... It is safe and effective
373
What is the disadvantage of Positional parameters?
reduced readability + error prone
374
What is the advantage + disadv of Keyword parameters?
Adv: Avoid corespondence errors. can appear in any order (improved readability) Dis: Memorize param names
375
Can formal parameters have default values?
Yes
376
How are variable number of parameters processed?
Like a list
377
What are the 2 categories of subprograms?
Procedures (collections of statements that define parameterized computations) Functions (resemble procedures but semantically modeled on mathematical functions)
378
How does Procedures and functions differ?
Procedures: produce result by modifying Functions: produce results by returning a value
379
What is the adv and disadv of stack-dynamic variables?
adv: recursion + shared among subprograms dis: time for allocation, initialization
380
What is the advantage of static local variables?
Opposite of stack-dynamic local variables
381
What are the 3 modes for parameters?
In mode formal parameter: received data from an actual parameter Out mode: Sends data to an actual parameter Inout mode: Both
382
What are the 2 ways data transfer can take place?
Physical copy of a value Transmit access path to value
383
What are the 5 implementation models for parameter passing?
pass-by-value pass by result pass by value result pass by reference pass by name
384
What mode is pass by value?
In mode
385
How does pass by value work?
The value of the actual parameter is used in formal parameter Normally implemented by copying can be done by transmitting an access path
386
What mode is pass by result and how does it work?
Out mode Value of formal parameter is used to change corresponding actual parameter
387
What mode is pass by value result and how does it work
inout mode Formal params have local storage
388
How does pass by reference work and what mode is it?
Passes an access path (implemented using a reference or pointer) Inout Mode
389
What mode is pass by name and how does it work?
Uses textual substitution All formal parameter occurrences are replaced by the appropriate actual parameter
390
What is parameter type checking?
Testing if the actual & formal parameter types match (important for reliability)
391
What must happen if multidimensional arrays are passe as parameters?
Compiler must map array subscript references to values Mapping function must know size of all dimensions
392
What are some design considerations for parameter passing?
Efficiency 1 way or 2 way data transfer
393
How are c# method pointers declared?
deleates key word
394
What are the 3 binding options?
Shallow binding ("Normal") Deep binding ( static scope) Ad-hoc binding
395
What is a overloaded subprogram?
Same as overloaded function
396
What are the 2 types of subprograms?
Generic (template) Polymorphic (Take different parameter types in different calls)
397
What is ad hoc polymorphism?
Overloaded subprograms
398
When are subprogram versions created?
At compile time
399
How is a wildcard represented and what does it mean in C++?
? it means any object
400
How are side effects reduced?
Parameters should ideally be in mode.
401
What is a closure?
An Anonymous function (function without name)
402
What is a coroutine?
A subprogram with multiple entry points.
403
What is a symmetric control
When the caller and called coroutines exist on a more equal basis.
404
What is a coroutine call named?
A resume
405
What is quasi-concurrent execution?
When a coroutine interleaves their execution but it doesnt overlap
406
What is abstraction?
A view of an entity that includes only most significant attributes
407
How is process abstraction created?
By means of subprograms
408
When did all languages start to support data abstraction?
Since 1980
409
What are the 2 abstract data type conditions that is being satisfied?
Representation of object are defined in a single syntactic unit. Representation of objects of the type is hidden from the program units that use these objects
410
What is the Adv of representing objects in a single syntactic unit?
organization, modifiability, Each ADT can be compiled separately in own file.
411
What are language requirements for ADTs?
Syntactic unit. A method to make essential parts of an ADT visible to client
412
ADT example
struct
413
What are parameterized ADTs also known as?
Generic classes
414
What can ADTs store?
elements of any type
415
What must any OOP language support?
ADT Inheritance Polymorphism
416
Why is Inheritance needed?
Can increase productivity (reuse)
417
What are some OO concepts?
ADT (classes) class instances (objects) class that inherits (derived/subclass) parent class subprograms defining operations on objects (methods) Calls to methods (messages) collection of an object's methods (message protocol/interface) 2 parts in message (method name, dest object)
418
What are the 2 kinds of variables in a class?
Class variables (one per class) Instance variables (one per object) same for methods
419
What is Dynamic binding?
Polymorphic reference (pointer)
420
When everything is an object what are the advantages and disadv?
Adv: elegance Disadv: slow
421
When you add objects to a complete typing system what happens?
Speed up simple operations Results in confusing type system
422
When using an imperative typing system for primitives and make everything else object what happens?
Simple operations can be fast but typing system remains small but 2 type systems has to mix
423
What does dynamic binding look like in C++?
virtual key word, interface in java