Chapter 7 Flashcards
What do we need to know in order to understand expression evaluation?
The order of operator and operand evaluation
What was the biggest reason people wanted to develop programming languages?
Arithmetic evaluations
2 biggest questions when designing arithmetic expressions.
Operator precedence rules (order)
operator associativity rules (left-to-right or r-t-l)
How many operators does a unary, binary and ternary have?
1,2,3
How many precedence levels does APL have?
1 ( right to left)
How can you override precedence + associativity rules?
(In most languages) Parentheses
Problem with operators in Ruby?
Methods. Can overwrite the methods
What is the operand evaluation order?
Variables
Constants
Parenthesized expressions
Side effects?
What is the problem with operator overloading?
Decreased readability and writeability
Whats the difference between narrowing conversions and widening conversions with type conversions?
Narrowing = Cant include all original values ( float to int)
Widening = int to float
What is a mixed mode expression?
2 different type values are added together
A = int, B = float. A + B
What is Coercion?
Auto type conversion
What is bad about coercion?
Decrease in reliability
What kinds of errors can coercion create?
Run time errors, since it cant be checked beforehand
What does no coercion imply?
Extreme type safety
What type of conversion is casting in C?
Explicit type conversion
What does relational expressions do?
Evaluate to booleans
Equality for coercion and without coercion in Ruby
== for coercion ( == in JS )
elq? for no coercion ( === in JS)
What is short circuit evaluation?
Dont evaluate entire thing if 1st part fails
(13 * a) * ( b + c)
If a = 0 then dont evaluate the rest
What is the problem with non short-circuit evaluation?
Additional performance overhead
What is the problem with short-circuit evaluation?
If side effects are expected
What are conditional targets?
if statement but with “immediate” assignment.
(flag ? total : subtotal) = 0
(flag -> true = total = 0)
Possible problem with assignment statements?
If you overload it it can become ambiguous languages have == for relational
What is a compound assignment operator?
+=