In: Computer Science
1.a. With the aid of vivid real-life scenarios, depict each of the following programming paradigms: i. Structural Paradigm ii. Procedural Programming iii. Object Oriented Programming iv. Imperative Programming v. Literate Programming vi. Declarative Programming vii. Logic Programming viii. Functional Programming ix. Symbolic Programming b. Using any of the following programming languages: Java, C, C++, Visual Basic, and Python; present computer programming codes to illustrate each of the paradigms in 1a above.
1.
a) i) Structural Paradigm -
Like The structural-functional approach tells that all parts in the society works together in order to form a harmonious, sensible and stable society. Same way in programming, structural paradigm aims at improving the clarity, quality, and development time of a computer program by making extensive use of the structured control flow constructs of selection (if/then/else) and repetition (while and for), block structures, and subroutines in contrast to using simple tests and jumps such as the go to statement, which can lead to “spaghetti code” that is potentially difficult to follow and maintain.
ii) Procedural Paradigm :
This paradigm emphasizes on procedure in terms of under lying machine model. It is one of the most popular programming paradigms out there. Here, we split the code into smaller units called functions or procedures so that it is easier to reuse and the flow of execution is from top to bottom. This style is easy to understand and implement.
For example, while making a game we let create a evil boss and need to respawn it at every level. So, we dont have to create the character for every level. Rather we create one character and save it and resue it again and again in every level.
iii) Object Oriented Programming :
The program is written as a collection of classes and object which are meant for communication. The smallest and basic entity is object and all kind of computation is performed on the objects only. More emphasis is on data rather procedure. It can handle almost all kind of real life problems which are today in scenario. The advantage of OOP is reusable codes, flexibility, data security, inheritance etc.
For example, In a game you would have an alien “object”. It would know where it was, what it looked like, which direction it was moving and how to draw itself on the screen. You’d have a whole collection of aliens in another object called the AlienCollection. Each frame, you tell the AlienCollection to draw itself. It doesn't have to do anything except iterate over all its Alien objects and tell them to draw themselves.
iv) Imperative Programming :
It is one of the oldest programming paradigm. It features close relation relation to machine architecture. It is based on Von Neumann architecture. It works by changing the program state through assignment statements. It performs step by step task by changing state. The main focus is on how to achieve the goal. The paradigm consist of several statements and after execution of all the result is stored.
It uses statements that change a program's state. In much the same way that the imperative mood in natural languages expresses commands, an imperative program consists of commands for the computer to perform. Imperative programming focuses on describing how a program operates.
v) Literate Programming :
In Literate programming a computer program is given an explanation of its logic in a natural language, such as English, interspersed with snippets of macros and traditional source code, from which compilable source code can be generated.
The approach is used in scientific computing and in data science routinely for reproducible research and open access purposes. Literate programming tools are used by millions of programmers today.