Test 1 Flashcards
Why Study Theory of Programming Languages?
- Increased Capacity to express ideas
- Improved background for choosing languages that are appropriate
- Increased ability to learn about new languages
- Better understanding of implementation
- Better use of languages that are known
- Overall advancement of computing
What are the three Language Evaluation Criteria ?
Readability, Writability, Reliability
Readability
- How easy it is for others to read and follow development and work on it.
1. Simplicity:- # of language features to provide
- Minimal Feature Multiplicity
- Minimal Operator Loading/overloading (provides flexibility, if
used appropriately makes it easier to understand)
- Orthogonality:
- Every possible combination is meaningful combinations
- Exceptions: In c++ cant make function return array &
arrays are passed to functions by reference not value - The more orthogonal the design of a language, the fewer exceptions the
language rules require. - Too much orthogonality can lead to unnecessary complexity.
- Data Types:
- The presence of adequate facilities for defining data types and data structures
- Syntax Design:
- Effects readability -> special words & compound statements
- semantics depend on syntax **. ( statements’ appearance should indicate their purpose)
Writability
- Same as readability
- Abstraction:
- Procedure Abstraction (functions or simple procedures)
- Data Abstraction (Classes & Objects)
- Expressivity:
- How powerful & convenient to specify a computation
Reliability
- Features the program provides to make it more reliable
- All factors of Readability & Reliability
- Type Checking:
- happens at compile time or runtime
- Exception Handling:
- program deals with exceptions
- Aliasing:
- two or more distinct names used to access same memory cell
- VERY DANGEROUS
Cost
Three most important contributors to language costs:
1. Program Development 2. Maintenance 3. Reliability
Other Criteria used for Evaluation Programming Languages
- Portability:
- ease with which programs can be moved from one implementation to another
- Generality:
- applicability to a wide range of applications
- well-definedness:
- Completeness & precision of lang. definition
How are design criteria weighted differently from different perspectives?
- Language implementors:
->difficulty of
implementing the constructs and features of the language - Language Users:
- > writability first and readability later
-Language designers:
-> emphasize elegance and the ability
to attract widespread use.
What are the three Language design trade-offs?
- Reliability vs. Cost of Execution
- Readability vs. Writability
- Writability (flexibility) vs. Reliability
Reliability vs. Cost of Execution
Java demands all references to array elements be checked for proper
indexing, which leads to increased execution costs
Readability vs. Writability
APL provides many powerful operators (and a large number of new
symbols), allowing complex computations to be written in a compact program but
at the cost of poor readability
Writability vs. Reliability
C++ pointers are powerful and very flexible but are unreliable
What are the two Language Categories?
Declarative and Imperative Languages
Declarative Languages
Focus on WHAT the computer is to do
-Higher level
-In tune with the programmer’s point of
view
Imperative Languages
Focus on HOW the computer should do it
-Predominate
What are three types of Declarative Languages?
Functional:
- employ a computational model based
on the recursive definition of functions.
- FL, ML, Haskell
Dataflow:
- model computation as the flow of information (tokens)
Logic or Constraint-Based languages
- prolog - find values that satisfy certain specified relationships
What are the three types of imperative languages?
Von Neumann:
- statements (assignments in particular) that influence subsequent computation - most familiar and successful
Scripting:
- Subset of von neumann - distinguished by their emphasis on ”gluing together” components that were originally developed as independent programs
Object-oriented:
- closely related ^ - Have more structured and distributed model of memory and computation
What are the three general methods that programming languages can be implemented by?
- Compilation:
- Programs are translated into ML
- Use: large commercial applications
- Pure Interpretation:
- Programs interpreted by another program known as an interpreter
- Use: Small programs / efficiency is not an issue
- Hybrid Implementation Systems:
- A compromise between compilers and pure interpreters
- Use: Small & medium systems when efficiency is not a first concern
Compilation
- Translate high-level language to ML
- Slow translation, fast execution
- Phases:
- Lexical Analysis:
- characters to lexical units
- Syntax Analysis:
- lexical units to parse trees (syntactic
structure)
- lexical units to parse trees (syntactic
- Semantics Analysis:
- generate intermediate code
- Code Generation:
- machine code generated
- Lexical Analysis:
- Load Module:
- user and system code together
- Linking and Loading:
- Collect program units & link them to
user program
- Collect program units & link them to
von Neumann bottleneck
the primary limiting factor in computer speed
Pure Interpretation
- No translation
- Easier implementation (runtime errors immediately displayed)
- Slower execution
- Needs more space
- Rare for traditional high-level languages
- JavaScript, PHP
Hybrid Implementation Systems
- High level language –> intermediate language –> easy interpretation
- Faster than pure interpretation
-Perl programs –> partially compiled to
detect errors before interpretation