Programming Paradigms

Similar documents
Introduction. A. Bellaachia Page: 1

Concepts of Programming Languages

Com S 541. Programming Languages I

What is a programming language?

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

8/27/17. CS-3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES

General Concepts. Abstraction Computational Paradigms Implementation Application Domains Influence on Success Influences on Design

Chapter 1. Preliminaries

Programming Languages 2nd edition Tucker and Noonan"

Programming Languages, Summary CSC419; Odelia Schwartz

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

INSTITUTE OF AERONAUTICAL ENGINEERING

Topic I. Introduction and motivation References: Chapter 1 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

Why study Programming Language Concepts? Chapter One. Language Evaluation Criteria. Programming Domains. Readability Writability Reliability Cost

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

CSC 326H1F, Fall Programming Languages. What languages do you know? Instructor: Ali Juma. A survey of counted loops: FORTRAN

Principles of Programming Languages. Lecture Outline

Chapter 1 Preliminaries

CS508-Modern Programming Solved MCQ(S) From Midterm Papers (1 TO 22 Lectures) BY Arslan

Chapter 1. Preliminaries

Concepts in Programming Languages

Imperative Programming

CSc 372. Comparative Programming Languages. 2 : Functional Programming. Department of Computer Science University of Arizona

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

Logic Programming II & Revision

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

Programmiersprachen (Programming Languages)

Chapter 2 Preview. Preview. History of Programming Languages. History of Programming Languages. History of Programming Languages

Chapter 5 Names, Binding, Type Checking and Scopes

6. Discuss how producer-consumer problem and Dining philosophers problem are solved using concurrency in ADA. [16]

Programming Language Concepts 1982, 1987, Outline. Period

Chapter 1. Preview. Reason for Studying OPL. Language Evaluation Criteria. Programming Domains

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

Chapter 5. Names, Bindings, and Scopes

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011

Low-Level Languages. Computer Programs and Programming Languages

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

Part (04) Introduction to Programming

Early computers (1940s) cost millions of dollars and were programmed in machine language. less error-prone method needed

Second-generation: Assembly language. Figure 6.1 Generations of programming languages. Assembly Language Characteristics.

Chapter 5 Names, Bindings, Type Checking, and Scopes

Semantic Analysis. How to Ensure Type-Safety. What Are Types? Static vs. Dynamic Typing. Type Checking. Last time: CS412/CS413

Chapter 6: Programming Languages

Introduction & Review

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

What Is Computer Science? The Scientific Study of Computation. Expressing or Describing

Informatica 3 Syntax and Semantics

Software II: Principles of Programming Languages. Why Expressions?

CSc 372 Comparative Programming Languages

COSC 2P90 Programming Languages & Object-Orientation

CSC 533: Organization of Programming Languages. Spring 2005

Evolution of PL s. EECS 476, Prog. Lang. Design/ page 1

Lecturer: William W.Y. Hsu. Programming Languages

CS383 PROGRAMMING LANGUAGES. Kenny Q. Zhu Dept. of Computer Science Shanghai Jiao Tong University

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

Concepts of Programming Languages

Chapter 2. Pseudocodes: Speedcoding. 2.2 Minimal Hardware Programming: Pseudocodes. Evolution of the Major Programming Languages

MIDTERM EXAMINATION - CS130 - Spring 2005

IA010: Principles of Programming Languages

Chapter 5. Variables. Topics. Imperative Paradigm. Von Neumann Architecture

10. Abstract Data Types

2. Evolution of the Major Programming languages

UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi

Chapter 2. 5 * B => A V 6 7 (subscripts) S 1.n 1.n (data types)

Thanks! Review. Course Goals. General Themes in this Course. There are many programming languages. Teaching Assistants. John Mitchell.

Computer Software: Introduction

CSCI 3136 Principles of Programming Languages

Outline. Introduction to Programming (in C++) Introduction. First program in C++ Programming examples

2 rd class Department of Programming. OOP with Java Programming

Lecture 6 Introduction to Objects and Classes

Introduction to Scientific Computing Languages

Seminar in Programming Languages

CS 3304 Comparative Languages. Lecture 1: Introduction

