1 / 123

CPS 506 Comparative Programming Languages

CPS 506 Comparative Programming Languages. Winter 2010 Ryerson University. Course Outline. Introduction Syntax and Semantic Specification Type Systems, Semantics and Data Types Names, Scope, Expression Control Structures Sub-program and Parameter Passing Exception Handling

reia
Download Presentation

CPS 506 Comparative Programming Languages

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. CPS 506Comparative Programming Languages Winter 2010 Ryerson University

  2. Course Outline Introduction Syntax and Semantic Specification Type Systems, Semantics and Data Types Names, Scope, Expression Control Structures Sub-program and Parameter Passing Exception Handling Abstract Data Type and Encapsulation

  3. Course Outline (con’t) • Programming Language Paradigms • Imperative (C, Pascal,…) • Object-Oriented (C++, C#, Java,…) • Logic (Prolog, Mercury) • Functional (ML, Scheme, Haskell,…) • Even-driven (Visual Basic, Java,…) • Concurrent or Parallel (SR, Linda,…) • Multi-Paradigm (Ruby, Python, Perl,…)

  4. Course Outline (con’t) • Languages Survey • ML (Meta Language) (1990s) • Functional language • Ruby (1993) • A balanced functional and imperative languages • Python (1991) • Object-Oriented, functional and imperative language

  5. Textbook • Concepts of Programming Languages, 9th Edition • By Robert W. Sebesta http://www.coursesmart.com/0136073476 • Programming Languages: Principles and Paradigms, 2nd Edition • By Allen Tucker and Robert Noonan http://www.mhhe.com/engcs/compsci/tucker/ • …

  6. Evaluation • Assignments (20%) • Midterm (30%) • Final Exam (50%) • Optional Project (10%) • Programming language survey • Paradigm survey

  7. Contact Information • Course Web Page www.scs.ryerson.ca/~ssamet/ (check every three days) • Contact Email ssamet@scs.ryerson.ca • Office Hours TBA • Teaching Assistant TBA

  8. Why programming Languages? • Facilitate expression of ideas and communication • The more expressive power of the language , the deeper thought • Awareness of the programming languages increases range of software development thought processes • Ability to choose appropriate language • understanding main features of the languages

  9. Why programming Languages? (con’t) • Increase ability to learn and design new languages • Understanding fundamental concepts • Better usage of the languages • Learning unknown and unused parts of the languages • Overall advancement of computing • Most popular languages are not always the best ones • ALGOL 60 and Fortran

  10. Introduction (con’t) • Different from natural languages • Narrower expressive domain (Algorithmic ideas) • Communication between human and computer • Future programming languages • Understand features, strengths and weaknesses • New application needs

  11. Programming Language Qualities • Criteria • Readability • Ease of reading and understanding a program • Before 1970s • Efficiency and Machine readability • Design from the point of view of computer • 1970s and after • Software life-cycle concept • Maintenance • Machine orientation -> Human orientation • Consider in the context of the domain

  12. Programming Language Qualities • Criteria (con’t) • Writability • How easily a language can be used • Tough relation with readability • Consider in the context of the domain • VB for GUI • C for system programs

  13. Programming Language Qualities • Criteria (con’t) • Reliability • Performs according to the specifications under all conditions • Crucial criterion for embedded, scientific, real-time and human related systems

  14. Programming Language Qualities • Characteristics • Simplicity and Clarity • How easily a program is written and read • Knowledge difference of author and reader • Binding • Language definition, implementation time, program writing time, compile time, run time

  15. Programming Language Qualities (con’t) • Characteristics (con’t) • Orthogonality • Small set of primitive constructs can be combined in a small number of ways to define the components of a language • Not too many ways for doing the same thing • A symbol or reserve word always have the same meaning • Type checking • Testing for type errors • Expensive in run-time • Original C language had no parameter type checking

  16. Programming Language Qualities (con’t) • Characteristics (con’t) • Exception handling • Ability to intercept run-time errors • Prevent system crash • Aliasing • Same memory, two or more names • Side-effect • Difficult program verification • Applicability • Support for the application domain

  17. Programming Language Qualities (con’t) • Characteristics (con’t) • Abstraction • Complex s structures without specifying the detail implementation • Efficient Implementation • Problems like in early implementation of Java and Ada

  18. Programming Language Qualities (con’t) • Cost • Training, Writing, Compiling, Executing, Maintenance, Implementation environment • Portability • One program on different platforms • Generality • Applicability to wide range of application domain

  19. Quality Trade-offs • Reliability vs. Writability • C: Pointers are flexible and powerful • Reliability vs. Execution Cost • Java: Array index checking • Writability vs. Readability • APL: Many new symbols and complex computations • Example: Find all prime numbers from 1 to R: (~R∊R∘.×R)/R←1↓⍳R (From Wikipedia)

  20. Influence on Language Design • Computer Architecture • Many languages are designed according to the prevalent architecture, Van Neumann • Imperative languages • Both data and program in the same memory • CPU is separate from memory • Data and instructions piped to CPU • Results moved back to memory

  21. Influence on Language Design (con’t) Memory Control Unit Algorithmic Logic Unit Accumulator Input Input Van Neumann Architecture

  22. Influence on Language Design (con’t) • Computer Architecture (con’t) • Variables model memory cell • Assignments statements based on piping operation • Iterative form of repetition: efficient way to implement loops (instructions stored in adjacent cells) • Fetch-Execute cycle

  23. Influence on Language Design (con’t) • Software Development Methodologies • New paradigm, new languages

  24. Programming methodologies influences • 1950s and early 1960s: Simple applications; machine efficiency problem • Late 1960s: Efficiency became important; readability; better control structures • structured programming • top-down design

  25. Programming methodologies influences (con’t) • Late 1970s: Process-oriented to data-oriented • data abstraction • Mid 1980s: Object-oriented programming • Data abstraction; inheritance; dynamic method binding (polymorphism)

  26. Implementation Methods • Compiler • Translation of the program to machine code • Examples: C, Pascal, Haskell, ML • Interpreter • Program is interpreted by a software program, interpreter • Examples: Cobol, APL, LISP

  27. Implementation Methods (con’t) • Hybrid implementation • Partially translated to detect errors • Translate to an intermediate language for easier interpretation • Example: Perl, initial implementation of Java • Just-In-Time • Translate to intermediate language • Compile the methods that are called • Example: Java, .Net languages

  28. Layered View of Computer The operating system and language implementation are layered over machine interface of a computer

  29. Compilation • Translate high-level program (source language) into machine code (machine language) • Slow translation, fast execution

  30. The Compilation Process • Compilation process phases: • lexical analysis: converts characters in the source program into lexical units • Identifiers • Special words • Operators • Punctuation symbols • syntax analysis: transforms lexical units into parse trees which represent the syntactic structure of program • Semantics analysis: generate intermediate code • code generation: machine code is generated 30

  31. Additional Compilation Terminologies • Load module (executable image): the user and system code together • Linking and loading: the process of collecting system program units and linking them to a user program

  32. Von Neumann Bottleneck • Connection speed between a computer’s memory and its processor determines the speed of a computer • Program instructions often can be executed much faster than the speed of the connection; the connection speed thus results in a bottleneck • Known as the von Neumann bottleneck; it is the primary limiting factor in the speed of computers • Motivation for research and development of parallel computers

  33. Pure Interpretation • No translation • Works as a software simulation of a machine • Easier implementation of programs (run-time errors can easily and immediately be displayed) • Slower execution (10 to 100 times slower than compiled programs) • Decoding high-level language statements • Statements are decoded every time executed • Bottleneck is statement decoding and not the communication between memory and processor

  34. Pure Interpretation (con’t) • Often requires more space • In addition of source, symbol table has to be present during interpretation • Storing source program in a form for easy access and modification and not in minimal size • Pure interpreters (1960s) • APL, SNOBOL, LISP • Rarely used in high-level languages (by the 1980s) • Significant comeback with some Web scripting languages • JavaScript • PHP

  35. Pure Interpretation Process

  36. Hybrid Implementation Systems • A compromise between compilers and pure interpreters • A high-level language program is translated to an intermediate language that allows easy interpretation • Faster than pure interpretation • Source statements are decoded only once

  37. Hybrid Implementation Systems • Examples • Perl programs are partially compiled to • Detect errors before interpretation • Simplify the interpreter • Initial implementations of Java were hybrid; the intermediate form, byte code, provides portability to any machine that has • Byte code interpreter • Associated run-time system • Together, these are called Java Virtual Machine • New versions translate Java byte code into machine code for faster execution

  38. Hybrid Implementation Process

  39. Just-in-Time Implementation Systems • Initially translate programs to an intermediate language • Then compile the intermediate language of the subprograms into machine code when they are called • Machine code version is kept for subsequent calls • JIT systems are widely used for Java programs • .NET languages are implemented with a JIT system

  40. Preprocessors • Preprocessor macros (instructions) are commonly used to specify that code from another file is to be included • A preprocessor processes a program immediately before the program is compiled to expand embedded preprocessor macros • A well-known example: C preprocessor • expands #include, #define, and similar macros • Possible side effect

  41. Principles of language design • Basic vocabulary to express language structures, meaning, …, borrowed from • Linguistics • Mathematics • Principles categories • Syntax • Type Systems and Semantics • Memory Management • Exception Handling

  42. Syntax (form) • Grammar for writing programs • Basic vocabulary of • Keywords • Symbols • Combinations of keywords and symbols forming a syntactically correct program

  43. Syntax (con’t) Pascal program sample; var a,b:integer; begin a := 1; b := a+1; If ( b = a ) then begin a := a+1; b := 0; end; end. C main() { inta,b; a = 1; b = a+1; if ( b == a ) { a++; b = 0; } }

  44. Type Systems and Semantics • Type of values • Meaning of the programs • Formal approach to understand effects of • Statements • Sequence of steps • Loops • Conditional statements • … • Abstract definition (independent of machine or OS architectures)

  45. Type Systems and Semantics (con’t) • Different characteristics of data object • Location • Name • Value • Type • Primitive, Composite and Recursive data types • Type Binding • Type Checking • Type Conversion

  46. Memory Management Mapping of values, data structures, and program structures to the memory Static memory (Stack) Dynamic memory (Heap) Objects lifetime Garbage collection

  47. Exception Handling Unexpected input error Unexpected division by zero Unexpected unsuccessful space allocation in the heap A fundamental feature in modern languages

  48. Programming Paradigms • Imperative • Series of steps • Calculate • Retrieve input • Produce output • Procedural Abstraction • Assignments • Loops • Sequences • Conditional Statements • Examples • Cobol, Fortran, C, C++

  49. Programming Paradigms (con’t) • Object Oriented • Collection of objects interact with each other • Building blocks • Object modeling • Classification • Inheritance • Examples • Java, Smalltalk, C++, C#, Ruby, Ada 95

  50. Programming Paradigms (con’t) • Logic • Collection of declarative rules • “What outcome” instead of “How accomplish” • Natural vehicle for expressing non-determinism • A series of possible solutions to a problem • Examples • Prolog

More Related