Programming Constructs Paradigms PDF
Programming Constructs Paradigms PDF
Object-Oriented Programming
(OOP) is a programming paradigm
in computer science that relies on
the concept of classes and
objects. It is used to structure a
software program into simple,
reusable pieces of code blueprints
(usually called classes), which are
used to create individual instances
of objects. There are many object-
oriented programming languages,
including JavaScript, C++, Java,
and Python.
characteristics of OOp
ENCAPSULATION
refers to the bundling of data, along
with the methods that operate on
that data, into a single unit.
Containers are just one example of
encapsulation in coding where data
and methods are bundled together
into a single package. A key
benefits to hiding information about
attributes and methods using
encapsulation in programming is
that it prevents other developers
from writing scripts or APIs that use
your code.
characteristics of OOp
INHERITANCE
When a class derives from another class. The child class will inherit all the public and
protected properties and methods from the parent class. In addition, it can have its
own properties and methods. An inherited class is defined by using the extends
keyword.
For example, a child inherits the traits of his/her parents. With inheritance, we can
reuse the fields and methods of the existing class.
characteristics of OOp
POLYMORPHISM
Polymorphism is another fundamental
concept in OOP, which means multiple
forms. Polymorphism allows the use of
a single interface with different
underlying forms, such as data types
or classes.
Polymorphism means one function
with multiple functionalities or
representations
BENEFITS OF USING OOP
Reusability of code
Improved code organization
Improved code maintainability
Improved code security
FUNCTIONAL PROGRAMMING
Pure Functions:
Pure functions are functions that have no side effects and always return the same output
given the same input. This means that the function does not modify any variables outside its
scope, and it does not rely on variables outside its scope. Pure functions have several
advantages, including that they are easier to reason about, test, and debug, and they can be
safely executed in parallel.
Immutability:
In functional programming, data is treated as immutable, meaning that once a value is
assigned, it cannot be changed. Instead, new values are created by applying transformations
to existing values. This ensures that data is not accidentally modified in unexpected ways, and
it simplifies reasoning about program behavior. Immutable data also makes it easier to write
concurrent and parallel code, because data can be safely shared between threads without
fear of conflicts.
Characteristics of FUNCTI ONAL PROGRAMMI NG
Higher-order
Functions:
Easier debugging:
Because functional programs are composed of pure functions, they do not have
side effects or dependencies on external state. This makes it easier to reason about
the behavior of the program and debug issues that may arise.
Functional programming emphasizes the use of small, reusable functions that can
be combined to create larger programs. This modular approach to programming
makes it easier to modify and maintain code over time, as changes to one function
can be made without affecting other parts of the program.
Benefits of FUNCTIONAL PROGRAMMI NG
Better scalability:
DECLARATIVE
Logic Programming is a declarative programming paradigm, which means that the programmer
specifies what the program should do, rather than how it should do it. The program consists of a
set of logical rules and constraints that are used to derive solutions to the problem.
NON-PROCEDURAL
Logic Programming is a non-procedural programming paradigm, which means that the
programmer does not need to specify the sequence of steps to solve the problem. The program
derives the solution by applying logical rules and constraints.
BACKTRACKING
Backtracking is a key feature of Logic Programming, which allows the program to search for a
solution by trying different possibilities. If one possibility fails, the program backtracks and tries
another possibility.
Benefits of logic programmi ng
EASY TO DEBUG
Logic Programming is easy to debug because the program consists of a set of logical
rules and constraints that are easy to verify.
FLEXIBLE
Logic Programming is very flexible and can be used to solve a wide range of problems,
including those that are difficult to solve using other programming paradigms.
EFFICIENT
Logic Programming is often more efficient than other programming paradigms because it
uses backtracking to search for a solution, rather than brute force.
procedural programming
Procedural Programming is a
programming paradigm that
focuses on the procedure, or
sequence of statements, that are
executed to achieve a specific task.
In Procedural Programming, a
program is structured in terms of
procedures, which are also known as
functions, subroutines or methods.
These procedures can be called by
other procedures or from the main
program to accomplish a task.
characteristics of Proceduralprogrammi ng
MODULARITY
Programs written in procedural languages are divided into small modules or
procedures, which makes it easier to understand and maintain the code.
SEQUENTIAL EXECUTION
Procedural languages execute the code in a sequential manner, from top to
bottom. This means that the program follows a set order of execution.
REUSABILITY
Procedures can be reused throughout the code, which makes the code more
efficient and reduces the need for repetitive coding.
Benefits of procedural programming
Easy to learn
Code Reusability
Faster Execution
Structured Programming
PROGRAMMING GUIDELINES
Programming Guidelines refer to a set of best practices and guidelines
that developers follow while writing code. These guidelines ensure that
the code is efficient, maintainable, and free of errors.
documentation guidelines
Using pseudo codes
Example:
Enter value
if value greater than 10
say "your number is greater than 10"
if value is less than 10
say "your number is less than 10"
control structures guidelines
If-else
Documentation Guidelines