This post is also available in: English العربية (Arabic)
प्रोग्रामिंग पैराडाइम का क्या अर्थ है?
प्रोग्रामिंग की दुनिया में, आप “प्रोग्रामिंग प्रतिमान” शब्द कई बार सुन चुके होंगे। क्या आप जानते हैं कि इस शब्द का अर्थ क्या है?
प्रोग्रामिंग प्रतिमान शब्द प्रोग्रामिंग की एक शैली को संदर्भित करता है। शैली से, इसका मतलब किसी विशिष्ट भाषा की पसंद नहीं है, बल्कि यह आपके प्रोग्राम के तरीके को संदर्भित करता है।
कई प्रोग्रामिंग भाषाएं हैं जो दुनिया भर के प्रोग्रामर उपयोग करते हैं लेकिन ये सभी प्रोग्रामर कार्यक्रमों को लागू करने के लिए कुछ विशिष्ट रणनीति का पालन करते हैं। प्रोग्रामरों का अनुसरण करने वाली इस रणनीति को एक प्रोग्रामिंग प्रतिमान कहा जाता है।
प्रोग्रामिंग प्रतिमान के प्रकार
प्रोग्रामिंग के प्रतिमानों के 2 मूल प्रकार हैं, उनके प्रोग्राम लिखते समय प्रोग्रामर द्वारा। ये इस प्रकार हैं:
- इम्पेरटिव प्रोग्रामिंग पैराडाइम
- घोषणात्मक प्रोग्रामिंग प्रतिमान
इम्पेरटिव प्रोग्रामिंग पैराडाइम
Imperare एक लैटिन शब्द है जिसका अर्थ होता है कमांड। इम्पेरटिव प्रोग्रामिंग सबसे पुरानी प्रोग्रामिंग प्रतिमान है। इस प्रतिमान पर आधारित एक प्रोग्राम कंप्यूटर से निर्देशों के स्पष्ट रूप से परिभाषित अनुक्रम से बना है।
अनिवार्य प्रोग्रामिंग भाषाओं में, स्रोत कोड आदेशों की एक श्रृंखला है, जो निर्दिष्ट करता है कि कंप्यूटर को क्या करना है और कब – वांछित परिणाम प्राप्त करने के लिए। किसी प्रोग्राम में उपयोग किए जाने वाले चरों के मान को रनटाइम के दौरान बदल दिया जाता है। आदेशों को नियंत्रित करने के लिए, लूप और / या शाखाओं जैसे नियंत्रण संरचनाओं को कोड में एकीकृत किया जाता है।
इंपीरियल प्रोग्रामिंग लैंग्वेज बहुत विशिष्ट हैं, और ऑपरेशन सिस्टम-ओरिएंटेड है। एक तरफ, कोड को समझना आसान है; दूसरी ओर, स्रोत पाठ की कई पंक्तियों को यह वर्णन करने की आवश्यकता है कि घोषित प्रोग्रामिंग भाषाओं का उपयोग करके कमांड के एक अंश के साथ क्या हासिल किया जा सकता है।
इम्पेरटिव शैली सबसे पुरानी प्रोग्रामिंग प्रतिमानों में से एक है। यह मशीन आर्चिटेक्टचर का घनिष्ठ संबंध रखता है जो वॉन न्यूमैन आर्चिटेक्टचर पर आधारित है। यह असाइनमेंट स्टेटमेंट के माध्यम से प्रोग्राम स्टेट को बदलकर काम करता है। यह स्टेट को बदलकर चरणबद्ध कार्य करता है। मुख्य ध्यान इस पर है कि लक्ष्य को कैसे प्राप्त किया जाए। प्रतिमान में कई कथन होते हैं और सभी कथनों के निष्पादन के बाद, परिणाम एक चर (ओं) में संग्रहीत होता है।
कुछ सबसे प्रसिद्ध अनिवार्य प्रोग्रामिंग भाषाएं हैं
इम्पेरटिव प्रोग्रामिंग पैराडाइम के फायदे और नुकसान
|Easy to read||Code quickly becomes very extensive and thus confusing|
|Relatively easy to learn||Higher risk of errors when editing|
|The conceptual model (solution path) is very easy for beginners to understand.||System-oriented programming means that maintenance blocks application development.|
|Characteristics of specific applications can be taken into account.||Optimization and extension are more difficult.|
The different imperative programming languages are further divided into three sub-styles:
- Procedural Programming Paradigm
- Object-Oriented Programming Paradigm
- Parallel Processing Paradigm
This paradigm emphasizes procedure in terms of the underlying machine model. There is no difference between procedural and imperative approaches. It can reuse the code and it was a boon at that time when it was in use because of its reusability.
Procedural Programming Paradigm
Procedural Programming may be the first programming paradigm that a new developer will learn. Fundamentally, the procedural code is the one that directly instructs a device on how to finish a task in logical steps. This paradigm uses a linear top-down approach and treats data and procedures as two different entities. Based on the concept of a procedure call, Procedural Programming divides the program into procedures, which are also known as routines or functions, simply containing a series of steps to be carried out.
Simply put, Procedural Programming involves writing down a list of instructions to tell the computer what it should do step-by-step to finish the task at hand.
Features of Procedural Programming Paradigm
The key features of procedural programming are given below:
- Predefined functions: A predefined function is typically an instruction identified by a name. Usually, the predefined functions are built into higher-level programming languages, but they are derived from the library or the registry, rather than the program. One example of a pre-defined function is ‘charAt()’, which searches for a character position in a string.
- Local Variable: A local variable is a variable that is declared in the main structure of a method and is limited to the local scope it is given. The local variable can only be used in the method it is defined in, and if it were to be used outside the defined method, the code will cease to work.
- Global Variable: A global variable is a variable that is declared outside every other function defined in the code. Due to this, global variables can be used in all functions, unlike a local variable.
- Modularity: Modularity is when two dissimilar systems have two different tasks at hand but are grouped to conclude a larger task first. Every group of systems then would have its tasks finished one after the other until all tasks are complete.
- Parameter Passing: Parameter Passing is a mechanism used to pass parameters to functions, subroutines, or procedures. Parameter Passing can be done through ‘pass by value’, ‘pass by reference’, ‘pass by result’, ‘pass by value results and ‘pass by the name’.
Advantages and Disadvantages of Procedural Programming
Procedural Programming comes with its own set of pros and cons, some of which are mentioned below.
- Procedural Programming is excellent for general-purpose programming.
- The coded simplicity along with ease of implementation of compilers and interpreters.
- A large variety of books and online course material available on tested algorithms, making it easier to learn along the way.
- The source code is portable, therefore, it can be used to target a different CPU as well.
- The code can be reused in different parts of the program, without the need to copy it.
- Through the Procedural Programming technique, the memory requirement also slashes.
- The program flow can be tracked easily.
- The program code is harder to write when Procedural Programming is employed.
- The Procedural code is often not reusable, which may pose the need to recreate the code if it is needed to be used in another application.
- Difficult to relate to real-world objects.
- The importance is given to the operation rather than the data, which might pose issues in some data-sensitive cases.
- The data is exposed to the whole program, making it not so much security-friendly.
There are different types of programming paradigm as we mentioned before, which are nothing but a style of programming. It is important to understand that the paradigm does not cater to a specific language but to the way the program is written. Below is a comparison between Procedural Programming and Object-Oriented Programming.
Object-oriented programming (OOP) is a programming paradigm based upon objects (having both data and methods) that aims to incorporate the advantages of modularity and reusability. Objects, which are usually instances of classes, are used to interact with one another to design applications and computer programs.
The important features of object-oriented programming are −
- Bottom–up approach in program design.
- Programs organized around objects, grouped in classes.
- Focus on data with methods to operate upon the object’s data.
- Interaction between objects through functions.
- Reusability of design through the creation of new classes by adding features to existing classes.
Object-Oriented Programming comes with its own set of pros and cons, some of which are mentioned below.
- A real-world idea can be demonstrated, as everything in OOP is treated as an object.
- As we use the concept of encapsulation, programs are easier to test and maintain.
- Faster development of code is done, as we develop classes parallel instead of sequentially.
- OOP provides greater security due to data abstraction. The outside world cannot access the hidden data.
- Reusability can be achieved by using classes that have been already written.
- Designing a program with an OOP concept can be tricky.
- A programmer needs to plan for developing a program in OOP.
- The size of programs developed with OOP is bigger than those developed with a procedural approach.
- Since OOP programs are larger, the execution time for these programs is also more.
Parallel Processing Paradigm
Parallel computing is the use of two or more processors (cores, computers) in combination to solve a single problem. It is a type of computing architecture in which several processors execute or process an application or computation simultaneously. Parallel computing helps in performing large computations by dividing the workload between more than one processor, all of which work through the computation at the same time. Most supercomputers employ parallel computing principles to operate.
This type of computing is also known as parallel processing. The primary objective of parallel computing is to increase the available computation power for faster application processing or task resolution.
Parallel computing infrastructure is standing within a single facility where many processors are installed in one or separate servers that are connected.
It is generally implemented in operational environments/scenarios that require massive computation or processing power.
Following are the advantages and disadvantages of the parallel processing paradigm.
- Parallel computing saves time, allowing the execution of applications in a shorter wall-clock time.
- Solve Larger Problems in a short point of time.
- Compared to serial computing, parallel computing is much better suited for modeling, simulating, and understanding complex, real-world phenomena.
- Throwing more resources at a task will shorten its time to completion, with potential cost savings. Parallel computers can be built from cheap, commodity components.
- Many problems are so large and/or complex that it is impractical or impossible to solve them on a single computer, especially given limited computer memory.
- You can do many things simultaneously by using multiple computing resources.
- Can use computer resources on the Wide Area Network(WAN) or even on the internet.
- It can help keep you organized. If you have the Internet, then communication and social networking can be made easier.
- It has massive data storage and quick data computations.
- Programming to target Parallel architecture is a bit difficult but with proper understanding and practice, you are good to go.
- The use of parallel computing lets you solve computationally and data-intensive problems using multicore processors, but, sometimes this effect on some of our control algorithms do not give good results and this can also affect the convergence of the system due to the parallel option.
- The extra cost (i.e. increased execution time) incurred is due to data transfers, synchronization, communication, thread creation/destruction, etc. These costs can sometimes be quite large and may exceed the gains due to parallelization.
- Various code tweaking has to be performed for different target architectures for improved performance.
- Better cooling technologies are required in the case of clusters.
- Power consumption is huge by the multi-core architectures.
- Parallel solutions are harder to implement, they’re harder to debug or prove correct, and they often perform worse than their serial counterparts due to communication and coordination overhead.
घोषणात्मक प्रोग्रामिंग प्रतिमान
In computer science, declarative programming is a programming paradigm – a style of building the structure and elements of computer programs – that expresses the logic of a computation without describing its control flow.
Many languages that apply this style attempt to minimize or eliminate side effects by describing what the program must accomplish in terms of the problem domain, rather than describe how to accomplish it as a sequence of the programming language primitives. (the how is left up to the language’s implementation). This is in contrast with imperative programming, which implements algorithms in explicit steps.
Declarative programming often considers programs as theories of formal logic, and computations as deductions in that logic space. Declarative programming may greatly simplify writing parallel programs.
Common declarative languages include those of database query languages (e.g., SQL, XQuery), regular expressions, logic programming, functional programming, and configuration management systems.
Examples of Declarative Programming Languages
The best-known declarative programming languages are:
Advantages and Disadvantages of Declarative Programming Paradigm
Following are the advantages and disadvantages of the Declarative Programming languages:
- Short, efficient code
- Can be implemented using methods not yet known at the time of programming
- Easy optimization as implementation is controlled by an algorithm
- Maintenance possible independent of application development
- Sometimes hard to understand for external people
- Based on an unfamiliar conceptual model for people (solution state)
- Hard to take characteristics of individual applications into account during programming
The different declarative programming languages are further divided into three sub-styles:
- Logic Programming Paradigm
- Functional Programming Paradigm
- Database Processing Paradigm
Logic Programming Paradigm
It can be termed as an abstract model of computation. It would solve logical problems like puzzles, series, etc. In logic programming we have a knowledge base that we know before and along with the question and knowledge base which is given to the machine, it produces results. In normal programming languages, such a concept of the knowledge base is not available but while using the concept of artificial intelligence, machine learning we have some models like the Perception model which is using the same mechanism.
In logical programming, the main emphasis is on a knowledge base and the problem. The execution of the program is very much like proof of the mathematical statement, e.g., Prolog.
Logic programming has its number of advantages and disadvantages, and here are some of them:
• Logic programming can be used to express knowledge in a way that does not depend on the
implementation, making programs more flexible, compressed, and understandable.
• It enables knowledge to be separated from use, ie the machine architecture can be changed
without changing programs or their underlying code.
• It can be altered and extended in natural ways to support special forms of knowledge, such
as meta-level of higher-order knowledge.
• It can be used in non-computational disciplines relying on reasoning and precise means of
• Initially, due to insufficient investment in complementary technologies, users were poorly
• In the beginning, poor facilities for supporting arithmetic, types, etc. had a discouraging
effect on the programming community.
• There is no adequate way of representing computational concepts found in built-in
mechanisms of state variables (as is usually found in conventional languages).
• Some programmers always have, and always will prefer the overtly operational nature of machine-operated programs, since they prefer active control over the ‘moving parts’.
Functional Programming Paradigm
Following are the advantages and disadvantages of Functional Programming languages:
- Because pure functions don’t change any states and are entirely dependent on the input, they are simple to understand. The return value given by such functions is the same as the output produced by them. The arguments and return type of pure functions are given out by their function signature.
- Due to the nature of pure functions to avoid changing variables or any data outside it, implementing concurrency becomes efficacious
- It supports the concept of lazy evaluation, which means that the value is evaluated and stored only when it is required.
- Pure functions take arguments once and produce unchangeable output. Hence, they don’t produce any hidden output. They use immutable values, making debugging and testing easier.
- Its style treats functions as values and passes the same to other functions as parameters. It enhances the comprehension and readability of the code.
- Immutable values combined with recursion might lead to a reduction in performance
- In some cases, writing pure functions causes a reduction in the readability of the code
- Though writing pure functions are easy, combining the same with the rest of the application as well as the I/O operations is tough
- Writing programs in recursive style in place of using loops for the same can be a daunting task
Database Processing Paradigm
This programming methodology is based on data and its movement. Program statements are defined by data rather than hard-coding a series of steps. A database program is the heart of a business information system and provides file creation, data entry, update, query, and reporting functions. Several programming languages are developed mostly for a database application. For example SQL. It is applied to streams of structured data, for filtering, transforming, aggregating (such as computing statistics), or calling other programs. So it has its wide application.
Advantages and disadvantages of Database Processing languages are listed below:
- Reduced data redundancy
- Reduced updating errors and increased consistency
- Greater data integrity and independence from applications programs
- Improved data access to users through the use of host and query languages
- Improved data security
- Reduced data entry, storage, and retrieval costs
- Facilitated development of new applications program
- Database systems are complex, difficult and time-consuming to design
- Substantial hardware and software start-up costs
- Damage to database affects virtually all applications programs
- Extensive conversion costs in moving from a file-based system to a database system
- Initial training required for all programmers and users
Declarative vs. Imperative Programming
Imperative programming languages differ from declarative languages on one fundamental point: imperative programming focuses on the “how”, declarative programming on the “what”.
But what does that mean? Imperative programming languages are composed of step-by-step instructions (how) for the computer. They describe explicitly which steps are to be performed in what order to obtain the desired solution at the end. By contrast, in declarative programming, the desired result (what) is described directly. This becomes clearer when using a cooking analogy for illustration: imperative languages provide recipes; declarative languages contribute photos of the finished meal.
In declarative languages, the source code remains very abstract in terms of the specific procedure. To get to the solution, an algorithm is used which automatically identifies and applies appropriate methods. This approach has numerous advantages: Programs can be written much more quickly, and applications are also very easy to optimize. If a new method is developed in the future, the abstract instructions in the source code mean that the algorithm can easily utilize the newer method.
In practice, mixed forms of the paradigms are generally used these days because both imperative and declarative programming styles have their advantages and disadvantages. However, the declarative programming style is becoming increasingly dominant, supplemented by imperative methods.
Image Credit: Technology vector created by freepik – www.freepik.com