0% found this document useful (0 votes)
85 views

Programming Language and Paradigms

Uploaded by

M.Thenmozhi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views

Programming Language and Paradigms

Uploaded by

M.Thenmozhi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 28

Programming Language and

Paradigms
Introduction
Topics

• A brief history of programming languages


• Why study programming languages?
• The art of language design
• Language evaluation criteria
• Programming language paradigms
• Programming environments

2
PROG0101 Fundamentals of Programming

Computer Program

• A program is a set of instructions following the rules


of the chosen language.
• A program is like a recipe.

• It contains a list of ingredients (called variables) and


a list of directions (called statements) that tell the c
omputer what to do with the variables.

3
PROG0101 Fundamentals of Programming

Programming Language
• A vocabulary and set of grammatical rules (syntax)
for instructing a computer to perform specific tasks.
• Programming languages can be used to create co
mputer programs.
• The term programming language usually refers to
high-level languages, such as BASIC, C, C++, CO
BOL, FORTRAN, Ada, and Pascal.

4
A Brief History of
Programming Languages
Brief history: Machine language
• Machine language – the sequence of bits that
directly controls a processor
• Add, compare, move data from one place to another,
and so forth at appropriate times

55 89 e5 53 83 ec 04 83 e4 f0 e8 31 00 00 00 89 c3 e8 2a 00
00 00 39 c3 74 10 8d b6 00 00 00 00 39 c3 7e 13 29 c3 39 c3
75 f6 89 1c 24 e8 6e 00 00 00 8b 5d fc c9 c3 29 d8 eb eb 90

GCD program in machine language for the x86 (Pentium)


instruction set, expressed as hexadecimal (base 16) numbers

6
Brief history: Assembly language
• Assembly language – expressed with mnemonic
abbreviations, a less error-prone notation
pushl % ebp jle D
movl %esp, %ebp subl %eax, %ebx
pushl %ebx B: cmpl %eax, %ebx
subl $4, %esp jne A
andl $-16, %esp C: movl %ebx, (%esp)
call getint call put int
movl %eax, %ebx movl -4(%ebp), %ebx
call getint leave
cmpl %eax, %ebx ret
je C D: subl %ebx, %eax
A: cmpl %eax, %ebx jmp B

GCD program in assembly language for the x86.


7
Brief history: Assembly language
• One-to-one correspondence between mnemonics
and machine language instructions
• Assembler – system program for translating from
mnemonics to machine language
• Machine-dependent language – rewrite programs
for every new machine
• Difficult to read and write large programs

8
Brief history: high-level language
• Fortran – first high-level language in the mid-
1950s
• Machine-independent language
• Compiler – system program for translating
from high-level language to assembly or
machine language
• Not one-to-one correspondence between
source and target operations.

9
Why Study Programming
Languages?
Why study programming languages?
• Understand obscure features
• Choose among alternative ways to express things
• Simulate useful features in languages that lack
them
• Make it easier to learn new languages
• Help you choose a language

11
The Art of Language Design
What is a language for?

• Way of thinking – way of expressing algorithms


• Languages from the user's point of view
• Abstraction of virtual machine – way of specifying
what you want the hardware to do without getting
down into the bits
• Languages from the implementer's point of view

13
Why are there so many?
• Evolution - learn better ways of doing things over time
– goto-based control flow (Fortran)
– structured programming (Pascal, C)
– object-oriented structure (C++, Java)
• Special purpose
– symbolic data
– character strings
– low-level system programming
– reasoning, logical relation
• Socio-economic factors - proprietary interests, commercial advantage
• Personal preference - diverse ideas about what is pleasant to use
• Special hardware

14
What makes a language successful?
• Expressive power – easy to express things, to use once fluent (C, APL,
Algol-68, Perl)
• Ease of use for novice – easy to learn (BASIC, Pascal, LOGO)
• Ease of implementation – (BASIC, Forth)
• Standardization – (C, Java)
• Open source - wide dissemination without cost (Pascal, Java)
• Excellent compilers – possible to compile to very good (fast/small)
code (Fortran)
• Patronage - backing of a powerful sponsor (COBOL, PL/1, Ada, Visual
Basic)

15
Language Evaluation Criteria
Language Evaluation Criteria
• Readability: the ease with which
programs can be read and understood
• Writability: the ease with which a
language can be used to create programs
• Reliability: conformance to specifications
(i.e., performs to its specifications under
all conditions)

