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

1 Introduction ProgrammingParadigm

Uploaded by

HAO
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

1 Introduction ProgrammingParadigm

Uploaded by

HAO
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

CT006-3-3 & Advanced Programming Language Concepts

Introduction to Programming Paradigm

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 1
TOPIC LEARNING OUTCOMES

At the end of this topic, you should be able to:


• Understand the programming paradigms
• Explain imperative and declarative programming

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 2
Contents & Structure

 Programming paradigm
 Definition
 Programming paradigm categories
 Imperative programming
 Declarative programming (logic, data driven, functional)
 Origin of functional programming
 Why functional programming

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 3
Serial Computing

Parallel Computing

Adapted from https://computing.llnl.gov/tutorials/parallel_comp/


4

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 4
4. Computational speed
4.3 Introduction to space-time diagram

Space- time diagram of a message- passing program

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 5
Change, change, change...
Change is always a fact of life.

Organizations under pressure to change and adapt.

To stay competitive, it must be agile.

The COVID-19 pandemic caused changes in regulatory policy, market uncertainty,
disruption of production and supply chains..

Changes in organizations policy and functionality.

Organization functionality change so are the underlying software.

Software to adapt swiftly and effectively to changes is a crucial factor that separates
successful organizations

CMM/CMMI Level 5: Optimizing, stress on organization capability to manage change
without defect in continuous process improvement to achieve organizational innovation
and deployment.

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 6
Change is tough

Huge costs in rework and interruptions for users of the software.

Affects how software is maintained and bang up to date.

Software maintenance is the task of modifying an existing software
systems to correct defects, improve performance or adapt it to the new
environment.

Without maintenance, systems would become rapidly out-of-date and
inefficient.

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 7
Software Maintenance
The Department of Defense (DoD) defines software maintenance in DoD Instruction
4151.20 as follows [USDAS 2018]:
Software Maintenance: Includes actions that change the software baseline (adaptive,
corrective, perfective, and preventative) as well as modification or upgrade that add
capability or functionality. Encompasses requirements development, architecture and
design, coding, and integration and test activities. Software maintenance and software
sustainment are considered synonymous.

Corrective sustainment activities diagnose and correct software errors after the
software is released.

Perfective sustainment activities consist of upgrades to software to support new
capabilities and functionality.

Adaptive sustainment activities modify software to interface with changing
environments.

Preventive sustainment activities modify software to improve future maintainability or
reliability.
CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 8
Maintainability
Maintainability (maintenance effort) is the most time consuming part of software life
cycle which can range from 65% to 75% of total software development time.

ISO/IEC 25010 defines five components for the maintainability: analyzability,
modifiability, modularity, reusability and testability.

Here, we focus on the software analyzability and modifiability.

Analyzability covers assessing the impact of an intended change, diagnosing
deficiencies and failures, and identifying parts to be modified.

Modifiability covers work needs to be done to implement a modification and the steps
taken to make designs more adaptable and ease the implementation of changes that
improve maintainability.

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 9
Design principles in application design
In general, what we need is a programming paradigm that
encourages us to think carefully about our data and the functions
that interact with it. When considering the design of your application,
ask yourself the following questions based on these design
principles:

 Extensibility - Am I continually refactoring my code to support


additional functionality?
 Ease of modularization – If I change one file, will it affect
another?
 Reusability - Is there a lot of duplication?
 Testability - Will it be difficult to unit test my functions?
 Ease of reasoning – Is my code unstructured and difficult to
understand? [1]
CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 10
Paradigm
Paradigm:
A set of assumptions, concepts, values, and practices that
constitutes a way of viewing reality for the community that shares
them, especially in an intellectual discipline.

A paradigm is a framework that expresses a particular set of


assumptions, relies on particular ways of thinking through problems,
and uses particular methodologies to solve those problems.

The functional programming paradigm is a framework that


expresses a particular set of assumptions, relies on particular ways
of thinking through problems, and uses particular methodologies to
solve those problems.

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 11
Programming paradigm explained
 The focus is on programming concepts and techniques for using them, not programming
languages. These concepts are organized by model of computation. A computation model is a
formal system that defines how computations are done.
 There are many ways to define a model of computation. To be directly useful to
programmers, it is defined in terms of concepts that are important to programmers: data types,
operations, and programming language. Programmers need programming techniques and
design principles implemented by computational models [2].
 A programming paradigm is an approach to programming a computer based on a
mathematical theory or a coherent set of principles. Each paradigm supports a set of
concepts that makes it the best for a certain kind of problem [3].
 Programming paradigms are different ways or styles in which a given program or
programming language can be organized. Each paradigm consists of certain structures,
features, and opinions about how common programming problems should be tackled.
 Solving a programming problem requires choosing the right concepts. All but the smallest
toy problems require different sets of concepts for different parts. This is why programming
languages should support many paradigms. For example, object-oriented programming is best
for problems with a large number of related data abstractions organized in a hierarchy. Logic
programming is best for transforming or navigating complex symbolic structures according to
logical rules.
CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 12
Programming paradigm explained - contd
 Programming paradigms classify programming languages according to their features.
However, some languages may be classified into multiple paradigms – as is the case of
JavaScript itself!
 A primary division is imperative versus declarative languages. In the former, developers
