CSC 533: Organization of Programming Languages
Spring 2007
Test 2 Review
TEST 1 MATERIAL
Object-Oriented Programming
abstract data type (ADT)
requires encapsulates of data & operatations + information hiding
object-based programming: program is a collection of interacting objects
natural approach to design, modular (allows for reuse)
object-oriented programming: OBP + inheritance + dynamic binding
can build new classes on top of existing classes
IS_A relationship enables generic functions (requires dynamic binding)
polymorphism: same name can refer to diff. code for diff. objects
OOP in Java: "pure" OO language
inheritance, public vs. private vs. protected, abstract classes
super can specify methods from parent
dynamic binding is automatic, implemented via method reference
no multiple inheritance, but can implement multiple interfaces
OOP in C++: hybrid language, combines procedural code with objects
inheritance, public vs. private vs. protected, abstract classes
scope resolution operator (::) can specify member functions from parent
static binding is default, but can specify dynamic binding via "virtual"
multiple inheritance allowed (use :: to disambiguate), no interfaces
Java vs. C++
C++ design goals
support OO, retain C performance, gentle path to OO
C++ language features: added OO to C + numerous reliability features
pass-by-reference, constants, new & delete, bool, string
memory management
by default, memory allocation is stack-dynamic
can allocate heap-dynamic using new & delete
no automatic garbage collection, destructors
separate compilation, templated classes & functions
Java design goals
simple, OO, network savvy, robust, secure, architecture neutral,
portable, interpreted, high-performance, multi-threaded, dynamic
Java language features: emphasize ease of programming more than efficiency
based on C++ syntax, but removed many confusing/redundant features
name resolution at link time, automatic garbage collection, ...
execution model: compile into byte code, then interpret with JVM
Java vs. JavaScript
JavaScript design goals
scripting language -> interpreted by browser, code embedded in HTML
applications are quick & dirty -> implicit, dynamic variables
applications are small -> useful objects provided, creation is crude
user security is important -> can't access client files, but open code
JavaScript language features
input/output, functions, numbers & expressions, control statements
dynamic images, buttons, text boxes, text areas
strings, arrays, special purpose functions, timeouts
Functional Programming
developed out of AI movement in mid-50's
symbolic, list-oriented, transparent memory mgmt, simple & orthogonal
Scheme developed at MIT, mid-70's: clean, simple subset of LISP
static scoping, first-class functions, efficient tail-recursion
syntax
S-expressions: atoms (numbers, characters, strings, booleans, symbols)
lists -- non-contiguous, dynamic, represented as dotted pair
functional expressions: S-expressions that represent function calls
primitive functions
arithmetic: +, -, *, /, quotient, remainder, max, min, abs, =, <, <=
symbolic: car, cdr, cons, list, list-ref, length, member, reverse, append
predicates: zero?, positive?, odd?, even?, number?, list?, null?, equal?
boolean: and, or, not
user-defined functions
create using define
control
to evaluate functional expr: evaluate each arg, apply function to values
conditionals: if-expression, cond-expression (both considered special forms)
repetition via recursion: Scheme must perform tail-recursion optimization