Programming paradigms Flashcards
Imperative
Control flow is an explicit sequence of commands
Declarative
Programs state the result you want, not how to get it
Structured
Programs have clean, goto-free, nested control structures
Procedural
Imperative programming with procedure calls
Functional (Applicative)
Computation proceeds by (nested) function calls that avoid any global state
Function-Level (Combinator)
Programs have no variables. No kidding
Object-Oriented
Computation is effected by sending messages to objects; objects have state and behavior
Object-Oriented: Class-based
Objects get their state and behavior based on membership in a class
Object-Oriented: Prototype-based
Objects get their behavior from a prototype object
Event-Driven
Control flow is determined by asynchronous actions (from humans or sensors)
Flow-Driven
Computation is specified by multiple processes communicating over predefined channels
Logic (Rule-based)
Programmer specifies a set of facts and rules, and an engine infers the answers to questions
Constraint
Programmer specifies a set of constraints, and an engine infers the answers to questions
Aspect-Oriented
Programs have cross-cutting concerns applied transparently
Reflective
Programs manipulate their own structures
Array
Operators are extended to arrays, so loops are normally unnecessary
Concurrent by default
For example, imagine you wrote three lines of code, A, B, and C:
A;
B;
C;
In most programming languages, A would execute first, then B, and then C. In a language like ANI, A, B, and C would all execute at the same time!
Dependent types
You’re probably used to type systems in languages like C and Java, where the compiler can check that a variable is an integer, list, or string. But what if your compiler could check that a variable is “a positive integer”, “a list of length 2”, or “a string that is a palindrome”?
This is the idea behind languages that support dependent types: you can specify types that can check the value of your variables at compile time.
Concatenative languages
The idea is that everything in the language is a function that pushes data onto a stack or pops data off the stack; programs are built up almost exclusively through functional composition (concatenation is composition).
This sounds pretty abstract, so let’s look at a simple example in cat:
2 3 +