Lecture Data Structures and Practise

Download Report

Transcript Lecture Data Structures and Practise

Lecture 2
Concepts of Programming
Languages
Arne Kutzner
Hanyang University / Seoul Korea
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
L2.2
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
L2.3
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
L2.4
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
L2.5
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
L2.6
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
L2.7
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
L2.8
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
L2.9
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
L2.10
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
L2.11
Von Neumann Architecture
Concepts of Programming Languages
L2.12
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
L2.13
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
L2.14
Language Categories / Families
• Imperative
– Comprises languages that support object-oriented programming
– Comprises scripting languages
– Examples: C, Java, Perl, JavaScript, 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
L2.15
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
L2.16
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
L2.17
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
L2.18
Additional Compilation
Terminology
• Linking: the process of collecting
“objects files” for creating an executable
file as output.
Concepts of Programming Languages
L2.19
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. JavaScript, PHP)
Concepts of Programming Languages
L2.20
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
L2.21
Hybrid Implementations
Write Source Code
Source Code
Compile Source Code
Byte Code
Execute Byte Code
program text in human
readable form
all 5 steps of
compilation
represents an
intermediate code
using a bytecode interpreter
Concepts of Programming Languages
L2.22
Just-in-Time Compilation
• Optimization for hybrid implementations
• Instead of interpreting the byte-code 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
L2.23
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
L2.24
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
– NetBeans
• An integrated development environment for Java provided by
Oracle
Concepts of Programming Languages
L2.25