Everything you do now is for your future. Think About that.
--Your friends at LectureNotes

Note for Principles of Programming Languages - ppl By p v

  • Principles of Programming Languages - ppl
  • Note
  • 21 Offline Downloads
  • Uploaded 5 months ago
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-2

memory. Continues translating the program until the first error is met, in which case it stops. Hence debugging is easy. It generates the error message only after scanning the whole program. Hence debugging is comparatively hard. Programming language like Python, Ruby use interpreters. Programming language like C, C++ use compilers. 3. Compute the weakest precondition of the following assignment: a = 2 * (b-1)-1 (a>0) ANS: a>0 2*(b-1)-1>0 2*(b-1)>1 2*b-2>1 2b>3 b>3/2 4. Explain the evolution of various programming language paradigms in detail with suitable examples. The programming paradigms which are most widely used and implemented by various programming languages are: • • • • • Imperative programming Object-oriented programming (OO) Functional programming (FP) Generic programming (GP) Meta-programming (MP) 1.Imperative programming is a paradigm of computer programming in which the program describes a sequence of steps that change the state of the computer. Unlike declarative programming, which describes "what" a program should accomplish, imperative programming

Text from page-3

explicitly tells the computer "how" to accomplish it. Programs written this way often compile to binary executables that run more efficiently since all CPU instructions are themselves imperative statements. To make programs simpler for a human to read and write, imperative statements can be grouped into sections known as code blocks. In the 1950s, the idea of grouping a program's code into blocks was first implemented in the ALGOL programming language. They were originally called "compound statements," but today these blocks of code are known as procedures. Once a procedure is defined, it can be used as a single imperative statement, abstracting the control flow of a program and allowing the developer to express programming ideas more naturally. This type of imperative programming is called procedural programming, and it is a step towards higherlevel abstractions such as declarative programming. Imperative programming languages • • Ada ALGOL 2.The object-oriented programming paradigm introduced mechanisms required to obtain modular software design and reusability compared to universal accessibility of implementations by imperative programming. The main part of the object-oriented paradigm is related to the introduction of classes which cover basic properties of concepts to be implemented. Based on this description of properties, an object is created, which can be briefly explained by a selfgoverning unit of information which actively communicates with other objects. This is the main difference compared to a passive access as used in imperative programming languages. The concept of inheritance was introduced due to the fact that a particular concept, e.g., a mathematical -dimensional vector, cannot be described in its generality by a single class. By inheritance, semantically related concepts can be implemented in a class from which other classes can be derived, which should enable means of code reusability. • The first source snippet presents an implementation of the given problem in a fully object-oriented language, Java. 3.Functional Programming A different type of programming paradigm is functional programming, where computation is treated as the evaluation of functions based on the following properties: • • Objects are provided only as constants or as expressions on objects. Functional programming avoids states of objects and mutable data. Loops therefore have to be replaced by recursion.

Text from page-4

An important part of functional programming related to high performance is the delayed or lazy evaluation. This means that the moment in which a function is bound with some of its arguments can be separated from the one in which it is evaluated, thereby supporting the following techniques: • • Partial binding and partial evaluation, e.g., a binary function where one of the arguments is already bound to the function and only one parameter has to be specified to finally evaluate the function. Lambda expressions, based on the lambda calculus , use partial binding to define the • expression , with the reserved prefix , followed by the formal parameters, a dot, and the function definition. Currying, which creates unnamed lambda expressions automatically. An implementation of the given problem is presented in the following source snippet using Haskell as the host language. This programming paradigm, with the corresponding purely functional programming languages, such as Haskell, is currently widely used in the area of mathematical modeling. The static type mechanism and the generic mechanism, e.g., the availability of return type deduction, which goes beyond the capabilities of, e.g., C++, is an important feature and advantage of this language. 4.Generic Programming Generic programming denotes (object-oriented) programming methods based on the mechanism of parametric polymorphism of data structures and algorithms to obtain orthogonality, while avoiding the performance drawback of virtual function call costs in C++. The generic programming paradigm thereby establishes homogeneous interfaces between algorithms and data structures without sub-typing polymorphism by an abstract access mechanism, the STL iterator concept. This concept specifies an abstract mechanism for accessing data structures in a concise way. 5.Meta-Programming

Text from page-5

The paradigm of meta-programming can be briefly explained as writing a computer program that writes or manipulates other programs or themselves. For programming tasks which have to be repeated a great number of times, this paradigm can be used to obtain an efficient implementation . Template meta-programming is a type of meta-programming in which the template (parametric polymorphism) system of the host language is used. The compiler uses these templates to generate new source code at compile-time. Template meta-programming is currently implemented by various programming languages, such as C++, Haskell, or D . Here, only the implementation of this paradigm in C++ is used. C++ implements a Turing-complete template system, which means that any computation is expressible. In contrast to run-time programming, template meta-programming has non-mutuable variables and therefore requires the functional programming paradigm, most often used by recursion patterns. 5. Write any important uses of programming language. Programmers use programming languages to communicate with computers. Many different languages exist, and each one has its own unique features, though they all share some similarities. Because each language is different, each may be best suited for a certain purpose or purposes within certain industries. Some programming languages are used to create programs to solve problems or interpret data. Other programming languages are more suitable for making create software or apps that entertain. With a strong need for unique and diverse programming languages, it is virtually impossible to create a single universal programming language that meets all needs. Programming languages are often revised and even combined with other languages over time, evolving to meet our changing technological needs. Programming Languages • • • • Python is an open-source programming language used by software engineers and backend Web developers. Python is well-suited for scientific computing, and it is relatively simple to learn. Java is prevalent in Web-based development, and it was created in 1995. Many companies in the health sciences, education, and finance industries use Java. Java enables the downloading of applets from websites, which enable browsers to perform additional functions. Ruby is an open-source scripting language that coders can use independently or in conjunction with Ruby on Rails. NASA uses Ruby in its work with simulations. HTML is used extensively in Web development. HTML is the code that serves as the foundation of Web pages, allowing people to create and structure electronic documents for viewing online.

Lecture Notes