Basics of ProgrammingParadigms
Programming Paradigm
– Programming paradigms are a way to classify programming languages based on
their features. -wikipedia
– Programming paradigms are different ways or styles in which a given program or
programming language can be organized.
– There are many programming languages. Each has its own strategy
(methodology) when it is implemented. That strategy is what known as
paradigms
– Programming paradigms are not languages or tools.
Imperative Programming Paradigm
•It is one of the oldest programming paradigm
• close relation to machine architecture-based on Von
Neumann architecture
• An imperative program consists of commands for
the computer to perform. Imperative programming
focuses on describing how a program operates step by
step, rather than on high-level descriptions of its
expected results.
• Statements or commands are used to change the state
• Result can be achieved after executing several statements
Procedural Programming
• Proceduralprogramming is a programming
paradigm, derived from imperative
programming, based on the concept of
the procedure call. Procedures (a type of
routine or subroutine) simply contain a series
of computational steps to be carried out.
• It has the ability to reuse the code
9.
Object Oriented Programming
•Object-Oriented Programming (OOP) is
a programming paradigm based on the
concept of "objects", which can
contain data and code. The data is in the form
of fields (often known
as attributes or properties), and the code is in
the form of procedures (often known
as methods).
• Example C++,java,Python
10.
Concurrent Programming
• Concurrentcomputing is a form of modular
programming. In its paradigm an overall
computation is factored into sub computations
that may be executed concurrently.
• instead of sequentially
• A parallel processing system posses many
numbers of processor with the objective of
running a program in less time by dividing them.
• C, C++ java python
11.
Declarative programming paradigm
•that expresses the logic of a computation without
describing its control flow.
• The focus is on what needs to be done rather how
it should be done
• States the goal to be achieved explicitly
• The procedure of how to achieve is not given
explicitly
• therefore it considers programs as theories of
some logic (Mathematics / Data / Known facts)
Logic Programming Paradigm
•In logic programming we have a knowledge
base which we know before and along with
the question and knowledge base which is
given to machine, it produces result.
14.
Functional programming paradigms
•The central model for the abstraction is the
function which are meant for some specific
computation and not the data structure.
• Data are loosely coupled to functions.
• Function can be replaced with their values
without changing the meaning of the
program.
• Example perl, javascript
15.
Database/Data driven programming
approach
•This programming methodology is based on
data and its movement
• file creation, data entry, update, query and
reporting functions.
• Example :SQL
16.
Expression Semantics
• Operandsand operator
• Way to use operator and operands
• Representation
– Infix postfix prefix
• Example
– my_func(A, B, C)
a + b //c
"+"(a, b) //ada
17.
Expression Semantics
• Precedenceand Associativity
– Priority
– (a+b)*d*d/(d-1)
• Assignments
• Each assignment takes a pair of arguments: a value and a reference to a
variable into which the value should be placed.
• References and Values
– Consider the following assignments in C:
– L-values and r-values
– d = a;
– a = b + c;
18.
Expression Semantics
• Representation
–Infix postfix prefix
• Infix-Binary operators
• Postfix-Unary operator
• Precedence and Associativity-evaluation orders and Left to
right
– a + b * c**d**e/f?
– ((((a + b) * c)**d)**e)/f
– or
– a + (((b * c)**d)**(e/f))
– or
– a + ((b * (c**(d**e)))/f)
19.
• Compound assignment
•Pre post increment
• Multiway assignment
– a, b := c, d;
– a, b, c := foo(d, e, f);
20.
• Type Checking
–Compile time
• Definition of Types
– Denotational –simple set of values
– Constructive primitive Int float char
– abstraction-based derived
21.
• Classification oftypes
– Numeric type
– Enumeration Type
– Subrange type
• type test_score = 0..100;
– workday = mon..fri;
22.
• Composite Types
•Records-Collection of fields
• Variant records
• Arrays
• Sets,
• Pointers
• Lists,
• Files
23.
Data Semantics
• Datasemantics is the study of the meaning
and use of specific pieces of data in
computer programming and other areas that
employ data
24.
Integer
Almost alwaysan exact reflection of the
hardware so the mapping is trivial
There may be as many as eight different
integer types in a language
Java‘s signed integer sizes: byte, short, int,
long
25.
Floating Point
• Modelreal numbers, but only as
approximations
• Languages for scientific use support at least
two floating-point types (e.g., float and
double; sometimes more
• Usually exactly like the hardware, but not
always
• IEEE Floating-Point Standard 754
26.
Complex
• Some languagessupport a complex type, e.g.,
Fortran and Python
• Each value consists of two floats, the real part
and the imaginary part
• Literal form (in Python):
• (7 + 3j), where 7 is the real part and 3 is the
imaginary part
27.
Decimal
• For businessapplications (money)
• Essential to COBOL
• C# offers a decimal data type
• Store a fixed number of decimal digits, in
coded form
• Advantage: accuracy
• Disadvantages: limited range, wastes memory
28.
Boolean
• Simplest ofall
• Range of values: two elements, one for “true”
and one for “false”
• Could be implemented as bits, but often as
bytes
• Advantage: readability
29.
Character
• Stored asnumeric coding
• Most commonly used coding: ASCII
• An alternative, 16-bit coding: Unicode
• Includes characters from most natural
languages – Originally used in Java
• C# and JavaScript also support Unicode
30.
Character String Types
•Values are sequences of characters
• Design issues: – Is it a primitive type or just a
special kind of array?
• Should the length of strings be static or
dynamic?
31.
Character String Typein Certain Languages
• C and C++ – Not primitive – Use char arrays
and a library of functions that provide
operations
• Fortran and Python – Primitive type with
assignment and several operations
• Java – Primitive via the String class
32.
Character String LengthOptions
• Static: COBOL, Java‘s String class
• Limited Dynamic Length: C and C++
In these languages, a special character is used to indicate the
end of a string‘s characters, rather than maintaining the length
• Dynamic (no maximum): SNOBOL4, Perl,
JavaScript
• Ada supports all three string length options
33.
Implementation
• Static length:compile-time descriptor
• Limited dynamic length: may need a run-time
descriptor for length (but not in C and C++)
• Dynamic length: need run-time descriptor;
allocation/de-allocation is the biggest
implementation problem
34.
Array Types
• Anarray is an aggregate of homogeneous data
elements in which an individual element is
identified by its position in the aggregate,
relative to the first element
35.
Array Design Issues
•What types are legal for subscripts?
• Are subscripting expressions in element
references range checked?
• When are subscript ranges bound?
• When does allocation take place?
• What is the maximum number of subscripts?
• Can array objects be initialized?
• Are any kind of slices supported?
36.
Record Types
• Arecord is a possibly heterogeneous
aggregate of data elements in which the
individual elements are identified by names.
37.
Pointer and ReferenceTypes
• A pointer type variable has a range of values
that consists of memory addresses and a
special value, nil
• Provide the power of indirect addressing
Provide a way to manage dynamic memory
A pointer can be used to access a location in
the area where storage is dynamically created
(usually called a heap)
38.
Design Issues ofPointers
• What are the scope of and lifetime of a pointer variable?
• What is the lifetime of a heap-dynamic variable?
• Are pointers restricted as to the type of value to which they
can point?
• Are pointers used for dynamic storage management, indirect
addressing, or both?
• Should the language support pointer types, reference types,
or both?
39.
UNIT 1
Imperative Designprinciples – Structured, Turing Complete, Modularity,
Procedural abstraction, Structured Theorem - Sequencing, Selection, Iteration
and Recursion
Structured
• Structured Analysisis a development method that
allows the analyst to understand the system and its
activities in a logical way.
• It is graphic which specifies the presentation of application.
• It divides the processes so that it gives a clear picture of system flow.
• It is logical rather than physical i.e., the elements of system do not
depend on vendor or hardware.
• It is an approach that works from high-level overviews to lower-level
details
Turing completeness
A computationalsystem that can compute every Turing-computable
function is called Turing-complete (or Turing-powerful).
Alternatively, such a system is one that can simulate a universal
Turing machine. Flow of control, control execution, repetition.
Alan Turing. a limited set of states, an infinite
amount of storage, and a
transition function.
44.
examples
• Many proceduralprogramming languages, including C and
Pascal.
• Most object-oriented programming languages, such as Java and
C++.
• Logic programming languages, such as Prolog.
• HTML,XML,JSON - Non turning complete
• Compliers ,interprestes – Non-turning complete
• Excel,PPT – turning complete
C, C++, Java, Python, Go, Visual Basic,
Ruby, Pascal, Fortran, COBOL
•Fully orthogonal languagesare often considered more expressive and
flexible, as programmers have greater freedom in how they construct
programs.
•Non-orthogonal languages can be more complex to learn and use, as there
are more rules and exceptions to remember.
•Quasi-orthogonal languages strike a balance between orthogonality and
practicality, providing a good compromise between expressiveness and
complexity.
•Uniform Syntax: Thesame syntax is used for defining functions, calling
functions, and performing arithmetic operations.
•First-Class Functions: Functions can be passed as arguments to other
functions, returned as values, and assigned to variables, making them
interchangeable with other data types.
•Consistent Evaluation: The evaluation of expressions follows a consistent
order, regardless of the type of expression.
Combination Assignment Operators
•Updating assignment
• a = a + 1;
• clutter free
• compile- or run-time cost of redundant
address calculations reduction
• to avoid the issue of repeated side effects
• a += 1;
58.
• Compound assignmentx += 1 // x = x + 1
• Pre post increment
• Multiway assignment
– a, b := c, d; a := c; b := d; // clu
– Used in ML – Pattern Matching Mechanisms
60.
Summary
• Expression Evaluation
–Representation -infix post fix pre fix
– Order of Evaluation -precedence
– Associativity –left to write or write to left
– Orthogonal
– Assignment
• Simple
• Compound
• Multiple
What is ?
•Only one entry and exit is to be used.
• None of the constructs sequence selection and repetition consists of more
than three boxes.
• If we visualize any one of the three constructs as they are used then a third
characteristic is evident.
• The entry is the start and the exit is at the end.
• clarity, quality, and development time
• Hypotheses and conclusion
•C
•C++
•Java
•C#,PASCAL,ALGOL,MODULE 2
64.
Four Principles
• Standardization.if then else and while
do
• Abstraction.(Subsystem as blackbox)
• Expressive Power.(while or recursion)
• Orthogonality.(minimum no of
functions)
• Minimality.
65.
Advantages
• Application programsare easier to read
and understand.
• Application programs are less likely to
contain logic errors.
• Errors are more easily found.
• Higher productivity during application
program development.
• Improved application program design.
66.
Disadvantage
1. Since itis Machine-Independent, So it takes time to convert into
machine code.
2. The converted machine code is not the same as for assembly
language.
3. The program depends upon changeable factors like data-types.
Therefore it needs to be updated with the need on the go.
4. Usually the development in this approach takes longer time as it
is language-dependent. Whereas in the case of assembly
language, the development takes lesser time as it is fixed for the
machine.
Sequence
• Selection ofan appropriate order in which no
of jobs (operations) can be assigned to a
finite no of service facilities(machines) so as
to optimize the outputs in terms of time, cost
or profit.
70.
Selection
• Simple selection(simple IF statement)
• Simple selection with null false branch
(null ELSE statement)
• Combined selection (combined IF
statement)
• Nested selection (nested IF statement)
Iteration
• is aprocess wherein a set of
instructions or structures are repeated
in a sequence a specified number of
times or until a condition is met.
Recursion
• Recursion isalso repeating code, but it calls
the same function again until the necessary
criteria are met.
• While iteration is used for much simpler
purposes, we repeat the same block of
code until the conditions are met