Lecture 2 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea
Concepts of Programming Languages Topics Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design Language Categories Language Design Trade-Offs Implementation Characteristics of Languages Significance of individual languages in 2019 Concepts of Programming 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
Concepts of Programming Languages Programming Domains Business applications E.g. Middleware that implements some business process Java, C++, C#, COBOL (still popular here!) Web programming Markup (HTML), Scripting (JavaScript (TypeScript), PHP etc.), general-purpose (e.g., Java), General purpose applications like Photoshop, Autocad, Word etc. Efficiency is important here C++, C, Delphi Systems programming / Operating System implementation Low level, code efficiency is very important C, Assembler Scientific applications E.g. Simulations; computational expensive tasks Python, R, Fortran, (C, C++) Artificial intelligence C++, Python: Deep learning, TensorFlow, etc. Older: Experimental work with languages like LISP (Scheme) and Prolog Gaming, Embedded Systems, IoT … Concepts of Programming Languages
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
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
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 List comprehensions (Python, Haskell) etc. Range-based for loops Concepts of Programming Languages
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
Evaluation Criteria: Cost Training programmers to use the language Language implementation system: Costs for compilers Reliability: poor reliability leads to high costs Maintenance costs Deployment costs Concepts of Programming Languages
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
Influences on Language Design Computer Architecture Architecture as driving factor of language design. E.g. Von Neumann Architecture OpenCL/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
Von Neumann Architecture Concepts of Programming Languages
Programming Methodologies History / Mainstream developments 1950s and early 1960s: Simple applications; worry about machine efficiency Late 1960s: People efficiency became more 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 Appearance of C++, Eiffel … Concepts of Programming Languages
Concepts of Programming Languages Imperative Languages Characteristics: Variables model memory cells Assignment statements used for assigning values to memory cells Iteration represents central concept 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 Concepts of Programming Languages
Language Categories / Families Imperative / Object Oriented Comprises languages that support object-oriented programming Comprises scripting languages Examples: C++, C, Java, C#, Python, JavaScript (TypeScript) Markup and related No logic, only pure descriptive: HTML, CSS, XML Hybrids: PHP (Visualization plus logic), XSLT (XML plus logic) Functional Motivated by Lambda Calculus Examples: LISP, Scheme, Haskell Logic Rule-based (rules are specified in no particular order) Example: Prolog Concepts of Programming Languages
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
Implementation Characteristics of languages Compilation Programs are translated directly into machine language Pure Interpretation Programs are interpreted by an execution context known as an interpreter Hybrids (Bytecode-based) A compromise between compilers and pure interpreters Concepts of Programming Languages
Concepts of Programming Languages Compilation Translate high-level program (source code) into machine code (executable file) Phases of compilation process: Lexical analysis: converts characters in the source program into lexical units Syntax analysis: transforms lexical units into parse trees which represent the syntactic structure of program Semantics analysis: generate intermediate code Optimization: automatically apply improvements Code generation: machine code is generated and written to "objects files" Linking: collect "objects files" for creating an executable Concepts of Programming Languages
Concepts of Programming Languages Interpretation Advantages: No compilation involved Boost portability! Disadvantages: Errors are recognized during runtime No static type-check, because of the absence of compilation Slow execution speed, if no clever just-in-time compilation is involved. Significant in the area of Web programming: JavaScript, PHP Concepts of Programming Languages
Bytecode-based Systems A compromise between platform-specific compilation (e.g. C++) and pure interpretation Program code is first translated to an intermediate code (called byte code) for later execution on a virtual machine Much Faster than pure interpretation Advantage: Portability Examples Java, C# Concepts of Programming Languages
Bytecode-based Systems - Programming Workflow Write Source Code Source Code program text in human readable form all 5 steps of compilation Compile Source Code Byte Code represents an intermediate code using a byte-code interpreter Execute Byte Code Concepts of Programming Languages
Just-in-Time Compilation Optimization for byte-code interpretation Instead of interpreting the byte-code the byte-code is first compiled into machine code and this machine code is executed directly on processor level Higher performance compared to pure interpretation JIT-compilation requires initially extra time. So, it delays code execution / program start. Concepts of Programming Languages
Concepts of Programming Languages 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
Significance of individual languages in 2019 Java Programming