What are the differences between methods, functions, and procedures?
Instructor solution
Functions take inputs and return some outputs. Strictly speaking, functions (as in math) should not have any effects (e.g. mutation).
Procedures are functions that might have an effect.
(In class, I am not super strict about my use of 'function' vs. 'procedure'.)
Methods are procedures that are part of a class so have access to this
and super
. Every method is a procedure but not every procedure is a method.
Think you've got it?
What do we gain in our evaluator by only returning the value of the last evaluated expression?
- A.
It allows for our interpreter to ingest code that has intermediary steps making it easier to read
- B.
It allows for better error handling by being able to verify parameters
- C.
It simulates an OOP language where the return statement is the last statement in a method
- D.
It allows for methods to cause side effects such as modifying a field such as a counter
You may exit out of this review and return later without penalty.