200 likes | 227 Views
Why study programming languages?. Increased capacity to express ideas Constructs we can express can be constrained by the language we know Improved background for choosing appropriate language Should choose language appropriate for task not just the one that we know
E N D
Why study programming languages? • Increased capacity to express ideas • Constructs we can express can be constrained by the language we know • Improved background for choosing appropriate language • Should choose language appropriate for task not just the one that we know • Increased ability to learn new languages • Learning new languages and learning language fundamentals enables us to learn other languages more easily • Better understanding of the significance of implementation • Aids in finding bugs • Enables us to write more efficient code • Overall advancement of computing • Educated people will make better language choices Section 1.1
Computer Applications & Languages • Scientific • Number crunching, weather forecasting, codebreaking, plane/missile trajectories • Language requirements: • Real numbers • Large amount of calculations (hence efficient) • Arrays, matrices • Selection, Counting loops • Languages: • Assembly, Fortran, Algol Section 1.2
Computer Applications & Languages • Scientific Applications • Language requirements: reals, efficiency, arrays, loops • Languages: Fortran, assembly, Algol • Business • Financial transactions • Language requirements: • Report production • Exact (but low) precision (e.g., money) • Character data • Languages: COBOL, RPG Section 1.2
Computer Applications & Languages • Scientific Applications: reals, efficiency, arrays, loops Fortran, assembly, Algol • Business Applications: reports, decimal precision, characters COBOL, RPG • Artificial Intelligence • Deductive systems, reasoning, machine learning • Language requirements: • Symbolic computation (“names” not numbers) • Lists of data (not arrays) • Recursion • Languages: LISP, Scheme, Prolog Section 1.2
Computer Applications & Languages • Scientific Applications: reals, efficiency, arrays, loops Fortran, assembly, Algol • Business Applications: reports, decimal precision, characters COBOL, RPG • AI Applications: Symbolic computation, Lists of data, Recursion LISP, Scheme, Prolog • Systems Programming • Operating systems, compilers, debuggers, etc. • Language requirements: • FAST execution • External device interfaces • Languages: C, Assembly Section 1.2
Computer Applications & Languages • Scientific Applications: reals, efficiency, arrays, loops Fortran, assembly, Algol • Business Applications: reports, decimal precision, characters COBOL, RPG • AI Applications: Symbolic computation, Lists of data, Recursion LISP, Scheme, Prolog • Systems Programming: fast, external devices C, Assembly • Scripting Languages • Typically not general-purpose, originally utility in nature • Language requirements: vary since they are more specific • Languages: csh, tcl, perl, javascript, php Section 1.2
Computer Applications & Languages • Scientific Applications: reals, efficiency, arrays, loops Fortran, assembly, Algol • Business Applications: reports, decimal precision, characters COBOL • AI Applications: Symbolic computation, Lists of data, Recursion LISP, Scheme, Prolog • Systems Programming: fast, external devices C, Assembly • Scripting Languages: specific not general csh, tcl, perl, javascript, php • Special-purpose languages • Domain-specific, typically small • Language requirements: Vary with domain • Languages: HTML, GPSS, Excel Section 1.2
Language Characteristics • Simplicity/Orthogonality • Control structures • Data types and structures • Syntax design • Abstraction • Expressivity • Type checking • Exception handling • Restricted aliasing Section 1.1
Selected Language Characteristics • Simplicity • { … } vs. begin … end vs. if … endif • foo++ vs. foo += 1 vs. foo = foo + 1 • Syntax design • { … } vs. begin … end vs. if … endif • affects readability and writability • Exception handling • Affects reliability (impacts syntax, …) Section 1.1
Language Influences • Architecture • von Neumann • Memory • CPU • ALU • Programming Maturity (Methodologies) • Unstructured • Procedure-oriented (top-down, functions, …) • Data-oriented (ADT, OO) Section 1.1
Language Categories (most important ones) • Imperative • Functional • Logic • Object oriented • Is it an imperative sub-group? Section 1.5
Imperative Programming Languages • Central features are variables and assignment statements • Design based on the von Neumann architecture • Variables model memory cells • Assignment statement models the “piping operation” – operands piped from memory to CPU; result piped from CPU to memory Section 1.5
Functional Programming Languages • Main features are functions and function calls (recursion instead of iteration) • Design is based upon mathematical functions Section 1.5
Logic programming languages • Also called rule-based languages and declarative languages • Programmer gives rules that specify what a solution looks like and not how desired solution is achieved Section 1.5
Object Oriented Programming Languages • Provides a feature for building objects • Provides a method for specifying inheritance • Provides polymorphism • Same name for different functions (method overriding) • Dynamic binding of function call to function body Section 1.5
Implementation methods • Compilation • Interpretation • Hybrid Section 1.7
Compilation • Compiler translates program into machine language that is executed on the computer • Execution is fast Section 1.7
source machine code Compilation Lexical analyzer Linker Syntax analyzer executable Semantic analyzer/ Intermediate code generation Optimizer Code generator machine code Section 1.7
Interpreter • Pure interpretation means there is no translation of the source program • Program called an interpreter is executed by the computer • Interpreter fetches/decodes/executes source program • Slower and requires more space than the compilation process Section 1.7
Hybrid • Source program is translated into an intermediate code that is then interpreted • Examples • Java is translated into byte code that can be interpreted • Perl is compiled before execution in order to detect compilation errors (unlike shell languages) Section 1.7