Paradigms
Different tasks can be resolved using different methods. Those variants are different programming approaches, called paradigms. We will analize two main paradigms:
- Imperative
- Declarative
Remember that almost all modern languages are multi-paradigm, this means they can implement and combine the capabilities of multiple approaches.
# 1. Imperative Paradigm
Key points:
- It’s one of the oldest programming paradigms.
- Closely related to machine architecture.
- Focuses on how to achieve the goal.
- Sequence of instructions that must be executed step by step.
- Consists of several statements that produce a result.
For example, you want to display the phrase “Hello, *<username>*!”. How should the program do it ? following these steps:
- Ask the username
- Read and remember the username
- Display the result
This paradigm is divided in three broad categories:
- Procedural Programming Paradigm.
- Object-Oriented Programming.
- Parallel Processing Approach.
# 2. Procedural Programming Paradigm
# 3. Object-Oriented Programming
- Paradigm where the program is written as a collection of classes.
- Each class has instances (also called objects).
- Class: Way of describing an entity in general, defining usual state, behavior, rules for interacting with it. Its viewed as a set of data (with fields, attributes, class members and functions like methods for working with them)
- It can handle all kinds of common real-life problems.
Programming languages with Object-Oriented Programming:
- Java.
- C++.
- Python.
- Simula.
- Smalltalk.
- Visual Basic .NET.
- Objective-C.
# 4. Parallel Processing Approach
- Helps reduce instructions execution time.
- Shares and/or parallelizes instructions across multiple processors.
- “Divide and conquer”
Programming Languages with Parallel Processing Approach:
- NESL.
- C.
- C++.
# 5. Declarative Paradigm
- Specify the problem and the expected result.
- Answers with “What needs to be done?” and “What will be the result of the work?”.
- You tell the system what you need and let it try to come up with a solution
This paradigm is divided in three categories:
- Logic Programming Paradigm.
- Functional Programming Paradigm.
- Database Paradigm.
# 6. Logic Programming Paradigm
- Heavily based on formal logic
- Set of sentences in a logical form that express facts and rules
Basic statements of logic programming are:
- Facts. Fundamental assertions about the problem domain (“Socrtates is a man”).
- Rules. Interferences about the facts in the domain (“All men are mortal”).
- Queries. Questions about that domain (“Is Socrates mortal?”)
The task here is to find the answer to the query based on facts and rules.
Programming languages with Logic Programming Paradigm:
- Prolog.
- ASP.
- Datalog
# 7. Functional Programming Paradigm
- The computation process is interpreted as the computation of the values of functions.
- The function is similar to a mathematical function.
- The function input is an array that is not changed.
- The function output is a new array with new data.
- Function is different from a function in Procedural Programming, where the function is a sequence of actions that change the original data.
Example: You might have a function that takes a list of numbers as input and returns a new list with the squares of those numbers. This does not change the original list of numbers
Programming Languages with Functional Programming Paradigm:
- JavaScript.
- Haskell.
- Scala.
- Erlang.
- Lisp.
- ML.
- Clojure.
- OCaml.
- Common Lisp.
- F#.
# 8. Database Programming Paradigm
- Based on working with data.
- The data is stored in the database.
- Queries are made to the database in a special language (like SQL).
- Special languages let you access the data.
- You can filter, transform, calculate statistics, and so on on this data.
- Program stattements are data-defined rather than a hard-coded series of steps.
The database program is the heart of the business information system, allowing for file creation, data entry, updating, querying and reporting functions.
# 9. Conclusion
- Different approaches to creating programs are called paradigms.
- There are two main Programming Paradigms: Imperative and Declarative
- Imperative Paradigm focuses on achieving a result using step-by-step instructions that change data sequentially.
- Imperative Paradigm includes: Procedural Programming Paradigm, Object-Oriented Programming and Parallel Processing Approach.
- Declarative Paradigm focuses on the task and tries tog et an expected result.
- Declarative Paradigm includes: Logic Programming Paradigm, Functional Programming Paradigm, and Database Programming Paradigm.