1 / 43

Chapter One: Metrics and Influences on Language Design

Chapter One: Metrics and Influences on Language Design. Lesson 02. What makes a good programming language?. Language Evaluation Criteria. Readability Writability Reliability Cost. A language that has poor readability, writability , and/or reliability has a high cost.

neka
Download Presentation

Chapter One: Metrics and Influences on Language Design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter One: Metrics and Influences on Language Design Lesson 02

  2. What makes a good programming language? Programming Languages: lecture two

  3. Language Evaluation Criteria • Readability • Writability • Reliability • Cost A language that has poor readability, writability, and/or reliability has a high cost Example writable vs. readable: APL has a powerful set of operators for array operands. Can be used to create very complex, very long expressions. APL has excellent writability APL has poor readability Reliable if programs that are written in the language tend to be error free. Readability and writability contribute to reliability Example: people tend to make mistakes when using pointers which leads to unreliable programs Programming Languages: lecture two

  4. Characteristics that affect criteria • To be writable, should be readable (if ever need to make changes to code) • To be reliable, must be readable and writable How could APL be writable but not readable? Programming Languages: lecture two

  5. Readability • Overall simplicity • Small number of features and constructs • Minimal feature multiplicity (multiple ways to do things, a++, a+=1,a=a+1) • Minimal operator overloading • Orthogonality • Few exceptions to the rules, always behaves as expected • Data types • Adequate predefined data types (example: int used because no boolean) • Syntax considerations • Allowable Identifiers (another word for a variable) • Intuitive meaning of statements Readability Programming Languages: lecture two

  6. Writability • Support for abstraction • Expressivity • A set of relatively convenient ways of specifying operations (++, vector multiplication, for vs. while) • Strength and number of operators and predefined functions Writability Programming Languages: lecture two

  7. Let’s try it Programming Languages: lecture two

  8. Reliability • Type checking • Exception handling • Disallow aliasing (two variables pointing to same object) Reliability Programming Languages: lecture two

  9. Cost • Readability/writability • Training programmers to use the language • Support for design approach and problem domain (object orientation, easy integration of appropriate math operations, etc.) • Maintaining programs, the more readable the better • Reliability • Constant debugging • Literal cost • Actual cost of compiler software (free?) • Compile time • Execution efficiency Cost Programming Languages: lecture two

  10. Two Major Influences on Language Design • Computer Architecture • Programming Methodologies • Software Design and Engineering Approaches Programming Languages: lecture two

  11. John von Neumann: von Neumann Architecture • Mathematician • Member of the Manhattan Project • Same memory for program and data Programming Languages: lecture two

  12. First programming languages… • 1’s and 0’s (Machine Language) • Designed to navigate the existing architecture Machine language: 10110000 01100001 Move the value 61h (or 97 decimal; the h-suffix means hexadecimal; into the processor register named "AL". Artillery firing tables: World War II ENIAC Programming Languages: lecture two

  13. First compiled languages… • Assembly: directly translates to machine language • one to one correspondence between commands in machine and assembly languages • Textual, so easier to remember Machine language: 10110000 01100001 Assembly: MOV AL, 61h Move the value 61h (or 97 decimal; the h-suffix means hexadecimal; into the processor register named "AL". IBM 360 Programming Languages: lecture two

  14. Finally, high-level, compiled programs • Make human readable • mov ax, a • cmp ax, b • jneElseBlk • mov ax, d • mov c, ax • jmpEndOfIf • ElseBlk: • inc b • EndOfIf: • if (a=b) then • c := d • else • b := b + 1; Programming Languages: lecture two

  15. Course is generally about the … • Evolution of high-level, compiled languages • Interpreted: on the fly determination of program meaning • Hybrid: when execute makes a pass compiling to an intermediate form • JIT: (just in time) subprograms compiled into machine code when they are called What other kinds of languages are there (besides compiled)? Text (source) 0101010101010101010010 (machine language) Programming Languages: lecture two

  16. Architecture first, later programming methodologies • Mid 1950s to early 1960s: machine efficiency • Late 50’s: application to problems in artificial intelligence • Late 1960s: People efficiency became important; readability, better control structures and modularity • structured programming • top-down design and step-wise refinement • Late 1970s: Process-oriented to data-oriented • data abstraction – data structures • Middle 1980s: Object-oriented programming • Data abstraction + inheritance + polymorphism Control Structures? If/else condition checking and loops Programming Languages: lecture two

  17. First high-level languages… • Considered to be “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++ Imperative Programming Languages: lecture two

  18. Why imperative? • Architecture driven • Pull data and instructions from memory • Sequential operations clock driven • Also mindset driven: • Definition of an algorithm • A step-by-step procedure for solving a problem in a finite number of steps Imperative Programming Languages: lecture two

  19. A limitation to early imperative languages • When study languages • Must formalize definitions • Many definitions and proofs (inductive) are recursive in nature • Doesn’t take long when studying algorithms to move into the realm of recursion • Recurrence relations • Earliest high-level compiled languages (Fortran) could not handle recursion No Recursion Programming Languages: lecture two

  20. The Search for Artificial Intelligence • Shortly after first high-level languages (Mid 50’s) … • Allen Newell, J. C. Shaw, and Herbert Simon “The Logical Theorist” • Used a program to actually prove theorems • Approach called “list processing” Programming Languages: lecture two

  21. Artificial Intelligence (List Processing) • Proof technique • Based upon a search tree: the root was the initial hypothesis, each branch was a deduction based on the rules of logic. • Required recursion to elegantly solve the tree search • Method needed for processing symbolic data in linked lists • Came up with own language: Information Processing Language (IPL) for list processing • Never took off: too low-level, essentially assembly language Programming Languages: lecture two

  22. Retrofit list processing • IBM retrofitted list processing to the first high-level programming language: Fortran (Fortran List Processing Language or FLPL) • John McCarthy of MIT worked for a summer at IBM • Studied symbolic differentiation • Concluded that list processing required recursion, condition checking, and implicit deallocation of abandoned lists • FLPL did not have xkcd.com Programming Languages: lecture two

  23. LISP • McCarthy and Minsky of MIT therefore developed LISP (List Programming Language) • Approach became known as functional programming • Each list has as first item a function, all subsequent items are arguments • Second major category of programming languages (first being imperative) Function applied to items in the list (f, i1, i2, …, in) Programming Languages: lecture two

  24. Example • Factorial mathematical definition • In LISP (DEFINE (factorial n) (IF (= n 0) 1 (* n (factorial (- n 1))) )) Genealogy of Common Languages

  25. In short: functional languages… • Were the result of the vacuum left by early languages when they did not support recursion • Virtually all “imperative” programming languages now support recursion, linked lists, and passing of functions as arguments • Hasn’t really received widespread acceptance • Most list processing languages are interpreted (can be slow) • Most users find it difficult to master: many of us think “imperatively” (i.e. step-by-step) when we think of algorithms Programming Languages: lecture two

  26. AI strikes again • Early 70’s: it became apparent that much of AI was comprised of logic based conclusions • Predicate calculus (if a is true then b must be true) • Inference process • Example • It can be deduced that X is the grandparent of Z if it si true that X is the parent of Y and Y is the parent of Z • Can query a database of fact statements and rules • Like Y is the parent of Z • Looking for relationships that satisfy rule statements like grandparent relationship Programming Languages: lecture two

  27. Programming language categories • Logic programming languages became the third major category • Advent of WEB drove the fourth • Categories • Imperative • C, Java, Perl, JavaScript, Visual BASIC .NET, C++ • Functional • LISP, Scheme, ML • Logic • Prolog • Markup/programming hybrid • JSTL, XSLT Programming Languages: lecture two

  28. Course • Practice at several exemplary programming languages • Focus more on C/C++ than the rest • Learn the vernacular of formally describing languages • Gain some insight into how compilers work Objectives Programming Languages: lecture two

  29. What should you study in this chapter? • Terminology • Readability/ writability/ reliability (e.g. if a language allows aliasing how does that affect reliability)? • Homework will give you some examples • Imperative • Functional • Logic • JIT • Interpreted • Hybrid • Expression • Orthogonal • Syntax • Abstraction • Expressive • Aliasing • Construct • Identifier • Control structures • Compile VOCABULARY Programming Languages: lecture two

  30. Programming Languages: lecture two

  31. Construct • From construction, to construct something from smaller parts • (Wikipedia) A language construct is a syntactically allowable part of a program that may be formed from one or more lexical tokens in accordance with the rules of a programming language. • Variable • If/else • Method/function/procedure • Class Return Introduction

  32. Lexical • A lexicon is a dictionary • Merriam-Webster Main Entry: lex·i·cal Pronunciation: \ˈlek-si-kəl\ Function: adjective Date: 1836 1: of or relating to words or the vocabulary of a language as distinguished from its grammar and construction 2: of or relating to a lexicon or to lexicography Return Programming Languages: lecture two

  33. Orthogonality • Merriam-Webster Main Entry: or·thog·o·nal Pronunciation: \ȯr-ˈthä-gə-nəl\ Function: adjective Etymology: Middle French, from Latin orthogonius, from Greek orthogōnios, from orth- + gōnia angle — more at -gon Date: 1612 1 a: intersecting or lying at right angles b: having perpendicular slopes or tangents at the point of intersection <orthogonal curves>2: having a sum of products or an integral that is zero or sometimes one under specified conditions: as aof real-valued functions: having the integral of the product of each pair of functions over a specific interval equal to zero bof vectors: having the scalar product equal to zero cof a square matrix: having the sum of products of corresponding elements in any two rows or any two columns equal to one if the rows or columns are the same and equal to zero otherwise : having a transpose with which the product equals the identity matrix 3of a linear transformation: having a matrix that is orthogonal : preserving length and distance4: composed of mutually orthogonal elements <an orthogonal basis of a vector space>5: statistically independent Return Programming Languages: lecture two

  34. Orthogonality (continued) • A relatively small set of primitive constructs can be combined in a relatively small number of ways • Every possible combination is legal, independentof context • Negative examples • C: • Cannot return an array from a function • Member of a struct can be any data type except void • Members of an array can be any data type except void Programming Languages: lecture two

  35. Syntax • Merriam-Webster Main Entry: syn·tax Pronunciation: \ˈsin-ˌtaks\ Function: noun Etymology: Middle French or Late Latin; Middle French sintaxe, from Late Latin syntaxis, from Greek, from syntassein to arrange together, from syn- + tassein to arrange Date: 1574 1 a: the way in which linguistic elements (as words) are put together to form constituents (as phrases or clauses) b: the part of grammar dealing with this2: a connected or orderly system : harmonious arrangement of parts or elements <the syntax of classical architecture>3:syntactics especially as dealing with the formal properties of languages or calculi Introduction

  36. Expression • (Wikipedia) An expression is a combination of values, variables, operators, and functions that are interpreted (evaluated) according to the particular rules of precedence and of association for a particular programming language, which computes and then produces (returns, in a stateful environment) another value. • Examples: • a • a+b • f(x) • a==b Return Programming Languages: lecture two

  37. Abstraction • (Wikipedia) Abstraction is the process or result of generalization by reducing the information content of a concept or an observable phenomenon, typically to retain only information which is relevant for a particular purpose. For example, abstracting a leather soccer ball to a ball retains only the information on general ball attributes and behavior. Similarly, abstracting happiness to an emotional state reduces the amount of information conveyed about the emotional state. Computer scientists use abstraction to understand and solve problems and communicate their solutions with the computer in some particular computer language. • Examples: • Float is an abstraction for a real number • An Employee object in a program is an abstraction for an employee: doesn’t describe everything about an object Return Programming Languages: lecture two

  38. Recursion • Recursion is a method where the solution to a problem depends on solutions to smaller instances of the same problem. Graham, Ronald; Donald Knuth, Oren Patashnik (1990). Concrete Mathematics. Chapter 1: Recurrent Problems. http://www-cs-faculty.stanford.edu/~knuth/gkp.html. Donald Knuth wrote “The art of programming,” "father" of the analysis of algorithms, big O notation • The power of recursion evidently lies in the possibility of defining an infinite set of objects by a finite statement. In the same manner, an infinite number of computations can be described by a finite recursive program, even if this program contains no explicit repetitions. Wirth, Niklaus (1976). Algorithms + Data Structures = Programs. Prentice-Hall. p. 126. Niklaus Wirth wrote Pascal programming language Programming Languages: lecture two

  39. Recursion (continued) • Example • Factorial if x==1 then f(x)=1 else f(x) = x * f(x-1) • Fibonacci • By definition, the first two Fibonacci numbers are 0 and 1, and each remaining number is the sum of the previous two. Some sources omit the initial 0, instead beginning the sequence with two 1s. • 0 1 1 2 3 5 8 13 21 34 55 89 144 • In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation • F0=0 and F1 = 1 otherwise Fn=Fn-1+Fn-2 if x==0 then f(x)=0 else if x==1 then f(x)=1 else f(x) = x * f(x-1) Programming Languages: lecture two

  40. Recursion (continued) • Definition of the set of natural numbers • 1 is in N • If an element n is in N then n+1 is in N Programming Languages: lecture two

  41. Why no recursion early on Stack: local variables Heap: dynamic allocation Data: global variables Text: program code • Efficient implementation of recursion generally requires a memory data structure known as a stack, and most computer architectures designed since the 1970s provide fast hardware support for stacks. The routine calling convention on the machines of the 1950s for which Fortran was originally developed stored the return address in the called routine, completely preventing recursion. Done with recursion Programming Languages: lecture two

  42. Reasons for Studying Programming Languages • Increased ability to express ideas • Improved background for choosing appropriate languages • Increased ability to learn new languages • Better understanding of significance of implementation • Better use of languages that are already known • Overall advancement of computing Programming Languages: lecture two

  43. Where programming is used(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 (operating system and supporting tools) • 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) Return Programming Languages: lecture two

More Related