22
Programming Languages Lecture 1 Naveen Kumar

Lec 1 25_jul13

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Lec 1 25_jul13

Programming Languages

Lecture 1

Naveen Kumar

Page 2: Lec 1 25_jul13

The Study of Programming Languages

The purpose of language is simply that it must convey meaning (Confucius)

Whatever can be said, can be said clearly (Wittgenstein,1963)

A programming language is a notation for writing programs (Sethi,89)– program is a specification of a computation.2

Page 3: Lec 1 25_jul13

What is a programming language?

A language that is intended for the expression of computer programs and

that is capable of expressing any computer program

3Computer program is a specification of a computation.

Page 4: Lec 1 25_jul13

What is Programming Language

4

ComputerProgram

Programming Language

Output

use

giveswriteUser

executes

Problem

takes

Page 5: Lec 1 25_jul13

A short history of programming Languages

Early languages:– Numerically based languages. (FORTRAN:55,ALGOL:58)– Business languages. (COBOL:60)– Artificial intelligence languages. (LISP,Prolog)– Systems languages. (C:70)

1950 : LISP, FORTRAN, COBOL, ALGOL60, BASIC 1970 : Ada, C, Pascal, Prolog 1980 : C++ 1990 : Delphi, Perl 1996 : Java by James Gosling (at SUN Micro Systems)5

Page 6: Lec 1 25_jul13

Attributes of a good language

Clarity and simplicity– Readability

Naturalness for the application Ease of program verification

– Proof of correctness, test– Simplicity of semantic and syntax

Portability of programs Cost of use

– Program execution– Program translation– Program creation, testing, and use– Program maintenance6

Page 7: Lec 1 25_jul13

Programming Methodology

Kind of approach to solve different problems

How should programs be designed?

How should programs be structured?

Page 8: Lec 1 25_jul13

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

Late 1970s: Process-oriented (Goal or.) to data-oriented (DB or.)

– data abstraction

Middle 1980s: Object-oriented programming– Data abstraction + inheritance + polymorphism

Page 9: Lec 1 25_jul13

Kinds of Programming Methodology

Unstructured programming Procedural/Process oriented programming

– Modular programming Object-oriented programming

Page 10: Lec 1 25_jul13

Unstructured Programming

Direct code (step)

Ex: Assembly LanguageAdv. speed (written in assembly)Disadv. No re-usability Statements written many times As code increases, complexity increases

– Hard to manage large programs – Hard to debug

Page 11: Lec 1 25_jul13

Procedural oriented Programming

Top-down approach Procedure (Function) are building block De-allocation problem (memory leak: memory allocated

but not used) Un- initialized Variables (rand value assigned)Ex: Calculator → scientific

→ non-scientific → float→ int → add.

→ subs.→ mult.→ div.

Ex: C - language

Smallfunctions

Page 12: Lec 1 25_jul13

Procedural oriented Programming

Adv:– Re-usability– Easy to debug

Disadv:– Concentrate on what we want to do, not on who will use it– Data does not have a owner (sharing) – All functions are global– No data security

Ex: let there are three functions a(),b() and c(). Data d is used by a() and b() but how to restrict from c() [data will be either global or local]

– No data integrity [Stack:{push,pop},Queue:{enque, deque}] How to distinguish which fun associated with which data

structure

Page 13: Lec 1 25_jul13

Object-Oriented Programming

Keep large software projects manageable by human programmers

Bottom-up approach (user oriented) Objects are building block

Page 14: Lec 1 25_jul13

An Example

Everything in OOP is grouped as self sustainable "objects".

let’s take your “hand” as an example. – Your body has two objects of type hand, named left hand and

right hand. Their main functions are controlled/ managed by a set of electrical signals sent through your shoulders

– So the shoulder is an interface which your body uses to interact with your hands.

– The hand is being re-used to create the left hand and the right hand by slightly changing the properties of it.

14

Page 15: Lec 1 25_jul13

Another Example

Ex: college (Student, Faculty, Admin)

Student (take course, write exam, view indv. result)Faculty (set paper, prepare result, view results)Admin (student admission, staff/faculty selection)

15

Page 16: Lec 1 25_jul13

Why OOP?

Modularization Decompose problem into smaller

subproblems that can be solved separately.

16

Page 17: Lec 1 25_jul13

Why OOP?

Abstraction -- Understandability

Individual modules are understandable by human readers.

17

Page 18: Lec 1 25_jul13

Why OOP?

Encapsulation -- Information Hiding

Hide complexity from the user of a software. Protect low-level functionality.

18

Page 19: Lec 1 25_jul13

Why OOP?

Composability -- Structured Design

Interfaces allow to freely combine modules to produce new systems.

19

Page 20: Lec 1 25_jul13

Why OOP?

Hierarchy

Incremental development from small and simple to more complex modules.

20

Complexityincreases

Page 21: Lec 1 25_jul13

Why OOP?

Continuity

Changes and maintenance in only a few modules does not affect the architecture.

21

Page 22: Lec 1 25_jul13

Main OOP Language Features

Classes: Modularization, structure. Inheritance / extends: Hierarchy of modules,

incremental development. Public / Protected / Private: Encapsulation. Interfaces / Abstract Classes: Composability. Polymorphism / virtual: Hierarchy of modules,

incremental development. Templates: Type independent abstract data

types. 22