Presentation is loading. Please wait.

Presentation is loading. Please wait.

CST2231_introduction1 Programming Languages A programming language is a language that is intended to be used by a person to express a process by which.

Similar presentations


Presentation on theme: "CST2231_introduction1 Programming Languages A programming language is a language that is intended to be used by a person to express a process by which."— Presentation transcript:

1 CST2231_introduction1 Programming Languages A programming language is a language that is intended to be used by a person to express a process by which a computer can solve a problem. ?? ? –Is a calculator a programming language? –Is a spreadsheet a programming language? –Is HTML a programming language?

2 CST2231_introduction2 Computational Theory Anything that could be computed could, in theory, be computed on a simple device, a Turing Machine. If our language can simulate a Turing Machine, then in theory, it can compute anything that ’ s computable. If so, we have a programming language. ???

3 CST2231_introduction3 Computational Theory Turing Tarpit Argument –“ Anything your language can do, my language can do as well, so there! ” All languages have exactly the same power. Why do we need more than one language then? This argument is a tarpit because it is deceptively simple, but gets you nowhere. Everything is possible, but nothing is easy.

4 CST2231_introduction4 A simpler definition A language is a Programming Language iff it has the power for expressing 3 fundamental constructs in the problem solving process: –Sequence (sequential execution of statements) –Conditional (if, switch/case) –Loops (while, for) A programming language is said to be “ Turing Complete ”.

5 CST2231_introduction5 Language and Thought Instead of theoretical computation power, we are concerned with ease of use. How easily is it to communicate what we want the computer to do in some language? Structure of a language defines the boundaries of thought. Most of what we express is expressed in language, and must suffer the constraints of the medium.

6 CST2231_introduction6 Language and Thought Languages predispose us to viewing the world in a certain way. The same thing is true in programming languages, to an even greater extent. Once someone has learned their first programming language, they tend to approach all problems from within that language.

7 CST2231_introduction7 Why study PLs? Improve problem-solving ability. Make better use of a language. Choose an appropriate language. Easier to learn a new language. Better language designers. Increased capacity to express ideas.

8 CST2231_introduction8 Programming Domains Scientific applications –Large numbers of floating point computations; use of arrays –Fortran Business applications –Produce reports, use decimal numbers and characters –COBOL Artificial intelligence –Symbols rather than numbers manipulated; use of linked lists –LISP Systems programming –Need efficiency because of continuous use –C Web Software –Eclectic collection of languages: markup (e.g., XHTML), scripting (e.g., PHP), general-purpose (e.g., Java)

9 CST2231_introduction9 Language Evaluation Criteria Readability: the ease with which programs can be read and understood Writability: the ease with which a language can be used to create programs Reliability: conformance to specifications (i.e., performs to its specifications) Cost: the ultimate total cost

10 CST2231_introduction10 Evaluation Criteria: Readability Overall simplicity –A manageable set of features and constructs –Minimal feature multiplicity –Minimal operator overloading Orthogonality –A relatively small set of primitive constructs can be combined in a relatively small number of ways –Every possible combination is legal Data types –Adequate predefined data types Syntax considerations –Identifier forms: flexible composition –Special words and methods of forming compound statements –Form and meaning: self-descriptive constructs, meaningful keywords

11 CST2231_introduction11 Evaluation Criteria: Writability Simplicity and orthogonality –Few constructs, a small number of primitives, a small set of rules for combining them Support for abstraction –The ability to define and use complex structures or operations in ways that allow details to be ignored Expressivity –A set of relatively convenient ways of specifying operations –Strength and number of operators and predefined functions

12 CST2231_introduction12 Evaluation Criteria: Reliability Type checking –Testing for type errors Exception handling –Intercept run-time errors and take corrective measures Aliasing –Presence of two or more distinct referencing methods for the same memory location Readability and writability –A language that does not support “natural” ways of expressing an algorithm will require the use of “unnatural” approaches, and hence reduced reliability

13 CST2231_introduction13 Evaluation Criteria: Cost Training programmers to use the language Writing programs (closeness to particular applications) Compiling programs Executing programs Language implementation system: availability of free compilers Reliability: poor reliability leads to high costs Maintaining programs

14 CST2231_introduction14 Evaluation Criteria: Others Portability –The ease with which programs can be moved from one implementation to another Generality –The applicability to a wide range of applications Well-definedness –The completeness and precision of the language’s official definition

15 CST2231_introduction15 Influences on Language Design Computer Architecture –Languages are developed around the prevalent computer architecture, known as the von Neumann architecture Programming Methodologies –New software development methodologies (e.g., object-oriented software development) led to new programming paradigms and by extension, new programming languages

16 CST2231_introduction16 Computer Architecture Influence Well-known computer architecture: Von Neumann Imperative languages, most dominant, because of von Neumann computers –Data and programs stored in memory –Memory is separate from CPU –Instructions and data are piped from memory to CPU –Basis for imperative languages Variables model memory cells Assignment statements model piping Iteration is efficient

17 CST2231_introduction17 The von Neumann Architecture

18 CST2231_introduction18 The von Neumann Architecture Fetch-execute-cycle (on a von Neumann architecture computer) initialize the program counter repeat forever fetch the instruction pointed by the counter increment the counter decode the instruction execute the instruction end repeat

19 CST2231_introduction19 Programming Methodologies Influences 1950s and early 1960s: Simple applications; worry about machine efficiency Late 1960s: People efficiency became important; readability, better control structures –structured programming –top-down design and step-wise refinement Late 1970s: Process-oriented to data-oriented –data abstraction Middle 1980s: Object-oriented programming –Data abstraction + inheritance + polymorphism

