Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
By domain
business languages, scientific languages, AI languages, systems languages, scripting languages, XML-based languages
By generality
general purpose vs. special purpose
By implementation methods
Nancy E. Reed nreed@hawaii.edu
Interpreted vs. compiled
By paradigm
a paradigm is a way of viewing programming, based on underlying theories of problem solving styles programming languages grouped in the same paradigm are similar in their approach to problem solving imperative, object-oriented, logic-based, functional, etc.
High-level languages
Algol, Pascal, C++, Java, C#, etc.
Declarative
functional logic, constraint-based (Scheme, ML, pure Lisp, FP) (Prolog, VisiCalc, RPG)
Originally C was considered high level but now many programmers might refer to C as low level, as it stills allows memory to be accessed by address, and provides direct access to the assembly level.
Abstraction Level
HighLevel vs. Low-Level Languages
Low-level languages Registers and memory addresses More time-consuming to write Can produce faster code write those in a lower-level language High-level languages Variables, arrays and complex arithmetic or Boolean expressions; Easier programming, smaller code
Assembly Language
Languages
thought
Closer to humans
The first digital computer was used and invented for scientific applications The first high level programming languages were developed to solve scientific (engineering) problems Large number of floating-point arithmetic computations built in Only simple data structures Compilers emphasized speed and efficiency Example languages: Fortran, Algol.
Classifying Languages by Domain: Business and Data Processing Require strong language support for
file manipulation table lookup report generation (text)
10
Minimal math, graphics, and recursion capabilities Example language: COBOL (COmmon
Business Oriented Language
High level of abstraction - closer to human thought Symbols names for concepts Symbol manipulation, rather than all numeric Lists more flexible than arrays Recursion used more than iteration Code = data, resulting in self-modifying code Example languages:
Lisp (LISt Processing), Scheme, ML, Miranda, etc. Prolog (French for logic programming), datalog,
11
12
1 13
14
15
16
Implementation - Compilation The compiler translates the high-level source program into an equivalent target program (typically in machine language), and then exits Advantages of compiled languages
Primarily speed of execution Compile once, execute repeatedly Usually requires less runtime space Optimization can increase speed
17
18
Implementation - Interpreters
Interpreter includes a run-time system that is active throughout the execution of the program Advantages of interpreted languages
Easy implementation of source-level debugging operations, run-time errors can refer to source-level units It can take less time to interpret it than the total time required to compile and run it. Good for prototyping and testing code when an editinterpret-debug cycle can often be much shorter than an edit-compile-run-debug cycle. (e.g. Perl, Lisp)
Hybrid Implementations
Some language implementations use both compilation and interpretation on source code! Not opposites, sometimes alternatives Some languages allow optional compilation source code can be either interpreted or compiled and executed together (e.g. Lisp) execution speeds up by a factor of 10 or more
Classifying Programming Languages by Paradigm A style of programming Provides the view that the programmer has of the execution of the program.
Object-oriented programming: programmers think of a program as a collection of interacting objects; Functional programming: a program can be thought of as a sequence of stateless function evaluations.
19
20
Many programming paradigms are as wellknown for what techniques they forbid as for what they enable.
Pure functional programming disallows the use of side-effects; Structured programming disallows the use of goto.
21
22
Functional:
what simple operations can be applied to solving a problem, how are they mutually related, and how can they be combined?
Object-oriented:
What objects play roles in a problem, what can they do, and how do they interact to solve the problem?
Scripting :
Use regular expressions
23
24
Imperative Languages
Central features are variables, assignment statements, and flow control Describes computation in terms of a program state and statements that modify it.
Is similar to the way that an imperative mood in natural languages expresses commands to take action. Imperative programs are a sequence of commands for the computer to perform.
Imperative Languages
Imperative language operations are themselves just abstractions of some sequence of lower-level machine instructions. The programmer specifies operations to be executed and specifies the order of execution to solve a problem. Programmer must describe in detail how a problem is to be solved (i.e., all of the steps involved in solving the problem) Most of the languages commonly used support an imperative paradigm. They include assembly, Fortran, Algol, Ada, Pascal, C, C++, etc., etc.
25
26
Unstructured Programming
All code is contained in a single continuous block. Rely on execution flow statements such as GOTO, used in many languages to jump to a specified section of code. Complex and tangled, difficult to read and debug; Unstructured programming results in spaghetti code Discouraged!!!!
Subprograms
Y S1 S2 S1 C N Y S2 S C N
27
28
Scripting Languages Both batch and interactive use Economy of expression Lack of declarations Simple scoping rules Flexible dynamic typing Easy access to other programs Sophisticated pattern matching and string manipulation High level data types
Object-Oriented Paradigm Encapsulate data and operations in objects Inheritance and dynamic type binding Grew out of imperative languages Program is composed of a collection of individual units, or objects, that act on each other,
Traditional (imperative) view: a program is a list of instructions to the computer.
29
30
Object-Oriented Languages
Objects as programming entities were first introduced in Simula 67, a language designed for making simulations. The Smalltalk language, which was developed at Xerox PARC, introduced the term Objectoriented programming to represent the pervasive use of objects and messages as the basis for the computation.
OO Problem Solving
A problem is solved by specifying objects involved in the problem
Objects in OO correspond roughly to real-world objects in the problem Objects are instances of classes (abstract data types) Classes are arranged in hierarchies, with subclasses inheriting properties of superclasses Operations (called methods) are defined specific to each class Problem solving is accomplished through message passing between objects (a message is a call to a method of a specific object)
31
32
Declarative Languages
A program is "declarative" if it describes what something is, rather than how to create it. Declarative programs make the goal explicit and leave the algorithm implicit.
Imperative programs make the algorithm explicit and leave the goal implicit;
Declarative Languages
Two major difference between imperative and declarative programming:
Assignment statement use; Order of statement execution.
Declarative means what not how Logic or rule-based Rules may be specified in no special order Inference procedure is part of the language Inferencing backwards or forwards Prolog
33
34
Functional Programming
A program consists of a set of function definitions Program execution consists of evaluating a toplevel function The language itself is the function evaluator; the evaluation mechanism is not visible to the programmer (major procedural abstraction!) No variables, no assignments
everything is a function can apply functions to functions as we have seen
35
36
Summary
Classify programming languages by: Abstraction level
Low level, high level, very high level
Questions
Application domain
Business languages, scientific languages, AI languages, systems languages, scripting languages,
Generality
General purpose vs. special purpose
Implementation methods
Interpreted, compiled, hybrid interpreted and compiled, interpreted or compiled
Paradigm
Imperative, declarative, object-oriented, logic-based, functional, scripting