1. Gyanastra
  2. Programming Languages
  3. Language Design and Translation
  4. Paradigms Concepts and Environments
Free lesson, no account needed 10 min read 27 practice questions after it
Asked in past papers8 times
  • GATE CSE20042002
  • UGC NET201620152014201320122008

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

  1. 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.
  2. 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.
  3. 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).
  4. 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.
  5. 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.
Figure. Notice that imperative paradigms are divided into procedural and object-oriented, while declarative paradigms are divided into functional and logic.
Figure. Notice the compiler path produces target code before execution, while the interpreter path goes from source code directly to execution.

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)
  1. a = 10. Step 2: call f(a); the value 10 is passed. Inside, x becomes 11 and is returned. Step 3: b = 11. Because integers are immutable in Python, the original a remains 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

ParadigmCore ideaMutable stateTypical languagesKey feature
ImperativeSequence of commandsYesC, Pascal, Fortran, BASICOrder of statements matters
FunctionalEvaluation of pure functionsNo (pure)Lisp, Haskell, OCaml, SchemeFirst-class functions, referential transparency
LogicFacts and rules, queriesNoProlog, MercuryUnification, backtracking
Object-orientedObjects encapsulate state and behaviorYes (object state)Java, C++, Simula 67, PythonEncapsulation, inheritance, dynamic dispatch
FeatureCompilerInterpreter
TranslationWhole program to target code before executionExecutes source directly, statement by statement
SpeedFaster execution after compilationSlower execution, faster startup
Error detectionBefore executionDuring execution
MemoryMore memory for target codeLess memory
Parameter passingMechanismAliasing possible?Typical paradigm
Call-by-valueCopies the valueNoImperative, functional (eager)
Call-by-referencePasses addressYesImperative
Call-by-nameRe-evaluates argument textuallyDependsFunctional (historical)
Call-by-needLazy evaluation, at most onceNoPurely functional (Haskell)
LanguageDominant paradigmNotes
LispFunctionalFirst functional language, McCarthy 1960
PrologLogicFacts, rules, unification, backtracking
CProceduralImperative, structured
JavaObject-orientedStatically typed, OO
PythonMulti-paradigmDynamically typed, OO and procedural
HaskellFunctionalPurely functional, lazy, type classes
AdaProcedural (with OO extensions)Statically typed
PascalStructured proceduralDesigned for structured programming
FortranProceduralHistorically non-structured
BASICInterpreted proceduralOften non-structured
Simula 67Object-orientedFirst OO language
OCamlMulti-paradigmFunctional, imperative, OO
MercuryLogic/functionalModern 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:

  1. Name the paradigm of Lisp, Prolog, C, Java, Haskell, and Python.
  2. Define extensibility and distinguish it from overloading and encapsulation.
  3. List the four ports of the Prolog Byrd box model.
  4. Explain referential transparency and why pure functional programs have it.
  5. Trace a simple Python program with integer arguments and state the output.
  6. Evaluate a finite prefix of an infinite Haskell list under lazy evaluation.
  7. Distinguish compiler, interpreter, pure interpreter, and bootstrapped compiler.
  8. Define aliasing and give an example using call-by-reference.
  9. Match historical milestones (lambda calculus, Lisp, lazy evaluation, type classes) with their dates and people.
  10. Identify the correct pair of typing and paradigm for Java, Python, Prolog, and Ada.

Attempt the sub-topic test first, then the subject test.

Pages 1–2 of 2