Computer ScienceNEB 2076 (old course)

What is programming language ? Describe the various types of programming language with their merits and demerits. [2+8] GROUP: B Short answer questions 9 × 5 = 45

10

Answer

Binary code (0s and 1s)Example: `10110000 01100001` (MOV AL, 'A')Machine LanguageMnemonic codes (e.g., MOV, ADD)Example: `MOV AX, BX` → `00000001 00000000 00000001 00000000Assembly LanguageStructured, step-by-step instructionsExample: `int sum(int a, int b) { return a + b; }`Procedural (e.g., C, Pascal)Encapsulation, inheritance, polymorphismExample: `class Car { private String model; ... }`Object-Oriented (e.g., Java, C++)Interpreted, dynamic typingExample: `print('Hello')`Scripting (e.g., Python, JavaScript)Immutability, higher-order functionsExample: `map(lambda x: x*2, [1,2,3])`Functional (e.g., Haskell, Lisp)High-Level Language (HLL)SQL (e.g., `SELECT * FROM students;`)Domain-specific (e.g., MATLAB for math)Fourth-Generation Language (4GL)Programming Languages
Classification of programming languages with examples (simplified)

Programming Language

A programming language is a formal language consisting of a set of instructions (syntax and semantics) used to communicate with computers. It allows programmers to write code that can be executed by a computer to perform specific tasks. Programming languages act as an intermediary between humans and machines, enabling the creation of software, applications, and systems.


Types of Programming Languages

Programming languages can be broadly classified into the following categories:

1. Machine Language

  • Definition: The lowest-level programming language, consisting of binary code (0s and 1s) directly understood by the CPU.
  • Example: 10101011 00000001 (binary instructions for a CPU operation).
  • Merits:
    • Fastest execution (directly executed by hardware).
    • No need for translation (compilation/interpretation).
  • Demerits:
    • Difficult to write, read, and debug (error-prone).
    • Machine-dependent (different for each CPU architecture).
    • Time-consuming to develop programs.

2. Assembly Language

  • Definition: A low-level language using mnemonic codes (e.g., MOV, ADD, JMP) that are easier to remember than binary. Requires an assembler to convert it into machine code.
  • Example:
    MOV AX, 5    ; Load value 5 into register AX
    ADD AX, 3    ; Add 3 to AX
    
  • Merits:
    • Easier to write and debug than machine language.
    • Retains low-level control over hardware (used in OS development, embedded systems).
  • Demerits:
    • Still machine-dependent.
    • Complex syntax and error-prone.
    • Slower development compared to high-level languages.

3. High-Level Language (HLL)

High-level languages are designed to be closer to human languages, making them easier to understand and program. They are portable (can run on different platforms with minimal changes) and require a compiler or interpreter to translate them into machine code.

Types of High-Level Languages
Type Examples Key Features Merits Demerits
Procedural C, Pascal, Fortran Structured, step-by-step instructions using functions/procedures. Easy to learn, efficient execution, widely used in system programming. Less flexible for large-scale applications; no built-in data hiding.
Object-Oriented (OOP) Java, C++, Python Encapsulation, inheritance, polymorphism; data and methods bundled as objects. Reusable code, modularity, better for large projects (e.g., GUI, enterprise software). Steeper learning curve; overhead due to object management.
Scripting Python, JavaScript, PHP Interpreted, lightweight, embedded in applications (e.g., web browsers). Fast development, dynamic typing, easy to debug. Slower execution; not suitable for system-level programming.
Functional Haskell, Lisp, ML Based on mathematical functions; avoids mutable state and side effects. Predictable, easier parallel processing; used in academic/research domains. Harder to learn; limited hardware control.
Logic Prolog Rule-based, declarative (focuses on "what" rather than "how"). Used in AI, expert systems, theorem proving. Niche applications; not suitable for general-purpose programming.

4. Fourth-Generation Language (4GL)

  • Definition: Designed to simplify programming for specific tasks (e.g., database queries, report generation). Often uses visual interfaces or natural language-like syntax.
  • Examples: SQL (Structured Query Language), MATLAB, Visual Basic.
  • Merits:
    • Reduces development time (e.g., SQL for databases).
    • User-friendly for non-programmers (e.g., drag-and-drop interfaces).
  • Demerits:
    • Limited to specific domains (e.g., SQL for databases only).
    • Less control over hardware/low-level operations.

Comparison Table: Key Differences

Feature Machine Language Assembly Language High-Level Language (HLL) Fourth-Generation (4GL)
Level of Abstraction Lowest (binary) Low (mnemonics) High (human-like) Very high (task-specific)
Readability Poor (binary) Better (mnemonics) Excellent (English-like) Excellent (domain-specific)
Portability Machine-dependent Machine-dependent Portable (with compilers) Limited to specific tasks
Development Speed Slowest Slower Fast Fastest (for specific tasks)
Execution Speed Fastest Fast Slower (due to translation) Moderate
Use Cases Embedded systems, OS kernels Device drivers, OS development General-purpose (apps, games, web) Database queries, reporting
02505007501000Machine1Assembly10HLL1004GL1000
Relative abstraction levels (log scale: 1=lowest, 1000=highest)

Choosing the Right Language

The choice of programming language depends on:

  1. Purpose of the program (e.g., web development → JavaScript/Python; game development → C++/C#).
  2. Performance requirements (e.g., real-time systems → C/C++; scripting → Python).
  3. Developer expertise (e.g., beginners → Python; system programmers → C).
  4. Platform compatibility (e.g., cross-platform → Java; Windows-only → C#).

Example Code Snippets

08162431Opcode8 bitsOperand24 bits
Machine language instruction format (x86: MOV AL, 'A')
High-level → MachineAssembly → MachineHigh-level → Direct executionCompilerAssemblerInterpreterCPU
How programming languages are processed (simplified)

1. Machine Language (Hypothetical)

10101011 00000001  ; Load value 1 into register
00000010 00000011  ; Add value 3 to register

(Note: Actual machine code varies by CPU architecture.)

2. Assembly Language (x86)

MOV AX, 5    ; Load 5 into AX register
ADD AX, 3    ; Add 3 to AX (result: 8)

(Assembled into machine code by an assembler.)

3. High-Level Language (Python)

# Procedural-style
def add(a, b):
    return a + b

result = add(5, 3)
print(result)  # Output: 8

4. SQL (4GL)

-- Query to fetch customer names from a database
SELECT name FROM customers WHERE age > 25;

Conclusion

Programming languages evolve to balance readability, performance, and usability. While machine language offers the fastest execution, high-level languages dominate modern software development due to their ease of use and portability. The choice of language depends on the project’s requirements, scalability needs, and the developer’s expertise.

Discussion

Loading…

More Computer Science questions

All Computer Science old questions