Chapter 7 Flashcards
What are expressions?
Fundamental means of specifying computations in a programming language
What is needed to understand expression evaluation?
The orders of operator and operand evaluation
What do arithmetic expressions consist of?
Operators
Operands
Parentheses
Function calls
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
How many operators does a Unary/Binary/Ternary operand have?
Unary = 1
Binary = 2
Ternary = 3
Typical precedence levels of a language
Parentheses. Unary operators. ** or ^. * and /. + and -
Operator associativity rules
Define order in which adjacent operators with the same precedence level are evaluated
Typical associativity rules
Left to right (** = right to left)
How are operators implemented in Ruby?
As methods
(Arith, relational, assignment)
Can you overwrite operators in Ruby?
Yes because they are methods
Scheme and Common LISP arithmetic and logic operations are implemented as?
Explicitly called subprograms
Operand Evaluation Order
Variables, Constants, Parenthesized expressions
Problematic operator overloading
& in C and C++. Loss of readability and loss of compiler error detection
Can user-defined overloaded operators increase readability?
Yes but only when sensibly used (+)
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)