Programming Languages · Language Design and Translation
Paradigms Concepts and Environments
Overview
Programming paradigms are the fundamental styles or models of computation that a language supports. Understanding them lets you classify any language and predict how programs are written, translated, and executed.
This topic sits in the Language Design and Translation area of the UGC NET syllabus.
You should already know basic programming constructs (variables, control flow, functions) and the difference between source code and machine code.
The notes cover paradigm definitions, language classification, execution environments, and key concepts such as extensibility, aliasing, and parameter passing.
Key concepts
- Imperative paradigm: A program is a sequence of statements that change a program state. Procedural (C, Pascal, Fortran, BASIC) and object-oriented (Java, C++, Simula 67) are sub-paradigms. Order of statements matters.
- Declarative paradigm: A program specifies what to compute, not how. Two main sub-paradigms: functional and logic. Order of evaluation is often less significant.
- Functional paradigm: Computation is evaluation of expressions. Functions are first-class values; pure functions have no side effects and are referentially transparent (same input gives same output).
Lisp (John McCarthy, 1958/1960) is the first functional language. Haskell (1990) is purely functional with lazy evaluation and type classes. Lambda calculus (Alonzo Church, 1932) is the theoretical foundation.
Lazy evaluation was introduced by Wordsworth in 1970. Other functional languages: Scheme, OCaml, Mercury. - Logic paradigm: A program is a set of facts and rules. Computation is a query answered by unification and backtracking. Prolog is the classic language; Mercury is a modern logic language.
The Byrd box model describes execution with four ports: Call, Exit, Redo, Fail. - Object-oriented paradigm: Programs are collections of objects that encapsulate state and behavior. Core features: encapsulation, inheritance, polymorphism, dynamic dispatch (virtual method tables).
Simula 67 is historically the first OO language; Java, C++, Python are widely used. - Hybrid/multi-paradigm languages: Support more than one style. Python supports procedural, OO, and some functional features. OCaml supports functional, imperative, and OO. JavaScript supports procedural, OO, and functional.
- Extensibility: The ability of a language to allow programmers to define new data types, operations, or syntax. A language with this capability is called extensible. (Do not confuse with overloaded or encapsulated.)
- Aliasing: Two or more names or references designate the same memory location. An assignment through one name changes the value seen through the other. Common with pointers and call-by-reference.
- Compiler: Translates the entire source program into target code (machine code or intermediate code) before execution. Interpreter: Executes the source program directly, statement by statement.
A pure interpreter performs no prior translation. A bootstrapped compiler is written in the language it compiles and requires an existing compiler for that language to build. - Evaluation criteria for languages: application-oriented features, efficiency and reliability, software development; hardware maintenance cost is not a standard language evaluation criterion.
- Code blocks: Named groups of statements that improve program structure. They enable algorithms to be implemented with clarity, elegance, and efficiency.
- Parameter passing: Call-by-value copies the argument; call-by-reference passes an alias (causes aliasing); call-by-name re-evaluates the argument each time it is used; call-by-need (lazy) evaluates at most once when needed.
Functional languages typically use call-by-need. - Referential transparency: An expression can be replaced by its value without changing the program's behavior. Pure functional programs have this property.
How it works
- Classifying a language into a paradigm: Start from the computation model. If the program is a sequence of commands that mutate state, it is imperative.
Within imperative, if it uses classes and objects, it is object-oriented; otherwise procedural. If the program is declarative, check whether it is based on functions (functional) or logical relations (logic).
Hybrid languages may belong to multiple categories. - Execution environment: A compiler translates the whole program to target code; an interpreter executes source directly. Many modern systems use a hybrid: compile to bytecode, then interpret or JIT-compile.
- Prolog execution: A query is unified with facts and rules. If multiple clauses match, Prolog chooses one and may backtrack.
The Byrd box ports are Call (goal entered), Exit (goal succeeds), Redo (backtracking into goal), Fail (goal fails). - Functional evaluation: Pure functions are evaluated by substitution. Lazy evaluation delays argument evaluation until needed, allowing infinite data structures. Eager evaluation evaluates arguments before the call.
- Aliasing: When two names refer to the same location, modifying one affects the other. This is a common source of bugs in call-by-reference and pointer code.
Drawing the diagram…
Drawing the diagram…
Worked examples
Example 1 (Match-the-list): Match List-I (Language) with List-II (Paradigm).
List-I: A. Prolog, B. Lisp, C. C, D. Java.
List-II: i. Logic, ii. Functional, iii. Procedural, iv. Object-Oriented.
Solution: Prolog is logic (i). Lisp is functional (ii). C is procedural (iii). Java is object-oriented (iv). So A-i, B-ii, C-iii, D-iv.
Example 2 (Statement type): Consider:
Statement I: A pure functional program avoids side effects and mutable state.
Statement II: A logic program is written as facts and rules, and computation is a query.
Are both statements true? Yes. Pure functional programs use immutable data and functions without side effects, ensuring referential transparency. Logic programs consist of facts and rules; a query triggers unification and backtracking. Answer: Both true.
Example 3 (Python code): What is printed?
def f(x):
x = x + 1
return x
a = 10
b = f(a)
print(a, b)
a = 10. Step 2: callf(a); the value 10 is passed. Inside,xbecomes 11 and is returned. Step 3:b = 11. Because integers are immutable in Python, the originalaremains 10. Output:10 11.
Example 4 (Haskell lazy evaluation): Given ones = 1 : ones, what is the sum of take 4 (map (*2) ones)?
ones is an infinite list of 1s. map (*2) ones is an infinite list of 2s. take 4 forces only the first four elements: [2,2,2,2]. Sum = 2+2+2+2 = 8. Answer: 8. This works because Haskell evaluates lazily; infinite lists are computed only as needed.
Example 5 (Scheme closure): What does (add5 10) return?
(define (make-adder n)
(lambda (x) (+ x n)))
(define add5 (make-adder 5))
(add5 10)
make-adder returns a lambda that captures n via lexical scoping. add5 is a closure with n = 5. Calling (add5 10) computes 10 + 5 = 15. Answer: 15.
Comparison
| Paradigm | Core idea | Mutable state | Typical languages | Key feature |
|---|---|---|---|---|
| Imperative | Sequence of commands | Yes | C, Pascal, Fortran, BASIC | Order of statements matters |
| Functional | Evaluation of pure functions | No (pure) | Lisp, Haskell, OCaml, Scheme | First-class functions, referential transparency |
| Logic | Facts and rules, queries | No | Prolog, Mercury | Unification, backtracking |
| Object-oriented | Objects encapsulate state and behavior | Yes (object state) | Java, C++, Simula 67, Python | Encapsulation, inheritance, dynamic dispatch |
| Feature | Compiler | Interpreter |
|---|---|---|
| Translation | Whole program to target code before execution | Executes source directly, statement by statement |
| Speed | Faster execution after compilation | Slower execution, faster startup |
| Error detection | Before execution | During execution |
| Memory | More memory for target code | Less memory |
| Parameter passing | Mechanism | Aliasing possible? | Typical paradigm |
|---|---|---|---|
| Call-by-value | Copies the value | No | Imperative, functional (eager) |
| Call-by-reference | Passes address | Yes | Imperative |
| Call-by-name | Re-evaluates argument textually | Depends | Functional (historical) |
| Call-by-need | Lazy evaluation, at most once | No | Purely functional (Haskell) |
| Language | Dominant paradigm | Notes |
|---|---|---|
| Lisp | Functional | First functional language, McCarthy 1960 |
| Prolog | Logic | Facts, rules, unification, backtracking |
| C | Procedural | Imperative, structured |
| Java | Object-oriented | Statically typed, OO |
| Python | Multi-paradigm | Dynamically typed, OO and procedural |
| Haskell | Functional | Purely functional, lazy, type classes |
| Ada | Procedural (with OO extensions) | Statically typed |
| Pascal | Structured procedural | Designed for structured programming |
| Fortran | Procedural | Historically non-structured |
| BASIC | Interpreted procedural | Often non-structured |
| Simula 67 | Object-oriented | First OO language |
| OCaml | Multi-paradigm | Functional, imperative, OO |
| Mercury | Logic/functional | Modern logic language |
Note on a past UGC NET key: Some answer keys label Prolog as “statically non-object-oriented”, but standard textbooks classify Prolog as dynamically typed and not object-oriented. The key’s intent is that Prolog is not object-oriented; treat “statically” as an error in the option.
Revision summary
- LISP is functional; Prolog is logic; C is procedural; Java is OO.
- Extensible = can create new data types; not overloaded or encapsulated.
- Prolog trace ports: Call, Exit, Redo, Fail (four ports in Byrd box).
- Pure functional programs have no side effects and are referentially transparent.
- Lazy evaluation allows infinite lists; eager evaluation does not.
- Aliasing = two names for the same memory location.
- Compiler translates whole program before execution; interpreter executes directly.
- Bootstrapped compiler is written in the language it compiles.
- Lambda calculus (Church 1932) is foundation of functional programming.
- Code blocks improve clarity, elegance, and efficiency.
- Call-by-reference can cause aliasing; call-by-value does not.
- Hardware maintenance cost is not a language evaluation criterion.
Previous-year exam insights
- Direct concept questions ask for the paradigm of a language (e.g., LISP is functional) or the term for a property (extensible language).
- Match-the-list questions pair languages with paradigms (Prolog-logic, Lisp-functional, C-procedural, Java-OO) and historical milestones (Church 1932, McCarthy 1960, lazy evaluation Wordsworth 1970, type classes Haskell 1990).
- Prolog debugging uses the Byrd box model; the four events are Call, Exit, Redo, Fail.
Missing one port is a common trap. - Language classification questions mix typing (static/dynamic) with paradigm (OO/non-OO).
Check both axes; note the UGC key’s typo for Prolog. - Aliasing is defined as multiple variables having the same memory location, not same value or same identifier.
- Compiler vs interpreter questions test the definition and the term “pure interpreter” and “bootstrapped compiler”.
- Statement/assertion questions test pure functional properties (no side effects) and logic program structure (facts and rules).
- Code-tracing questions use immutable integers, closures, and lazy evaluation; trace carefully with the given semantics.
Practice at PARIKSHA
You are ready for the PARIKSHA tests of this sub-topic when you can:
- Name the paradigm of Lisp, Prolog, C, Java, Haskell, and Python.
- Define extensibility and distinguish it from overloading and encapsulation.
- List the four ports of the Prolog Byrd box model.
- Explain referential transparency and why pure functional programs have it.
- Trace a simple Python program with integer arguments and state the output.
- Evaluate a finite prefix of an infinite Haskell list under lazy evaluation.
- Distinguish compiler, interpreter, pure interpreter, and bootstrapped compiler.
- Define aliasing and give an example using call-by-reference.
- Match historical milestones (lambda calculus, Lisp, lazy evaluation, type classes) with their dates and people.
- Identify the correct pair of typing and paradigm for Java, Python, Prolog, and Ada.
Attempt the sub-topic test first, then the subject test.