Fundamentals of Programming Languages. PL quality factors Lecture 01 sl. dr. ing. Ciprian-Bogdan Chirila

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

Topic 1: Introduction

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware

Functional Programming. Big Picture. Design of Programming Languages

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University

Introduction to Scientific Computing Languages

Chapter 7. Expressions and Assignment Statements ISBN

Chapter 11 :: Functional Languages

CSc 520 Principles of Programming Languages. 26 : Control Structures Introduction

Announcements Tues., Aug and 2. to call them ( ) ! For next time, read Learning Computing with Robots, chs.

Chapter 7. Expressions and Assignment Statements

! Broaden your language horizons. ! Study how languages are implemented. ! Study how languages are described / specified

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]

Chapter 6 Control Flow. June 9, 2015

Chapter 10 :: Data Abstraction and Object Orientation

COS 140: Foundations of Computer Science

CPS 506 Comparative Programming Languages. Programming Language

LECTURE 1. Overview and History

TYPES, VALUES AND DECLARATIONS

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Why are there so many programming languages?

G Programming Languages - Fall 2012

CSE 307: Principles of Programming Languages

9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5

Transcription:

Programming Paradigms Programming languages A Programming language is a notational system for describing tasks/computations in a machine and human readable form. Most computer languages are designed to facilitate certain operations and not others: numerical computation, or text manipulation, or I/O. More broadly, a computer language typically embodies a particular programming paradigm. Characteristics of a programming language: Every language has syntax and semantics: Syntax: The syntax of a program is the form of its declarations, expressions, statements and program units. Semantic: The semantic of a program is concerned with the meaning of its program. Which programming language? Since a task can be solved in different ways (paradigms), the language used to describe the solution differs in abstractions, structures due to the way in which the problem is solved. Abdelghani Bellaachia, Advanced Software Paradigms Page: 1

There is no theory that dictates the best paradigm to solve a particular problem. Efforts by Sebesta in his Concepts of Programming Languages book: o He based his evaluation criteria on three factors and 9 characteristics. o The three criteria (R,W,R) are: Readability Writability Reliability o The nine characteristics are: Simpilicity/orthogonality(R,W,R): - Orthogonality in a programming language means that 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 [Sebesta] - Relatively small set of primitive constructions combined in a number (of logically consistent) ways to provide the required control and data structures. - The concepts of a programming language do not interfere with each other: different methods of passing parameters. - Non-orthogonality: means exceptions to the general language rules, which make it harder to learn. It means that you cannot combine language features in all possible ways. - Examples of non-orthogonal languages: Arrays in Perl4 can't contain other arrays. In C, parameters can be passed by value, unless they are arrays, in which case they are passed by reference. Abdelghani Bellaachia, Advanced Software Paradigms Page: 2

In C++, we start a Switch statement by using the Switch keyword, followed by the expression that we would like to evaluate. This expression is just a single variable or a complex expression that must evaluatge to an integral type (that is, char, short, int, long, or enum). Floating point variables and other non-integral types may not be used here. o Good Orthogonality: Functional languages (Lisp, ML,etc.): everything is a function. o Given a programming language: m options on x axis n options on y axis Total number of possible interactions: mn interactions Total number of basic facts to learn: m+n facts Total number of exceptions: e exceptions Basic elements of the language: m+n+e facts and exceptions to be learned Total number of features: mn-e Objective: m+n+e << mn-e Control structures (R,W,R) Data types and structures (R,W,R): o Adequate data types help increase the readability of a programming language. o Example: Boolean data type: Abdelghani Bellaachia, Advanced Software Paradigms Page: 3