must instruct the machine on how to do its work, step by step. Programming may be
procedural (if instructions are grouped into procedures) or object-oriented (if instructions are
grouped with a related state).
In declarative languages, in opposition, developers just declare properties that the sought result
must satisfy, but not how to calculate it. Declarative languages may be logic-based (based on
logic rules and constraints), reactive (based on data and event streams), or functional (based
on the application and combination of functions). In a sense, we could say that imperative
languages focus on how, while declarative languages focus on what. [5]

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 13
Programming paradigm explained

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 14
 [2,4]

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 15
Imperative programming paradigm

 Imperative programming implements algorithms in explicit steps.


 It is based on changing the program states.
 Main focus:
 How to achieve the goal
 Advantages:
 Very simple to implement based on logical thinking skills
 It contains loops, variables and etc.
 Disadvantages:
 Complex problem cannot be solved effectively
 Less efficient and productive
 Parallel processing not possible

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 16
Imperative programming code examples

var name = "Sponge Bob";


var greeting = "Hi, ";
console.log(greeting + name);

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 17
Declarative programming paradigm

 It is special style of building programs that expresses logic of


computation without talking about its control flow.
 The declarative programs are said to be theories of logic.
 Main focus: what tasks need to be done rather than how it is being
done.
 Advantages:
 High level of abstraction
 Independent maintenance
 Efficient solution outline - prototyping
 Disadvantages:
 Difficult to understand the conceptual model

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 18
Logic programming

 Also, abstract model of computation


for solving logical problems.
 A knowledgebase is required be
servicing the queries for
solutions/results.
 it emphasizes on knowledgebase
and the problem therefore the
execution is alike proof of
mathematical statement i.e., Prolog

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 19
Database/ Data driven programming

 Program statements are


defined by data rather than
hard-coding a series of steps.
 E.g., database program for
data entry, update, query,
reporting functions.
 For example, SQL language.

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 20
Functional programming

 Surprisingly, you can write very sophisticated programs quite easily.


 Functional programming allows us to deal with lists and data structures
efficiently, by manipulating them as wholes, rather than by taking each
element and manipulating it separately as procedural programming
would.
 Haskell is a functional language.
 A functional program is a single expression, which is executed by
evaluating the expression.
 However, many high level programming languages have been
upgraded to support functional programming such as java (functional
java), javascript, C/C++, PHP in partial and etc.

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 21
Functional programming - contd

 Anyone who has used a spreadsheet has experience of functional


programming.
 In a spreadsheet, one specifies the value of each cell in terms of the values of
other cells. The focus is on what is to be computed, not how it should be
computed
 The focus on the high-level "what" rather than the low-level "how" is a
distinguishing characteristic of functional programming languages
 Another well-known nearly-functional language is the standard
database query language SQL

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 22
Functional programming code examples

//Functional
function greet(name) {
return "Hi, " + name;
}
greet("Sponge Bob");

//Imperative
var name = "Sponge Bob";
var greeting = "Hi, ";
console.log(greeting + name);
CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 23
Functional programming code

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 24
Functional programming code - contd

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 25
Origin of functional programming (FP)

 By Alonzo Church, a mathematician, introducing the lambda calculus


for computational model in computing.
 Lambda calculus – functional evaluation / abstraction
 Programming language such as
 Combinatory logic – mathematical logic / high abstraction
 Information Processing Language (IPL) – first computer-based functional
language
 LISP – multiparadigm programming language
 Miranda – a language with non-strict/ lazy evaluation
 ML – static type systems
 K programming language – widely used in financial industries
 Haskell programming language was released in 1980s in attempt to gather
many ideas in functional programming research.
CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 26
Why functional programming?

 More readability, thus maintainability: Pure functions do not change states


and are entirely dependent on input, and are consequently simple to
understand.
 Concurrency and parallel execution: Immutability and lack of side effects
make it easier to handle concurrency and parallelism. As pure functions
avoid changing variables or any data outside it, concurrency implementation
is easier and less buggy.
 Predictability makes debugging and testing easier: Pure functions take
arguments once and produce unchangeable output. With immutability and
no hidden output, debugging and testing becomes easier.
 Reusable Code: Higher-order functions enable you to write reusable pieces
of code that can be applied to different scenarios.

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 27
Review Exercise

 What is the programming paradigm?


 What are differences between imperative and functional programming?

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 28
Summary / Recap of Main Points

 Programming paradigm
 Definition
 Programming paradigm categories
 Imperative programming
 Declarative programming (logic, data driven, functional)
 Origin of functional programming
 Why functional programming

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 29
What To Expect Next Week

In Class
 Functional programming concepts:
 Purity and Higher order function

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 30
References
[1] Atencio, L. (2018). Functional Programming in Javascript: How to Improve Your Javascript Programs Using Functional Techniques. Manning
Publications.
[2] Peter Van-Roy; Seif Haridi (2004). Concepts, Techniques, and Models of Computer Programming. MIT Press. ISBN 978-0-262-22069-9
https://ctm.info.ucl.ac.be/.
[3] Peter Van Roy (2009-05-12). "Programming Paradigms: What Every Programmer Should Know" (PDF). info.ucl.ac.be. Retrieved 2014-01-27.
[4] https://en.wikipedia.org/wiki/Comparison_of_multi-paradigm_programming_languages
[5] Kereki, F. (2017). Mastering Javascript Functional Programming: In-depth guide for writing robust and maintainable Javascript code in ES8 and beyond.
1st ed. Packt Publishing.

CT006-3-3 & Advanced Programming Language Concepts Introduction to Programming Paradigm SLIDE 31

You might also like