final Flashcards
(157 cards)
functional languages vs imperative languages
imperative:
- based directly on the von Neumann
architecture:
- Efficiency is the primary concern, rather than the suitability of the language for software development
functional:
- based on mathematical functions:
- A solid theoretical basis that is also closer to the user, but relatively unconcerned with the architecture of the machines on which programs will run
mathematical function
a mapping of members of one set, called the domain set, to another set, called the range set
Lambda expressions
*Lambda expressions describe nameless functions
*Lambda expressions are applied to parameter(s) by placing the parameter(s)
after the expression,
Function Composition
A functional form that takes two functions as parameters and yields a function
whose value is the first actual parameter function applied to the application of
the second:
Form: h =f∘g
which means: h(x) =f(g(x)
objective of the design of an FPL
mimic mathematical functions to the
greatest extent possible
basic process of computation in FPL vs imperative languages
§ imperative language: operations are done and the results are stored in variables for later use
§Management of variables is a constant concern and source of complexity for
imperative programming
* FPL: variables are not necessary, as is the case in mathematics, the evaluation of a function always produces the same result given the same parameters (referential transparency)
Tail recursive function in Scheme
- A function is tail recursive if its recursive call is the last operation in
the function - A tail recursive function can be automatically converted by a compiler to use iteration, making it faster
- Scheme language definition requires that Scheme language systems convert all tail recursive functions to use iteration
common lisp features
§records
§arrays
§complex numbers
§character strings
§powerful I/O capabilities
§packages with access control
§iterative control statements
Symbol Data Type
*Similar to that of Ruby
*The reserved words are symbols that evaluate to themselves
*Symbols are either bound or unbound:
§Parameter symbols are bound while the function is being evaluated
§Symbols that are the names of imperative style variables that have been assigned
values are bound
§All other symbols are unbound
ML
- static-scoped
- syntax that is closer to Pascal than to
Lisp - type declarations + type inferencing
- strongly typed and has no type coercions
- Does not have imperative-style variables
- identifiers are untyped
- exception handling and a module facility for implementing abstract data types
- lists and list operations
how is Haskell similar and different from ML?
*Similar to ML (syntax, static scoped, strongly typed, type inferencing, pattern
matching)
*Different from ML (and most other functional languages) in that it is purely
functional (e.g., no variables, no assignment statements, and no side effects of
any kind)
F#
- imperative features and supports
OOP - tuples, lists, discriminated unions, records, and both mutable and immutable arrays
Trends in imperative languages
Support for functional programming is increasingly creeping into imperative languages
Comparing Functional and Imperative Languages
*Imperative Languages:
§Efficient execution
§Complex semantics
§Complex syntax
§Concurrency is programmer designed
*Functional Languages:
§Simple semantics
§Simple syntax
§Less efficient execution
§Programs can automatically be made concurrent
abstraction
view or representation of an entity that includes only the most significant attributes
* fundamental in programming (and computer science)
*Nearly all programming languages support process abstraction with subprograms
*Nearly all programming languages designed since 1980 support data
abstraction
abstract data type (ADT)
a user-defined data type that satisfies the
following two conditions
1. the only operations possible are those provided in the type’s definition
2. declarations and the protocols of the operations on objects of the type are contained in a single syntactic unit
Advantages of Data Abstraction
*Advantages the first condition:
§Reliability: by hiding the data representations, user code cannot directly access objects of the type or depend on the representation, allowing the representation to
be changed without affecting user code
§Reduces the range of code and variables of which the programmer must be aware
§Name conflicts are less likely
*Advantages of the second condition:
§Provides a method of program organization
§Aids modifiability (everything associated with a data structure is together)
§Separate compilation
Language Requirements for ADTs
*A syntactic unit in which to encapsulate the type definition
*A method of making type names and subprogram headers visible to clients,
while hiding actual definitions
*Some primitive operations must be built into the language processor
Parameterized ADTs
Parameterized ADTs allow designing an ADT that can store any type elements:
only an issue for static typed languages
Encapsulation Constructs
a grouping of subprograms that are logically related into a unit that can be separately compiled (compilation units)
Nested Subprograms
*Organizing programs by nesting subprogram definitions inside the logically
larger subprograms that use them
*Nested subprograms are supported in Python, JavaScript, and Ruby
Object-Oriented Programming (OOP) Languages
*Some support procedural and data-oriented programming (e.g., C++)
*Some support functional program (e.g., CLOS)
*Newer languages do not support other paradigms but use their imperative
structures (e.g., Java and C#)
*Some are pure OOP language (e.g., Smalltalk & Ruby)
*Some functional languages support OOP, but they are not discussed in this chapter
Three major OOP language features:
§Abstract data types (Chapter 11)
§(Class) Inheritance:
o Inheritance is the central theme in OOP and languages that support it
§Polymorphism
Design Issues for OOP Languages
*The Exclusivity of Objects
*Are Subclasses Subtypes?
*Single and Multiple Inheritance
*Object Allocation and Deallocation
*Dynamic and Static Binding
*Nested Classes
*Initialization of Objects