UNIHIVE

Study Hub UNIPORT CSC 392

CSC 392 · Automata Theory, Computability and Formal Languages

The role of programming languages and their paradigms

Why high-level languages exist, the main paradigms (imperative, object-oriented, functional, logic) and general against special-purpose languages.

Our notes

2 min read

Why programming languages

A programming language is a notation for describing computations precisely enough for a machine to carry them out, and clearly enough for people to read. Machine code is exact but unreadable; English is readable but ambiguous. Languages sit between.

Benefits of high-level languages

  • Closer to the problem: total := total + price instead of register loads and adds.
  • Portability: the same program runs on different machines with a compiler or interpreter for each.
  • Fewer errors: type checking and structured control catch mistakes.
  • Productivity: one statement does the work of many machine instructions.
  • Maintainability: easier to read and change.

The cost: some loss of direct control and, occasionally, of speed.

Paradigms

ParadigmIdeaExamples
Imperative (procedural)a sequence of commands that change variables (state)Fortran, C, Pascal
Object-orientedobjects bundle data and the operations on it; classes, inheritance, polymorphismJava, C++, Python, C#
Functionalcomputation as evaluating functions without changing state; functions are valuesHaskell, Lisp, ML, F#
Logic (declarative)state facts and rules; the system searches for answersProlog

Many modern languages are multi-paradigm: Python and JavaScript support imperative, object-oriented and functional styles.

Example: the same task in different styles

Sum the squares of a list [1, 2, 3, 4]:

  • Imperative: start total at 0; for each x add x × x. Result 30.
  • Functional: sum (map square list) = 1 + 4 + 9 + 16 = 30.
  • Logic: define sumsq([], 0) and sumsq([H|T], S) :- sumsq(T, S1), S is S1 + H × H; ask sumsq([1,2,3,4], S).

General and special purpose

  • General purpose: usable for most tasks (C, Java, Python).
  • Special purpose / domain-specific: SQL (databases), HTML and CSS (web pages, markup rather than programming), MATLAB (numerical work), R (statistics), ladder logic (PLCs), regular expressions (pattern matching).

Compilers and interpreters

  • Compiler: translates the whole program to machine code (or bytecode) before running.
  • Interpreter: executes the program statement by statement.
  • Hybrid: Java compiles to bytecode run by a virtual machine with just-in-time compilation.

The front end of every compiler rests on the formal language theory of this course: regular expressions for words (lexical analysis), grammars for sentences (parsing).

Exams usually ask

  • State the benefits of high-level languages.
  • Describe the programming paradigms with examples.
  • Distinguish general-purpose and domain-specific languages.

Common mistake

Calling a language "object-oriented" or "functional" as if it can be only one. Paradigms are styles; many languages support several.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

No reading links here yet

Our team adds free books, videos and practice for each topic, and opens every link before it goes up.

All CSC 392 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.