Concepts of Programming Languages Lecturer: Dr. Emad Nabil Lecture # 2 Fall 2018
Influences on Language Design Computer Architecture Program Design Methodologies Copyright © 2012 Addison-Wesley. All rights reserved.
Influences on Language Design Computer Architecture Languages are developed around the prevalent computer architecture, known as the von Neumann architecture Program Design Methodologies New software development methodologies (e.g., object-oriented software development) led to new programming paradigms new programming languages
Programming paradigms Algol Cobol PL/1 Ada Modula-2 Smalltalk C# Python Scala Haskell ML Mranda APL F# Copyright © 2012 Addison-Wesley. All rights reserved.
Imperative programming Vs. Declarative Programming Imperative programming languages focuses on describing how a program operates. a developer writes code that describes in exacting detail the steps that the computer must take to accomplish the goal. This is sometimes referred to as algorithmic / procedural programming. Ex (C#, Visual Basic, C++, and Java ) Declarative Programming languages : is non-procedural and very high-level (4th generation). focuses on what the program should accomplish without specifying how the program should achieve the result. expresses the logic of a computation without describing its control flow. Declarative programming often considers programs as theories of a formal logic, and computations as deductions in that logic space. EX: database query languages (e.g., SQL, XQuery), regular expressions, logic programming (Prolog), functional programming (Lisp, Haskell). Markup languages (NOT Programming language) It is a document format Markup languages extended to support some programming (Java script) Examples: HTML, XML
1-Computer Architecture Influences on Designing programming languages Well-known computer architecture: Von Neumann Imperative languages most dominant, because of von Neumann computers Properties of Imperative languages Data and programs stored in memory Memory is separate from CPU Instructions and data are piped from memory to CPU Basis for imperative languages Variables model memory cells Assignment statements model piping Iteration is fast on von Neumann computers (faster than recursion)
The von Neumann Architecture
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 instructions executed fast Connection with memory is slow von Neumann bottleneck
2-Programming Methodologies Influences on designing programming languages 1950s and early 1960s: Simple applications; worry about machine efficiency (Fortran ) Late 1960s: People efficiency became important; readability, better control structures structured programming top-down design and step-wise refinement (Basic) Late 1970s: Process-oriented to data-oriented data abstraction – (SIMULA) (Simula is the name of a simulation PL) Middle 1980s: Object-oriented programming Data abstraction + inheritance + polymorphism (Smalltalk) Copyright © 2012 Addison-Wesley. All rights reserved.
Language Design Trade-Offs Readability Writability Reliability Cost Reliability vs. execution cost 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 are unreliable Copyright © 2012 Addison-Wesley. All rights reserved.
Programming Languages Implementation Methods 1.Compilation 2. Pure interpretation 3.Hybrid Implementation Systems Copyright © 2012 Addison-Wesley. All rights reserved.
Programming Languages Implementation Methods Compilation Programs are translated into machine language such as C, COBOL, C++, and Ada, Use: Large commercial applications 2. Pure Interpretation Programs are interpreted by another program known as an interpreter Use: Small programs or when efficiency is not an issue (PHP, java script) 3. Hybrid Implementation Systems A compromise between compilers and pure interpreters Used when efficiency is not the first concern -(Java, .NET languages, python ) Copyright © 2012 Addison-Wesley. All rights reserved.
Layered View of Computer The operating system and language implementation are layered over machine interface of a computer Bare machine (or bare metal), in computer parlance, means a computer without its operating system. Macro instructions BOIS Copyright © 2012 Addison-Wesley. All rights reserved.
1-Compilation Translate high-level program (source language) into machine code (machine language) Slow translation means fast execution (why?) Ans: Code optimization takes time. Copyright © 2012 Addison-Wesley. All rights reserved.
1-Compilation Compilation process has several phases: 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 code generation: machine code is generated Copyright © 2012 Addison-Wesley. All rights reserved.
2.Pure Interpretation No translation Easier implementation of programs (run-time errors can easily and immediately be displayed) Slower execution (10 to 100 times slower than compiled programs) Often requires more space Now rare for traditional high-level languages Significant comeback with some Web scripting languages (e.g., JavaScript, PHP) Copyright © 2015 Pearson. All rights reserved.
3.Hybrid Implementation Systems 1.Compilation 2. Pure interpretation 3.Hybrid Implementation Systems
3. Hybrid Implementation Systems Just-in-Time Implementation Systems JIT 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 (later) calls, each method is translated into M/C only when called. JIT systems are widely used for Java programs (byte code) .NET languages are implemented with a JIT system (.NET Common Intermediate Language (CIL) In essence, JIT systems are delayed compilers Copyright © 2012 Addison-Wesley. All rights reserved.
Preprocessors in programming languages A preprocessor is a program that processes a program immediately before the program is compiled. Instructions to be used by the Preprocessor are embedded in programs. Like #include<iostream.h> The preprocessor is essentially a macro expander. #include, #define Preprocessor instructions are commonly used to specify that the code from another file is to be included. Copyright © 2012 Addison-Wesley. All rights reserved.
Programming Environments A collection of tools used in software development Microsoft Visual Studio.NET A large, complex visual environment Used to build Web applications and non-Web applications in any .NET language NetBeans Related to Visual Studio .NET, except for applications in Java Source : On March 2015 https://knoema.com/jtieieg/popularity-of-programming-languages Copyright © 2012 Addison-Wesley. All rights reserved.
Summary The study of programming languages is valuable for a number of reasons: Increase our capacity to use different constructs Enable us to choose languages more intelligently Makes learning new languages easier Most important criteria for evaluating programming languages include: Readability, writability, reliability, cost Major influences on language design have been machine architecture and software development methodologies The major methods of implementing programming languages are: compilation, pure interpretation, and hybrid implementation