20 CST2231_introduction20 Language Categories Imperative –Central features are variables, assignment statements, and iteration –Include languages that support object-oriented programming –Include scripting languages –Include the visual languages –Examples: C, Java, Perl, JavaScript, Visual BASIC.NET, C++ Functional –Main means of making computations is by applying functions to given parameters –Examples: LISP, Scheme Logic –Rule-based (rules are specified in no particular order) –Example: Prolog Markup/programming hybrid –Markup languages extended to support some programming –Examples: JSTL, XSLT

21 CST2231_introduction21 Language Design Trade-Offs Reliability vs. cost of execution –Example: Java demands all references to array elements be checked for proper indexing, which leads to increased execution costs Readability vs. writability Example: 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 (flexibility) vs. reliability –Example: C++ pointers are powerful and very flexible but are unreliable

22 CST2231_introduction22 Implementation Methods Compilation –Programs are translated into machine language Pure Interpretation –Programs are interpreted by another program known as an interpreter Hybrid Implementation Systems –A compromise between compilers and pure interpreters

23 CST2231_introduction23 Genealogy of Common Languages

24 CST2231_introduction24 Brief History of PL Early Languages –Fortran –Cobol –Algol60 –Lisp –APL –Basic

25 CST2231_introduction25 Algol-based Languages PL/I Simula 67 ALGOL68 Pascal

26 CST2231_introduction26 Languages of the 80 ’ s Prolog Smalltalk C/C++ Modula-2 Ada

27 CST2231_introduction27 Language of the 90 ’ s and beyond Domain-Specific Languages (www, database, GUI, etc.) Visual Programming Languages Visual Environments Scripting languages Libraries

28 CST2231_introduction28 Learning a new language Questions to ask: –What problem domain is the language intended for? –What is the programming model? –What are the basic objects (data structures) manipulated in the language? –What are the things that you can do with these objects? –How is control flow managed in the language? –How is information flow managed in the language? Parameter passing, scope rules, declaration statements, etc.

29 CST2231_introduction29 Learning a new language Problem-oriented. Syntax is unimportant at the conceptual stage. Syntax is the least interesting part of learning a new language.

30 CST2231_introduction30 Programming Models Paradigms –Imperative –Functional –Object-Oriented –Logical –Distributed/Parallel –Constraints –Declarative –....

31 CST2231_introduction31 Imperative Paradigm Dictatorship: –Processor in control –Stuff things in new places in the processor memory. –State modification - program consists of a sequence of modification to the memory. –Somewhere in the state modification lies the answer.

32 CST2231_introduction32 Imperative Example cin >> i; X = x + i; y++; Z = x / y; for (int j=0; j<i; j++) a = a + Z; i X Y Z j a

33 CST2231_introduction33 Functional Paradigm Mathematician: –Express the process in an abstract way. –Programming has to do with specifying definitions much like math functions. –Program describe, in an abstract way, the operations that must be performed to solve the problem.

34 CST2231_introduction34 Functional Example QuickSort a list of items QuickSort(empty) = empty QuickSort(head, tail) = QuickSort(list < head) + head + QuickSort(list >= head) * + concatenation

35 CST2231_introduction35 Object-Oriented Paradigm Committee –Send messages to ask members to do stuff –Objects have states. –Only objects can change their own states. –Divide up the responsibilities.

36 CST2231_introduction36 Logical Paradigm Philosopher –People ask questions –Program is a logical description of the problem expressed as facts and rules. –Output or answers are derived from the facts.

37 CST2231_introduction37 Problem Example Dexter wants to send flowers to Mimi Dexter Mimi

38 CST2231_introduction38 Imperative Solution Allocate space for $$$ & flower Get money from bank Store money Retrieve money Give money to florist Get flower from florist Store flower Arrive at destination Retrieve flower Deliver flower $$$

39 CST2231_introduction39 OO Solution Dexter Mimi Bank Teller Florist Delivery Person

40 CST2231_introduction40 Functional Solution What needs to be done here? –Cash Withdraw –Buy Flowers –Delivery Flowers What order do they need to happen? –Cash -> Flowers -> Deliver Functions have parameters and return values Deliver( Buy (Withdraw()))

41 CST2231_introduction41 Logical Solution Ask the Question: ReceiveFlower(Mimi)? Let ’ s see the rules and facts.

42 CST2231_introduction42 Rules ReceiveFlower(x): DeliverFlower(y, x) DeliverFlower(y,x): Florist(y) & OrderFlower(z, y) & Person(x) OrderFlower(x,y): Florist(y) & Person(x) & HasMoney(x) & GiveMoney(x, y)

43 CST2231_introduction43 Facts HasMoney(Dexter) Florist(Flo) GiveMoney(Dexter, Flo) Now ask the question: ReceiveFlower(Mimi)? ??? What ’ s missing?

44 CST2231_introduction44 Facts Dog (Dexter) Dog(Mimi) ReceiveFlower(Mimi)? NO

45 CST2231_introduction45 Problem Example Dexter wants to send flowers to Mimi

46 CST2231_introduction46 Other Paradigms Distributed / Parallel Constraints –Formulas Other names for functional –Declarative –Applicative

47 CST2231_introduction47 Declarative Paradigm Specify the WHAT instead of HOW Definitional and not operational Includes functional, logical, constraints


Download ppt "CST2231_introduction1 Programming Languages A programming language is a language that is intended to be used by a person to express a process by which."

Similar presentations


Ads by Google