Comparative Programming Flashcards
Functional language
General purpose: general and symbolic programming
Notable feature: uses higher order functions to provide structure and control complexity. This is because functions are values in their own right and can therefore be passed in other functions as arguments.
Advantages:
1) Supports parallelism
2) Gives more structuring mechanisms
Disadvantages:
1) Lots of mechanisms in the background mean that could run slower
2) No efficient vocabularies
Object-oriented language
Notable features: uses objects (or classes) as a means of controlling complexity rather than functions and logic
General purpose: kind of general purpose
Advantages:
1) Allows code re-use,
2) Easy to understand
Disadvantages:
1) Generally takes longer to create programs using this type of language
2) Unnecessary generalisation, can be verbose
Note: Object centred languages are often dynamically typed, while class centred languages are often statically typed
Object-based OO
- No inheritance
- No classes required
- Direct construction and cloning to make instances
- Methods and slots attached to objects
- For example, delegation, traits, prototyping
Class-based OO
- Supports inheritance but not all languages can support multiple inheritance
- Doesn’t require cloning to make instances
- For example, fixed and metaobject protocols
Delegation
- One kind of object, one kind of link
- Objects have a parent object; inheritance to parent object
- Object contains its own attributes, behaviours and link to a parent
- If there is an applicable method in the object, use it, otherwise pass to the parent
Traits
- Two types of object, one kind of link
- A collection of method signatures
- They are not classes but encapsulate behaviour of objects
- The methods are pulled out of the object and have a separate existence in a trait
- Behaviour can be reused independently of the parent hierarchy
- Example: Java interfaces
Prototyping language
- One kind of object, no links
- Typified by:
1) An object containing its own attributes (slots) and behaviours (methods), not a class
2) Attribute and behaviour lookup both done by interrogating the object
3) Creating a new object by direct construction or by cloning
4) No inheritance in the class-centred sense, but an object can itself call other methods as it sees fit: an object could contain an object of another type and treat that as its parent, calling its methods explicitly which is less efficient (requires runtime lookups) but more flexible
Differential inheritance
- Different from class centred inheritance, the cloned object contains all of its own methods and attributes
Procedural language
Follows a set of commands in order. Purpose is general programming.
Notable feature: uses functions (or procedures) to provide structure and to control complexity
Advantages:
1) Easy to keep track of program flow
2) You are able to re-use code at different places within the program without having to rewrite it every time
Disadvantages:
1) Limited encapsulation
2) Doesn’t allow writing of really large programs
Scripting language
- Languages that don’t do computation but aids in organising other kinds of computation, e.g. copying a file
- JavaScript, PHP, Perl, Python are example of scripting lang.
Purpose: control elements
Advantages:
1) They can provide high-level abstractions that make it easier to write correct code
2) Difficulties associated with compiling are avoided
Disadvantages:
1) There is an overhead at run-time as it is interpreted/ run at run-time rather than compile time.
Logic language
General purpose: logic programming
Notable feature: purely declarative, allows statements about what the program should output rather than explicit steps on how to reach said output.
Advantages:
1) Good for proofs
Disadvantages:
1) They’re very specific and can’t be used for more than its general purpose
Macro language
Purpose: to improve readability of other code, abstraction, textual manipulation
Examples: Latex, M4
Notable features: they are usually character or text based
Advantages:
1) Executed at compile time, rather than run time
2) Can be used in conjunction with another language
Disadvantages:
1) Limited in number of problems they can solve
Actor language
- An entity or object that communicates with other actors purely through messages
- Used in general programming, simulation, concurrent systems (Pong)
- Idea is to allow a way of having asynchronous communication between computations
- To have a concurrent way of programming allowing parallelism in execution
- Runtimes are complicated to make efficient; could have millions of actors, runtime will schedule them as it sees fit on avaiable hardware
Event-driven language
General purpose: used in interactive systems and simulations, is more of a style than a language family
Notable feature: doesn’t run in a set order, instead listens for an event to occur and handles when it does occur
Examples: Qt, GTK, Simula, VBA
Advantages:
- Doesn’t require a sequence of steps in order to achieve something
- Can run code in response to an event which in other languages, requires more checks
Disadvantages:
- Hard to understand flow of control
Dataflow language
- Purpose: asynchronous programming
- Notable feature: data driven computation
- Examples: SISAL, Strand, spreadsheets
Advantages:
- Supports parallelism
- Variables only need to be assigned once, therefore they update automatically
Markup language
- General purpose: describing objects, usually documents
- Examples: HTML, XML, CSS
- Notable features: use of notation to describe elements
Advantages:
- Create better structures for data to be displayed in and describe the metadata as a result
Disadvantages:
- Being text-based, it is hard to parse accurately and quickly
Call by value
The values of the argument expressions are passed to the functon call.
Advantage: only evaluates arguments once
Disadvantage: can be wasteful as values that don’t need to be evaluated are evaluated regardless
Call by name
Arguments to a function are not evaluated before the function is called, but instead substituted directly in the function and then re-evaluated every time they appear in the function. Takes expressions rather than the value of the expression
Advantage: If a function’s argument is not used in the function, call by name will save time by not evaluating the argument
Disadvantage: if the argument is used more then once, it is re-evaluated each time it appears and may return the same value every time
Call by need
A “memoizied” form of call by name that tries to get closer to the efficiency of call by value, where the given argument is evaluated at most once and then stored for subsequent uses.
Advantage: performance increases by avoiding needless calculations, and avoiding error conditions when evaluating compound expressions.
Disadvantage: Mechanisms are quite complex as it’s unsure whether to evaluate again if needed
For example, Haskell
Call by reference
- Instead of directly passing a variable’s value to a function, pass the address of the variable (location of variables) to the function
- Usually denoted as &
Multiple inheritance
- A class can inherit from more than one parent
Declarative language
The program is a description of the desired output, with little or no explicit direction on how to do it.
Notable feature: the system itself determines how to progress a computation. For example, an SQL engine must find the best way of finding the records that fit the query
Problems suited: database querying
For example: Haskell, SQL
Imperative language
- The program describes the action to be taken
- For example: C, Java, Lisp
Interpreted and compiled
Interpreted:
- Traverses line-by-line through the code
- At each line, read, check for errors and execute
- Will do everything before the error occurs
Compiled:
- Traverses through the whole program before running
- Checks for errors before running but won’t do everything before the code causing the error, the compiler will just return it