CSC 396 · Automata theory, Computability and Formal Languages
Our notes
2 min readWhy 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
| Paradigm | Idea | Examples |
|---|---|---|
| Imperative (procedural) | a sequence of commands that change variables (state) | Fortran, C, Pascal |
| Object-oriented | objects bundle data and the operations on it; classes, inheritance, polymorphism | Java, C++, Python, C# |
| Functional | computation as evaluating functions without changing state; functions are values | Haskell, Lisp, ML, F# |
| Logic (declarative) | state facts and rules; the system searches for answers | Prolog |
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.