How do you interpret the followingstatement: visited = 1; o Is this an assignment or a conditional statement? Syntax design (R,W,R): o Special words which is easier to read: braces or if end if provided by Ada? Braces or Begin..end provided in Pascal. Support for abstraction (,W,R): o Ability to hide detail o Abstraction is an important factor in the writability of a language. o Two types of abstraction: process and data Process: subprograms and modules Data: structures, records, objects Expressivity (,W,R): o Programming languages with poor support for abstraction and weak primitives will have poor writability. o Short circuit evaluation for Boolean expressions: Ada uses and then and or else Java uses: && and (regular operator for and and or operators & and for short circuit evaluation Type checking (,,R) Exception handling (,,R) Restricted aliasing (,,R): o example: (C) Abdelghani Bellaachia, Advanced Software Paradigms Page: 4

int salary, *p_salary; salary = 98000; p_salary = &salary; salary and *p_salary are aliases. Maintainability o Factoring: The ability to group related features into a single unit. Use subroutines to group related computations units so they can be re-used in different parts of the application. o Locality: The ability to implement information hiding so that changes to a grouping (either control or data) are transparent. Cost o Programmer training o Software creation o Compilation o Execution o Compiler cost o Poor reliability o Maintenance Others: portability and generality Abdelghani Bellaachia, Advanced Software Paradigms Page: 5

Programming paradigms The paradigms are not exclusive, but reflect the different emphasis of language designers. Most practical languages embody features of more than one paradigm. Classification: Imperative/ Algorithmic Algol Cobol PL/1 Ada C Modula-3 Functional Programming Lisp Haskell ML Miranda APL Declarative Logic Programming Prolog Object-Oriented Smalltalk Simula C++ Java Imperative paradigms It is based on commands that update variables in storage. The Latin word imperare means to command. The language provides statements, such as assignment statements, which explicitly change the state of the memory of the computer. This model closely matches the actual executions of computer and usually has high execution efficiency. Many people also find the imperative paradigm to be a more natural way of expressing themselves. Abdelghani Bellaachia, Advanced Software Paradigms Page: 6

Functional programming paradigms In this paradigm we express computations as the evaluation of mathematical functions. Functional programming paradigms treat values as single entities. Unlike variables, values are never modified. Instead, values are transformed into new values. Computations of functional languages are performed largely through applying functions to values, i.e., (+ 4 5). Abdelghani Bellaachia, Advanced Software Paradigms Page: 7

Logic programming paradigms In this paradigm we express computation in exclusively in terms of mathematical logic. While the functional paradigm emphasizes the idea of a mathematical function, the logic paradigm focuses on predicate logic, in which the basic concept is a relation. Logic languages are useful for expressing problems where it is not obvious what the functions should be. For example consider the uncle relationship: a given person can have many uncles, and another person can be uncle to many nieces and nephews. Let us consider now how we can define the brother relation in terms of simpler relations and properties father, mother, and male. Using the Prolog logic language one can say: brother(x,y) /* X is the brother of Y */ /* if there are two people F and M for which*/ father(f,x), /* F is the father of X */ father(f,y), /* and F is the father of Y */ mother(m,x), /* and M is the mother of X */ mother(m,y), /* and M is the mother of Y */ male(x). /* and X is male */ The Object-Oriented Paradigm OO programming paradigm is not just a few new features added to a programming language, but it a new way of Abdelghani Bellaachia, Advanced Software Paradigms Page: 8

thinking about the process of decomposing problems and developing programming solutions Alan Kay characterized the fundamental of OOP as follows: Everything is modeled as object Computation is performed by message passing: objects communicate with one another via message passing. Every object is an instance of a class where a class represents a grouping of similar objects. Inheritance: defines the relationships between classes. The Object Oriented paradigm focuses on the objects that a program is representing, and on allowing them to exhibit "behavior". Unlike imperative paradigm, where data are passive and procedures are active, in the O-O paradigm data is combined with procedures to give objects, which are thereby rendered active. Concurrent programming Improve performance Multiprogramming systems attempt to utilize resources that would otherwise be wasted, by running two or more jobs concurrently. Multiaccess systems extend this principle, allowing many jobs to be run, each on behalf of a user at an interactive terminal. Concurrency can be classified into: Abdelghani Bellaachia, Advanced Software Paradigms Page: 9

o Apparent concurrency: single processor (interleaved execution of concurrent tasks) o Real concurrency: multiprocessor environment Issues: o How to synchronize the interactions among concurrently executing processes to maintain the internal data integrity. o Another problem is to schedule the racing processes for a limited set of shared resources. Abdelghani Bellaachia, Advanced Software Paradigms Page: 10