Concepts of Programming Languages PDF

Document Details

EngagingSodalite

Uploaded by EngagingSodalite

Al-Aqsa University

2023

Mohammed A. Awadallah

Tags

programming languages programming computer science software development

Summary

This document is an introduction to programming concepts, and covers topics including programming languages, programming domains, language evaluation criteria, influences on language design, and programming environments for the first semester of 2022/2023 of the Al AQSA University.

Full Transcript

Concepts of Programming Languages Dr. Mohammed A. Awadallah First semester 2022/2023 Chapter 1 Preliminaries ISBN 0-321-49362-1 Chapter 1 Topics Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influ...

Concepts of Programming Languages Dr. Mohammed A. Awadallah First semester 2022/2023 Chapter 1 Preliminaries ISBN 0-321-49362-1 Chapter 1 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 Copyright © 2015 Pearson. All rights reserved. 1-3 Why am I Here? Because I am keen to learn about the concepts underlying the design and implementation of different programming languages. So I can select the most suitable programming language to perform specific program with specific features. Copyright © 2015 Pearson. All rights reserved. 1-4 What is a Programming Language A language used to write programs, where the program is instructions in computer memory to make it do something. Is an artificial language designed to express computations or algorithms that can be performed by a computer A means of formal and exact communication between humans A way of describing computation that is readable by both man and machine Copyright © 2015 Pearson. All rights reserved. 1-5 Reasons for Studying Concepts of Programming Languages 1. Increased ability to express ideas 2. Improved background for choosing appropriate languages 3. Increased ability to learn new languages 4. Better understanding of significance of implementation 5. Better use of languages that are already known 6. Overall advancement of computing Copyright © 2015 Pearson. All rights reserved. 1-6 1) Increased ability to express ideas The depth at which people can think is influenced by the expressive power of the language in which they communicate their thoughts. Programmers, in the process of developing software, are similarly constrained. The language in which they develop software places limits on the kinds of control structures, data structures, and abstractions they can use; thus, the forms of algorithms they can construct are likewise limited. Awareness of a wider variety of programming language features can reduce such limitations ▪ Example: C programmer who had learned the structure and uses of associative arrays in Perl. Copyright © 2015 Pearson. All rights reserved. 1-7 2) Improved background for choosing appropriate languages Many programmers received their formal training years ago. The languages they learned then are no longer used, and many features now available in PLs were not widely known at the time. The result is that many programmers, they use the language with which they are most familiar, even if it is poorly suited for the project at hand. If these programmers were familiar with a wider range of languages, they would be better able to choose the language with the features that best address the problem. It is preferable to use a feature whose design has been integrated into a language than to use a simulation of that feature, which is often less elegant, more cumbersome, and less safe. (e.g. Boolean in some languages) Copyright © 2015 Pearson. All rights reserved. 1-8 3) Increased ability to learn new languages The process of learning a new programming language can be lengthy and difficult, especially for someone who is comfortable with only one or two languages and has never examined programming language concepts in general Once a thorough understanding of the fundamental concepts of languages is acquired, it becomes far easier to see how these concepts are incorporated into the design of the language being learned. For example, programmers who understand the concepts of object-oriented programming will have a much easier time learning Ruby Copyright © 2015 Pearson. All rights reserved. 1-9 4) Better understanding of significance of implementation Understanding of implementation issues leads to an understanding of why languages are designed the way they are. In turn, this knowledge leads to the ability to use a language more intelligently, as it was designed to be used. Certain kinds of program bugs can be found and fixed only by a programmer who knows some related implementation details E.g., passing by value and passing by reference Understanding implementation issues is that it allows us to visualize how a computer executes various language constructs. E.g., stack (last in first out) Copyright © 2015 Pearson. All rights reserved. 1-10 5) Better use of languages that are already known Most contemporary programming languages are large and complex. Accordingly, it is uncommon for a programmer to be familiar with and use all of the features of a language he or she uses. This course leads programmers to learn about previously unknown and unused parts of the languages they already use and begin to use those features. Copyright © 2015 Pearson. All rights reserved. 1-11 6) Overall advancement of computing It is usually possible to determine why a particular programming language became popular, many believe, at least in retrospect, that the most popular languages are not always the best available. In some cases, it might be concluded that a language became widely used, at least in part, because those in positions to choose languages were not sufficiently familiar with the features of other programming languages. Copyright © 2015 Pearson. All rights reserved. 1-12 Programming Domains Scientific applications – Appeared in the late 1940s and early 1950s – Large numbers of floating point computations. – The most common data structures were arrays and matrices; – The most common control structures were counting loops and selections – Fortran, ALGOL 60 Business applications – Appeared in the began of 1950s. – Business languages are characterized by facilities for producing elaborate reports, precise ways of describing and storing decimal numbers and character data, and the ability to specify decimal arithmetic operations. – COBOL Copyright © 2015 Pearson. All rights reserved. 1-13 Programming Domains Artificial intelligence – Symbols rather than numbers manipulated; use of linked lists – LISP, Prolog – Now the new AI systems written using MATLAB, Python, R, etc. Systems programming – Need efficiency because of continuous use – C Web Software – Eclectic collection of languages: markup (e.g., HTML), scripting (e.g., JavaScript or PHP), general-purpose (e.g., Java) Mobile applications Copyright © 2015 Pearson. All rights reserved. 1-14 IEEE Language Ranking 2022: Spectrum Copyright © 2015 Pearson. All rights reserved. 1-15 IEEE Language Ranking 2022: Jobs Copyright © 2015 Pearson. All rights reserved. 1-16 IEEE Language Ranking 2022: Trending Copyright © 2015 Pearson. All rights reserved. 1-17 Language Evaluation Criteria 1. Readability: the ease with which programs can be read and understood 2. Writability: the ease with which a language can be used to create programs 3. Reliability: conformance to specifications (i.e., performs to its specifications) 4. Cost: the ultimate total cost to buy specific programming language. Copyright © 2015 Pearson. All rights reserved. 1-18 Evaluation Criteria: Readability 1. Overall simplicity – A manageable set of features and constructs The overall simplicity of a programming language strongly affects its readability. A language with a large number of basic constructs is more difficult to learn than one with a smaller number. Programmers who must use a large language often learn a subset of the language and ignore its other features. Readability problems occur whenever the program’s author has learned a different subset from that subset with which the reader is familiar. Copyright © 2015 Pearson. All rights reserved. 1-19 Evaluation Criteria: Readability 1. Overall simplicity – Minimal feature multiplicity More than one way to accomplish a particular operation Example in Java count = count + 1 count += 1 count++ ++count – Minimal operator overloading a single operator symbol has more than one meaning Example in C++ count = 4 if(count=5) Copyright © 2015 Pearson. All rights reserved. 1-20 Evaluation Criteria: Readability 2. Orthogonality – A relatively small set of primitive constructs can be combined in a relatively small number of ways to build the control and data structures of the language. – Primitive data types (integer, float, double, and character). – Two type operators (array and pointer) – Every possible combination is legal – A lack of orthogonality leads to exceptions to the rules of the language. Copyright © 2015 Pearson. All rights reserved. 1-21 Evaluation Criteria: Readability 3. Data types – Adequate predefined data types – suppose a numeric type is used for an indicator flag because there is no Boolean type in the language timeOut = 1 (meaning of this statement is unclear) timeOut = true (meaning of this statement is clear) Copyright © 2015 Pearson. All rights reserved. 1-22 Evaluation Criteria: Readability 4. Syntax considerations – Identifier forms: flexible composition – Special words and methods of forming compound statements For example, in Fortran 95, special words, such as Do and End, are legal variable names, so the appearance of these words in a program may or may not connote something special. – Form and meaning: self-descriptive constructs, meaningful keywords – Using words where their appearance at least partially indicates their purpose is an obvious aid to readability. For example, the same variable defined in the function as a local variable, and defined outside all functions as a global variable Copyright © 2015 Pearson. All rights reserved. 1-23 Evaluation Criteria: Writability Writability is a measure of how easily a language can be used to create programs for a chosen problem domain It simply is not fair to compare the writability of two languages in the realm of a particular application when one was designed for that application and the other was not For example, the writabilities of Visual BASIC (VB) (Halvorson, 2013) and C are dramatically different for creating a program that has a graphical user interface (GUI), for which VB is ideal. Copyright © 2015 Pearson. All rights reserved. 1-24 Evaluation Criteria: Writability 1. Simplicity and orthogonality – Few constructs, a small number of primitives, a small set of rules for combining them is much better than simply having a large number of primitives – If a language has a large number of different constructs, some programmers might not be familiar with all of them. 2. Expressivity – A set of relatively convenient ways of specifying operations – Strength and number of operators and predefined functions – e.g., notation count++ is more convenient and shorter than count = count + 1 Copyright © 2015 Pearson. All rights reserved. 1-25 Evaluation Criteria: Reliability A program is said to be reliable if it performs to its specifications under all conditions 1. Type checking – Type checking is simply testing for type errors in a given program, either by the compiler or during program execution – Run-time type checking is expensive, compile-time type checking is more desirable – The earlier errors in programs are detected, the less expensive it is to make the required repairs Copyright © 2015 Pearson. All rights reserved. 1-26 Evaluation Criteria: Reliability 2. Exception handling – The ability of a program to intercept run-time errors – Ada, C++, Java, and C# include extensive capabilities for exception handling, – nonexistent in some widely used languages, for example C. 3. Aliasing – Presence of two or more distinct referencing methods for the same memory location. E.g. pointers in C++, Array name is Java – Other languages greatly restrict aliasing to increase their reliability Copyright © 2015 Pearson. All rights reserved. 1-27 Evaluation Criteria: Reliability 4. Readability and writability – A language that does not support “natural” ways of expressing an algorithm will require the use of “unnatural” approaches, and hence reduced reliability – The easier a program is to write, the more likely it is to be correct – Programs that are difficult to read are difficult both to write and to modify Copyright © 2015 Pearson. All rights reserved. 1-28 Evaluation Criteria: Cost The total cost of a programming language is a function of many of its characteristics 1. Training programmers to use the language is a function of the simplicity and orthogonality 2. Writing programs is a function of the writability of the language 3. Compiling programs 4. Executing programs A language that requires many run-time type checks will prohibit fast code execution A simple trade-off can be made between compilation cost and execution speed of the compiled code Copyright © 2015 Pearson. All rights reserved. 1-29 Evaluation Criteria: Cost 5. Language implementation system: availability of free compilers A language whose implementation system is either expensive or runs only on expensive hardware will have a much smaller chance of becoming widely used 6. Reliability: poor reliability leads to high costs E.g. critical System 7. Maintaining programs The cost of software maintenance depends on a number of language characteristics, primarily readability Copyright © 2015 Pearson. All rights reserved. 1-30 Evaluation Criteria: Others 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 Copyright © 2015 Pearson. All rights reserved. 1-31 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 and by extension, new programming languages Copyright © 2015 Pearson. All rights reserved. 1-32 Computer Architecture Influence Well-known computer architecture: Von Neumann Imperative languages, most dominant, because of von Neumann computers – 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 efficient Copyright © 2015 Pearson. All rights reserved. 1-33 The von Neumann Architecture The von Neumann Architecture Copyright © 2015 Pearson. All rights reserved. 1-34 The von Neumann Architecture Fetch-execute-cycle (on a von Neumann architecture computer) initialize the program counter repeat forever fetch the instruction pointed by the counter increment the counter decode the instruction execute the instruction end repeat Copyright © 2015 Pearson. All rights reserved. 1-35 Programming Methodologies Influences 1950s and early 1960s: Simple applications; worry about machine efficiency Late 1960s: People efficiency became important; readability, better control structures – structured programming – top-down design and step-wise refinement Late 1970s: Process-oriented to data-oriented – data abstraction – The first language to provide even limited support for data abstraction was SIMULA 67 Middle 1980s: Object-oriented programming – Data abstraction + inheritance + polymorphism Copyright © 2015 Pearson. All rights reserved. 1-36 Language Categories Programming languages are often categorized into four bins: – Imperative – Functional – Logic – Markup/programming hybrid However, we do not consider languages that support object- oriented programming to form a separate category of languages. – We have described how the most popular languages that support object-oriented programming grew out of imperative languages – For example, the expressions, assignment statements, and control statements of C and Java are nearly identical Copyright © 2015 Pearson. All rights reserved. 1-37 Language Categories Imperative – Central features are variables, assignment statements, and iteration – Include languages that support object-oriented programming – Include scripting languages – Include the visual languages – Examples: C, Java, Perl, JavaScript, Visual BASIC.NET, C++ Functional – Main means of making computations is by applying functions to given parameters – Examples: LISP, Scheme, ML, F# Logic – Rule-based (rules are specified in no particular order) – Example: Prolog Markup/programming hybrid – Markup languages are not programming languages. – Markup languages extended to support some programming – Examples: HTML, XML, JSTL, XSLT Copyright © 2015 Pearson. All rights reserved. 1-38 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 – C does not require index range checking, so C programs execute faster than Java. – The designers of Java traded execution efficiency for reliability Readability vs. writability Example: APL provides many powerful operators (and a large number of new symbols), allowing complex computations to be written in a compact program but at the cost of poor readability Copyright © 2015 Pearson. All rights reserved. 1-39 Language Design Trade-Offs Writability (flexibility) vs. reliability – The conflict between writability and reliability is a common one in language design. – The pointers of C++ can be manipulated in a variety of ways, which supports highly flexible addressing of data. – Because of the potential reliability problems with pointers, they are not included in Java Copyright © 2015 Pearson. All rights reserved. 1-40 Implementation Methods There are three kinds of implementation methods: – Compilation – Pure Interpretation – Hybrid Implementation Systems Compilation – Programs are translated into machine language, which can be executed directly on the computer – has the advantage of very fast program execution, once the translation process is complete – such as C, COBOL, and C++, – Use: Large commercial applications Copyright © 2015 Pearson. All rights reserved. 1-41 Layered View of Computer Layered interface of virtual computers, provided by a typical computer system Copyright © 2015 Pearson. All rights reserved. 1-42 The Compilation Process Copyright © 2015 Pearson. All rights reserved. 1-43 Compilation Translate high-level program (source language) into machine code (machine language) Slow translation, fast execution Compilation process has several phases: – lexical analysis: converts characters in the source program into lexical units The lexical units of a program are identifiers, special words, operators, and punctuation symbols The lexical analyzer ignores comments in the source program Copyright © 2015 Pearson. All rights reserved. 1-44 Compilation – syntax analysis: transforms lexical units into parse trees which represent the syntactic structure of program E.g. x3 = y + 3. Copyright © 2015 Pearson. All rights reserved. 1-45 Compilation – Semantics analysis: generate intermediate code The intermediate code generator produces a program in a different language, at an intermediate level between the source program and the machine language program The semantic analyzer is an integral part of the intermediate code generator The semantic analyzer checks for errors, such as type errors – Optimization, which improves programs (usually in their intermediate code version) by making them smaller or faster or both. – code generation: translates the optimized intermediate code version of the program into an equivalent machine language program Copyright © 2015 Pearson. All rights reserved. 1-46 Additional Compilation Terminologies Load module (executable image): the user and system code together Linking and loading: the process of collecting system program units and linking them to a user program Copyright © 2015 Pearson. All rights reserved. 1-47 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 Copyright © 2015 Pearson. All rights reserved. 1-48 Pure Interpretation Programs are interpreted by another program known as an interpreter Interpreter is a software simulation of a machine whose fetch-execute cycle deals with high-level language program It provides a virtual machine for the language Some simple early languages of the 1960s (APL, SNOBOL, and Lisp) were purely interpreted Significant comeback with some Web scripting languages (e.g., JavaScript, PHP) Copyright © 2015 Pearson. All rights reserved. 1-49 Pure Interpretation Advantages: – No translation – Easier implementation of programs (run-time errors can easily and immediately be displayed) – E.g., if an array index is found to be out of range, the error message can easily indicate the source line of the error and the name of the array. Disadvantages – Use: Small programs or when efficiency is not an issue – Slower execution (10 to 100 times slower than compiled programs) – Regardless of how many times a statement is executed, it must be decoded every time. – Often requires more space (source code + symbol table during interpretation) Copyright © 2015 Pearson. All rights reserved. 1-50 Pure Interpretation Process Copyright © 2015 Pearson. All rights reserved. 1-51 Hybrid Implementation Systems A compromise between compilers and pure interpreters Use: Small and medium systems when efficiency is not the first concern A high-level language program is translated to an intermediate language that allows easy interpretation Faster than pure interpretation Copyright © 2015 Pearson. All rights reserved. 1-52 Hybrid Implementation Systems Examples – Perl programs are partially compiled to detect errors before interpretation – Initial implementations of Java were hybrid; the intermediate form, byte code, provides portability to any machine that has a byte code interpreter and a run-time system (together, these are called Java Virtual Machine) Copyright © 2015 Pearson. All rights reserved. 1-53 Hybrid Implementation Process Copyright © 2015 Pearson. All rights reserved. 1-54 Just-in-Time Implementation Systems 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 calls JIT systems are widely used for Java programs.NET languages are implemented with a JIT system In essence, JIT systems are delayed compilers Copyright © 2015 Pearson. All rights reserved. 1-55 Preprocessors Preprocessor macros (instructions) are commonly used to specify that code from another file is to be included A preprocessor processes a program immediately before the program is compiled to expand embedded preprocessor macros A well-known example: C preprocessor – expands #include, #define, and similar macros Copyright © 2015 Pearson. All rights reserved. 1-56 Programming Environments A collection of tools used in software development UNIX – An older operating system and tool collection – Nowadays often used through a GUI (e.g., CDE, KDE, or GNOME) that runs on top of UNIX Microsoft Visual Studio.NET – A large, complex visual environment – Used to build Web applications and non-Web applications in any.NET language (C#, VB.net, Jscript, F#, C++) NetBeans – development environment used for Java application but also supports JavaScript, Ruby, and PHP Copyright © 2015 Pearson. All rights reserved. 1-57 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 Copyright © 2015 Pearson. All rights reserved. 1-58

Use Quizgecko on...
Browser
Browser