Lecture 2 Concepts of Programming Languages Arne Kutzner

  • Slides: 25
Download presentation
Lecture 2 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea

Lecture 2 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea

Topics • • Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation

Topics • • Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design Language Categories Language Design Trade-Offs Implementation Methods Programming Environments Concepts of Programming Languages 2

Reasons for Studying Concepts of Programming Languages • Improved background for choosing appropriate languages

Reasons for Studying Concepts of Programming Languages • Improved background for choosing appropriate languages – Reduction of the risk of wrong decisions • Better use of languages that are already known • Better understanding of significance of language implementations Concepts of Programming Languages 3

Programming Domains • Business applications – E. g. Middleware that implements some business process

Programming Domains • Business applications – E. g. Middleware that implements some business process – Java, COBOL (still popular here!) • Web programming – Languages: markup (e. g. , HTML), scripting (e. g. , PHP), general-purpose (e. g. , Java) • General purpose applications – Examples: Photoshop, Autocad, Word …. – Reliability and efficiency are important • Systems programming / Operating System implementation – Low level, code efficiency is very important – C, Assembler • Scientific applications – E. g. Simulations; computational expensive tasks – Fortran, (C, C++) • Artificial intelligence – Experimental work with languages like LISP (Scheme) and Prolog – However, still on the level artificial stupidity Concepts of Programming Languages 4

Language Evaluation Criteria • Readability: Is this code easily readable? • Writability: Do you