17
Evaluation Criteria: Others
• Cost
– the ultimate total cost
• 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

18
Programming Paradigms
• Imperative
– Central features are variables, assignment statements, and iteration
– Examples: C, Pascal
• Object-oriented
– Data abstraction (Encapsulate data objects with processing) ,
inheritance, dynamic type binding
– Examples: Java, C++
• Functional
– Main means of making computations is by applying functions to
given parameters
– Examples: LISP, Scheme
• Logic
– Rule-based (rules are specified in no particular order)
– Example: Prolog
• Markup
– New; not a programming per se, but used to specify the layout of
information in Web documents
– Examples: XHTML, XML
19
Programming Language
Paradigms
IMPERATIVE PROGRAMMING PARADIGM
 Imperative programming is a programming paradigm that uses
statements that change a program's state.
 An imperative program consists of commands for the computer to
perform.
 Imperative programs describe the details of HOW the results are to
be obtained.
 HOW means describing the Inputs and describing
how the Outputs are produced.
 Examples are: C, C++, Java, PHP, Python, Ruby etc.
DECLARATIVE PROGRAMMING PARADIGM

 Declarative programming is a programming paradig


m—a style of building the structure and elements of
computer programs—that expresses the logic of a c
omputation without describing its control flow.
 Declarative programming focuses on what the progr
am should accomplish.
 Declarative programming often
considers programs as theories of a formal logic, and
computations as deductions in that logic space.
 Examples are: SQL, XSQL (XMLSQL) etc.
FUNCTIONAL PROGRAMMING PARADIGM

 Functional programming is a subset of declarative


programming.

 Programs written using this paradigm use functions, blocks of


code intended to behave like mathematical functions.

 Functional languages discourage changes in the value of vari


ables through assignment, making a great deal of use of recu
rsion instead.
 Examples are : F#, Haskell, Lisp, Python, Ruby,
JavaScript etc.
OBJECT ORIENTED PROGRAMMING PARADIGM
 Object-oriented programming (OOP) is a program
ming paradigm based on the concept of "objects",
which may contain data, in the form of fields, often
known as attributes; and code, in the form of proce
dures, often known as methods.
 There is significant diversity of OOP languages, but
the most popular ones are class-based, meaning t
hat objects are instances of classes, which typicall
y also determine their type.
 In OOP, computer programs are designed by
making them out of objects.
 Examples are: C++, C#, Java, PHP, Python.
MULTI PARADIG
M
 A multi-paradigm programming language is a progr
amming language that supports more than one pro
gramming paradigm.
 The design goal of such languages is to allow prog
rammers to use the most suitable programming sty
le and associated language constructs for a given j
ob.
 Languages such as C++, Java, Python
are multi- paradigm programming languages that s
upport object-oriented programming to a greater or
lesser degree, typically in combination with imperat
ive, procedural programming.
A Glance of different paradigm
s
Paradigm Description Pro Examples
grams as statements th
at directly change C, C++, Java, PHP
Imperative
computed state ,
(datafields). Python, Ruby.

Treats computation as the


Functional C++, Lisp, Python, JavaS
evaluation of mathematical
functions avoiding state. cript

Treats datafields as object


Object-oriented s manipulated through p C++, C#., Java, PHP,
Python .
redefined methods only

Declarative Defines program logic, but


not detailed control flow SQL, CSS.
Example of GCD program
int gcd(int a, int b) { (define gcd
while (a!=b) { (lambda (a b)
if (a>b) a = a-b; (cond ((= a b) a)
else b = b-a; ((> a b) (gcd (- a b) b))
} (else (gcd (- b a) a)))))
return a;
} //C ;scheme

gcd(A,B,G) :- A = B, G=A.
gcd(A,B,G) :- A > B, C is A-B, gcd(C,B,G).
gcd(A,B,G) :- B > A, C is B-A,
gcd(C,A,G). %Prolog

Copyright © 2009 Elsevier, Inc. All rights reserved. 27


Programming Domains
• Scientific applications
– Large number of floating point computations
– Fortran
• Business applications
– Produce reports, use decimal numbers and characters
– COBOL
• Artificial intelligence
– Symbols rather than numbers manipulated
– LISP
• Systems programming
– Need efficiency because of continuous use
– C
• Web Programming
– Eclectic collection of languages: markup (e.g., XHTML), scripting
(e.g., PHP), general-purpose (e.g., Java)
28

You might also like