Programming Languages
| Site: | Newgate University Minna - Elearning Platform |
| Course: | Computer Programming I |
| Book: | Programming Languages |
| Printed by: | Guest user |
| Date: | Monday, 9 November 2026, 1:10 PM |
1. A programming language
is a formal language used to write instructions that a computer can understand and execute.
A programming language is a set of instructions used to write computer programs. It's the medium through which a programmer communicates with a computer, defining the logic and tasks a computer must perform. Programming languages can be categorized in several ways, but the most common is by their level of abstraction.
It provides syntax (rules) and semantics (meaning) for writing programs.
Levels of Programming Languages
1. Machine Language
Binary instructions (0s and 1s).
Directly understood by the CPU.
Very fast but difficult to use.
1.1. Example:
10110000 01100001 → May represent “move the value 97 into a register”
1. Assembly Language
Uses mnemonic codes (e.g., MOV, ADD).
Easier than machine language but still low-level.
Requires an assembler to translate into machine code.
Example: MOV AL, 61h ; move hexadecimal 61 into register AL
2. High-Level Languages
Human-readable (e.g., Python, Java, C++).
Easier to write and maintain.
Require a compiler or interpreter to execute.
1.2. Python Example: python
print("Hello, World!")
Java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
2. Programming Paradigms
Introduction to Programming Paradigms
A programming paradigm is a fundamental style or approach to writing and structuring computer programs. It defines the way programmers think about and solve problems, influencing how code is organized, executed, and maintained. Paradigms emerge from research into software development practices, allowing us to classify languages and compare methodologies
A programming paradigm is a fundamental style or approach to writing and structuring computer programs. It defines the way programmers think about and solve problems, influencing how code is organized, executed, and maintained. Paradigms emerge from research into software development practices, allowing us to classify languages and compare methodologies.
2.1. Common Programming Paradigms
A programming paradigm is a style or philosophy for writing code. Most languages support multiple paradigms.
Procedural Programming: This is an imperative paradigm that structures a program as a sequence of steps or routines. The focus is on a series of commands to achieve a desired outcome. C and Fortran are examples.
Procedural programming is a programming paradigm (a pattern or model) that focuses on creating procedures or routines to solve problems. Procedural programming is a programming paradigm where the logic of a program is built around procedures, also known as functions or routines.
Procedural Programming languages follow a sequence of instructions and conveys it to the computer. In procedural programming, a program is divided into smaller, manageable units that perform specific tasks. These units are executed in a sequential manner, and the program flow is typically controlled using structures such as loops, conditionals, and function calls Procedural programming depends on procedures. As procedural programming language follows a method of solving problems from the top of the code to the bottom of the code, if a change is required to the program, the developer has to change every line of code that links to the main or the original code. If the user wants to code a program, they would have to follow a sequence of instructions and thereby enter the instructions. In addition, we can say that when a problem is need to be fix using procedural programming, the developer will start with the problem (procedure) and then he logically fragments the problem down into sub problems (Sub-Procedures). Subsequently, this process will continue until a sub- procedure is simple enough to be solved by itself.
2.2. The core principles of procedural programming include:
1. Sequence: The execution of code occurs in a linear sequence, one instruction after another.
2. Modularity: The program is broken down into functions or procedures that are responsible for specific tasks, promoting code reusability.
3. Local Variables: Variables are often declared within the scope of functions and are used to store temporary data during execution.
4. Control Flow: Structured control statements, such as if-else conditions, loops, and case-switch statements, determine the program’s flow of execution.
Abstraction: Functions provide abstraction by hiding the details of complex tasks and exposing only essential operations.
2.3. Examples for procedural programming languages include C, COBOL, FORTRAN and VB, PASCAL.
Pascal Program Structure
A Pascal program basically consists of the following parts −
Program name
Uses command
Type declarations
Constant declarations
Variables declarations
Functions declarations
Procedures declarations
Main program block
Statements and Expressions within each block
Comments
2.4. NOTE
Every pascal program generally has a heading statement, a declaration and an execution part strictly in that order. Following format shows the basic syntax for a Pascal program
program {name of the program}
uses {comma delimited names of libraries you use}
const {global constant declaration block}
var {global variable declaration block}
function {function declarations, if any}
{ local variables }
begin
end;
procedure { procedure declarations, if any}
{ local variables }
begin
end;
begin { main program block starts}
end. { the end of main program block }
2.5. C-language program
C-language program
a general structure
1 Calling header files #include <stdio.h>
2 Main function main()
3 Starting brace {
4 Variable(s) declaration int a;4 Variable(s) declaration int a;
5 Executable statement(s) printf () etc
6 Closing brace
3. Key characteristics of Procedural Programming
1. Functions: The fundamental building blocks of procedural programs are functions or procedures. Each function is responsible for a specific task and can take inputs, perform operations, and produce outputs.
2. Global Variables: Data in procedural programming is often organized using global variables, which can be accessed and modified by different functions within the program.
3. Emphasis on Procedure: The focus is on defining the sequence of steps required to solve a problem. The flow of control is determined by function calls and the order of execution.
4. Limited Reusability: While functions can be reused, procedural programs may lack the level of reusability and modularity seen in other paradigms like object-oriented programming.
5. Code Reusability: Functions can be reused across different parts of the program, enhancing code modularity and reducing redundancy.
6. Simplicity: Procedural programming is often simpler to learn and understand, making it suitable for smaller projects and straightforward tasks.
Advantages of Procedural Programming
1. Simplicity: Procedural programming is relatively straightforward to learn and implement, making it suitable for beginners and smaller projects.
2. Efficiency: The linear flow of control and direct manipulation of data in memory can lead to efficient code execution.
3. Clear Structure: Programs are organized as a sequence of functions, resulting in clear and modular code.
4. Resource Efficiency: Procedural programming can use fewer system resources compared to more complex paradigms, making it suitable for resource-constrained environments.
5. Well-Suited for Simple Tasks: It’s ideal for tasks that involve straightforward sequences of steps and do not require complex data manipulation or interactions.
Disadvantages of Procedural Programming
1. Limited Reusability: Functions are reusable, but the lack of inherent modularity in the paradigm may limit code reusability as programs become larger.
2. Code Maintainability: As programs grow, maintaining and extending code can become challenging due to the lack of clear encapsulation of data and behavior.
3. Complexity Handling: Procedural programming might struggle to handle complexity and interactions between different parts of a program.
Global State: The use of global variables can lead to unintended side effects and errors if not managed carefully.
3.1. Applications of Procedural Programming
1. System Programming: Procedural languages like C are used for system-level programming, such as writing operating systems, device drivers, and embedded systems.
2. Scientific Computing: Procedural programming can be used in scientific simulations and computations where a linear sequence of steps is involved.
3. Scripting: Many scripting tasks, such as automating routine tasks or processing data, can be efficiently accomplished using procedural programming.
4. Algorithm Development: Developing and testing algorithms, especially those involving numerical computations, can be done effectively using procedural languages.
5. Small-Scale Projects: Procedural programming is well-suited for small-scale projects, prototypes, and tasks that involve simple calculations or data manipulations.
Declarative Programming
Declarative programming specifies what the program should achieve without explicit control flow, leaving implementation to the system.
Core Principles
· Goal-Oriented: Define the desired outcome.
· System-Managed: Execution handled by the system (e.g., database engine).
· Minimal State: Often stateless.
Example (Java with SQL)
Java integrates with SQL via JDBC for declarative database queries.
3.2. Java
Java
import java.sql.*;
public class DeclarativeExample {
public static void main(String[] args) throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:sqlite:users.db");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT name FROM users WHERE age > 18");
while (rs.next()) {
System.out.println(rs.getString("name"));
}
conn.close();
}
}
3.3. Logic Programming
Logic programming uses formal logic, expressing programs as facts and rules. The system infers solutions via unification and backtracking.
Core Principles
Facts and Rules: Define relationships.
Queries: Ask the system to deduce answers.
Backtracking: Tries alternative solutions.
Declarative: Logic-focused, not procedural.
Example (Java with tuProlog)
Java integrates logic programming via libraries like tuProlog
import alice.tuprolog.*;
public class LogicExample {
public static void main(String[] args) throws Exception {
Prolog engine = new Prolog();
engine.addTheory(new Theory(
"parent('John', 'Mary').\n" +
"parent('Mary', 'Alice').\n" +
"grandparent(X, Z) :- parent(X, Y), parent(Y, Z)."
));
SolveInfo info = engine.solve("grandparent('John', 'Alice').");
System.out.println(info.isSuccess()); // Output: true
}
}
3.4. The grandparent relationship is inferred.
Strengths
Ideal for AI and rule-based systems.
Backtracking simplifies complex logic.
Declarative and concise.
Weaknesses
Inefficient for large datasets.
Non-deterministic behavior.
Niche usage.
Use Cases
Expert systems.
Knowledge bases.
Constraint solving.
Languages
Prolog, Datalog, Java (with tuProlog).