Language Evaluation Criteria • Readability: Is this code easily readable? • Writability: Do you like this coding? ++++[>++++[>++>+++>+<<<<-]>+>+>->>+[<]<-]>>. > ---. +++++++. >>. <-. <. +++. --------. >>+. >++. – Hello World in Brainfuck (http: //esolangs. org/wiki/Brainfuck) • Reliability: unexpected crashes, blue screen of death • Cost: $ $ $ … Concepts of Programming Languages 5

Evaluation Criteria: Readability / Writability • Overall readability/writability – Are the constructs of the

Evaluation Criteria: Readability / Writability • Overall readability/writability – Are the constructs of the language self describing/intuitive/well human readable … – Syntax considerations • Special symbols and their meaning (e. g. creation of compound statements) • Special words, meaningful keywords • Data types and structures – Adequate predefined data types and structures – The presence of adequate facilities for defining new data structures Concepts of Programming Languages 6

Evaluation Criteria: Readability / Writability • Support for abstraction – The ability to define

Evaluation Criteria: Readability / Writability • 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 function Concepts of Programming Languages 7

Evaluation Criteria: Reliability • Static type checking vs. dynamic type checking – Recognition of

Evaluation Criteria: Reliability • Static type checking vs. dynamic type checking – Recognition of type errors during compile time / runtime • Exception handling – Intercept run-time errors and take corrective measures Concepts of Programming Languages 8

Evaluation Criteria: Cost • Training programmers to use the language • Language implementation system:

Evaluation Criteria: Cost • Training programmers to use the language • Language implementation system: Availability of free compilers • Reliability: poor reliability leads to high costs • Maintenance costs • Deployment costs Concepts of Programming Languages 9

Further Evaluation Criteria … • Portability – The ease with which programs can be

Further Evaluation Criteria … • 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 Concepts of Programming Languages 10

Influences on Language Design • Computer Architecture – Architecture as driving factor of language

Influences on Language Design • Computer Architecture – Architecture as driving factor of language design. – E. g. Von Neumann Architecture – Open. CL/CUDA for computing on GPUs • Programming Methodologies – Abstract data types – concept of object orientation • Computational models / Mathematical models for computation – Lambda Calculus, Predicate Logic Concepts of Programming Languages 11

Von Neumann Architecture Concepts of Programming Languages 12

Von Neumann Architecture Concepts of Programming Languages 12

Programming Methodologies History / Mainstream developments • 1950 s and early 1960 s: Simple

Programming Methodologies History / Mainstream developments • 1950 s and early 1960 s: Simple applications; worry about machine efficiency • Late 1960 s: People efficiency became more important; readability, better control structures – structured programming – top-down design and step-wise refinement • Late 1970 s: Process-oriented to data-oriented – data abstraction • Middle 1980 s: Object-oriented programming – Data abstraction + Inheritance + Polymorphism – Appearance of C++, Eiffel … Concepts of Programming Languages 13

Imperative Languages • Inspired by von Neumann computers – Data and programs stored in

Imperative Languages • Inspired by von Neumann computers – Data and programs stored in memory – Memory is separate from CPU – Instructions and data are piped from memory to CPU • Characteristics of imperative languages – Variables model memory cells – Assignment statements used for assigning values to memory cells – Iteration represents central concept – Popular examples: C, Pascal Concepts of Programming Languages 14

Language Categories / Families • Imperative – Comprises languages that support object-oriented programming –

Language Categories / Families • Imperative – Comprises languages that support object-oriented programming – Comprises scripting languages – Examples: C, Java, Perl, Java. Script, Visual BASIC. NET, C++, C# • Markup/programming hybrid – Markup languages extended to support some programming – Examples: HTML, XML, PHP, XSLT • Functional – Main means of making computations is by applying functions to given parameters – Examples: LISP, Scheme, Haskell • Logic – Rule-based (rules are specified in no particular order) – Example: Prolog Concepts of Programming Languages 15

Language Design Trade-Offs • Reliability vs. Cost of execution – Example: Java demands all

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 • Writability (flexibility) vs. Reliability – Example: C pointers are powerful and very flexible but they are unreliable Concepts of Programming Languages 16

Implementation Characteristics of languages • Compilation – Programs are translated directly into machine language

Implementation Characteristics of languages • Compilation – Programs are translated directly into machine language • Pure Interpretation – Programs are interpreted by another program known as an interpreter • Hybrid Implementations – A compromise between compilers and pure interpreters Concepts of Programming Languages 17

Compilation • Translate high-level program (source code) into machine code (executable file) • Slow

Compilation • Translate high-level program (source code) into machine code (executable file) • Slow translation, fast execution • Phases of compilation process: 1. Lexical analysis: converts characters in the source program into lexical units 2. Syntax analysis: transforms lexical units into parse trees which represent the syntactic structure of program 3. Semantics analysis: generate intermediate code 4. Optimization: automatically apply improvements 5. Code generation: machine code is generated Concepts of Programming Languages 18

Additional Compilation Terminology • Linking: the process of collecting “objects files” for creating an

Additional Compilation Terminology • Linking: the process of collecting “objects files” for creating an executable file as output. Concepts of Programming Languages 19

Pure Interpretation • Advantages – No translation/compilation required • Disadvantages – Errors are recognized

Pure Interpretation • Advantages – No translation/compilation required • Disadvantages – Errors are recognized during runtime – Slow execution speed (10 to 100 times slower than compiled programs) – No static type-check, because of the absence of compilation • Significant in the area of Web scripting languages (e. g. Java. Script, PHP) Concepts of Programming Languages 20

Hybrid Implementation Systems • A compromise between compilers and pure interpreters • A program

Hybrid Implementation Systems • A compromise between compilers and pure interpreters • A program code is first translated to an intermediate code (called byte code) for later execution on a virtual machine • Faster than pure interpretation • More portable than compiled code • Examples – Java, C# Concepts of Programming Languages 21

Hybrid Implementations Write Source Code Compile Source Code program text in human readable form

Hybrid Implementations Write Source Code Compile Source Code program text in human readable form all 5 steps of compilation Byte Code represents an intermediate code Execute Byte Code using a byte-code interpreter Concepts of Programming Languages 22

Just-in-Time Compilation • Optimization for hybrid implementations • Instead of interpreting the byte-code is

Just-in-Time Compilation • Optimization for hybrid implementations • Instead of interpreting the byte-code is first compiled into machine code and this machine code is executed direct on processor level • Higher performance compared to interpretation • JIT-compilation requires initially extra time. So it delays code execution / program start • Nowadays standard with most hybrid implementations Concepts of Programming Languages 23

Preprocessors • A preprocessor processes/changes source code before it is compiled – Works like

Preprocessors • A preprocessor processes/changes source code before it is compiled – Works like a macro mechanism and implements a text to text transformation • C, C++ preprocessor – expands #include, #define, and similar macros • Not popular outside C and C++ • Main disadvantage: Compiler error messages can become quite cryptic/strange Concepts of Programming Languages 24

Integrated Development Environments • Not part of the programming language itself; only supportive tools

Integrated Development Environments • Not part of the programming language itself; only supportive tools for convenient software development • Popular examples: – Microsoft Visual Studio tools: • Supports MS-compiler for C#, Visual BASIC. NET, Jscript, J#, and C++ – Eclipse • Open programming environment that supports many programming languages – Net. Beans • An integrated development environment for Java provided by Oracle Concepts of Programming Languages 25