Comparative Programming Flashcards

1
Q

Functional language

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Object-oriented language

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Object-based OO

A
  • No inheritance
  • No classes required
  • Direct construction and cloning to make instances
  • Methods and slots attached to objects
  • For example, delegation, traits, prototyping
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Class-based OO

A
  • Supports inheritance but not all languages can support multiple inheritance
  • Doesn’t require cloning to make instances
  • For example, fixed and metaobject protocols
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Delegation

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Traits

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Prototyping language

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Differential inheritance

A
  • Different from class centred inheritance, the cloned object contains all of its own methods and attributes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Procedural language

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Scripting language

A

  • 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Logic language

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Macro language

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Actor language

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Event-driven language

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Dataflow language

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Markup language

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Call by value

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Call by name

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Call by need

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Call by reference

A
  • 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 &
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Multiple inheritance

A
  • A class can inherit from more than one parent
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Declarative language

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Imperative language

A
  • The program describes the action to be taken
  • For example: C, Java, Lisp
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Interpreted and compiled

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Execution of bytecode languages

A

1) The source file passes through the compiler, which then encodes the source into bytecode, which is a machine independent encoding
2) The content of each class is stored in a separate file. These files are independent of the machine or the OS, which allow them to be run any system
3) While converting into bytecode, the compiler performs these 7 steps: parse, enter, process annotations, attribute, flow, desguar and generate
4) The class is passed to the JVM
5) The class is loaded into the memory by passing its bytecode to the JVM, through invoking the JVM
6) It is then verified to make sure that the instructions don’t perform any damaging actions
7) After verification, it is passed into a JIT compiler in order to convert the bytecode into native machine code

26
Q

Abstraction

A
  • Irrelevant details are hidden
  • Helps programming at a higher concept level
  • Solves problems in the design level
  • Is applicable to all kinds of OO languages
27
Q

Encapsulation

A
  • The structure and the implementation is kept hidden from the programmer behind a well-defined interface.
  • Allows changing details of implementation at a lower level without affecting the higher levels.
  • Solves problems in the implementation level
  • Applicable for all kinds of OO languages
28
Q

Inheritance

A
  • When a class acquires properties of another class
  • Allows sharing of properties in a hierarchy, thus avoiding re-implementation across related objects
  • Not applicable to all kinds of OO languages, in particular prototype-based languages.
29
Q

Polymorphism

A
  • Treating different objects in different ways depending on their types
  • Not applicable to all kinds of OO languages
30
Q

Class Precedence List

A
  • A list of an argument in a method call, it is a linear list of superclasses starting with a class of the argument
  • Used for determining which method to call if there is more than one method applicable to the object
  • Problem when multiple inheritance is supported: deciding which class should be prioritised in the list
31
Q

Computing a CPL

A
  • Collect all superclasses and perform a depth first search from the root (lowest-level) class
  • There are two ways of ordering these:
    1) Flavours: if a class occurs more than once, only take the leftmost occurrence and discard the others
    2) Loops: take the rightmost occurrence
32
Q

Alternatives to multiple inheritance

A
  • Interfaces: provide method signatures without the functionality of the method, doesn’t require overriding
  • Class composition: classes within a class (implements multiple behaviours rather than inherit), for example IO streams contain an input stream and an output stream. Advantage is that it can specify which class the function is coming from.
33
Q

Metaobject protocol

A
  • A means by which we describe what kind of object protocol we want.

Exposes the internal mechanisms of;

  • Structure: how objects are structured
  • Methods: how methods are chosen
  • Classes: how properties are inherited (if we have inheritance) and so on
34
Q

Subtype polymorphism

A
  • A type of polymorphism that arises when defining a function on a type and applying it to an instance of a subtype
  • A method defined on the class will work on an instance of the subclass even though they are not the same types
35
Q

Parametric polymorphism

A
  • Defines types or functions that are generic over other types, which can be expressed by using variables for the parameter type
  • For example, adding a number to a integer x in a Haskell function
36
Q

Monomorphism

A
  • Types are determined by the variables and are checked via them
  • Takes only one type and gives out only one type
37
Q

Monomorphisation

A

Replace a polymorphic object with multiple monomorphic objects

Example code:
int f_int(int x) {
return -x;
}

double f_double(double x) {
return -x;
}

The example is an implementation of overloading as the underlying code in the first method is different from the code in the second method

38
Q

Overloading

A

The ability to create multiple functions of the same name but with different implementations.

Example code:
int f(int n) { ... }
double f(int n) { ... }
39
Q

Statically-typed languages

A
  • A language in which types are fixed at compile time
  • For example, C and Java

Problems well suited to this language: eg: print the first 100 prime numbers.

Advantages:

  • Generally perform better than dynamically typed
  • Better code completion
  • Reduced likelihood of errors

Disadvantages:

  • More verbose as types need to be declared for every variable and function parameter
  • Requires compilation which can take time
40
Q

Dynamically-typed languages

A
  • A language in which types are discovered at execution time
  • For example, Python and Perl
  • They figure out the type of variable when it’s assigned a value

Problems well suited to this language: Desktop/ windowing applications

Advantages:

  • Less verbose
  • More tolerant to change since code changes are more localised

Disadvantages:

  • Unpredictable performance due to reliance on more sophisticated optimisations
  • More likely for run-time errors to occur
41
Q

Untyped languages

A
  • Programmer decides how to interpret a value
  • Values are either byte or word
  • No type errors possible, and no checking for the programmer
  • Examples: assembly, BCPL
42
Q

Strongly typed languages

A
  • A language in which types are always enforced
  • Doesn’t allow types to be treated differently without explicitly converting them
43
Q

Weakly typed languages

A
  • A language in which types may be ignored
  • For example, Perl
44
Q

Type constructor

A
  • Makes a new type out of the input type
  • For example: vector: T -> vector<t></t>
45
Q

Garbage collector

A

Code that searches through memory for memory that is no longer accessible to the user program.

Languages with integrated GC include Haskell, Java, JavaScript, Python, Lisp.

Problems well suited to this language: word processors, some video games

Advantages:
- No memory leaks for programmer to worry about

Disadvantages:

  • GC code uses twice the space that it’d normally require: space for data + space for allocation
  • Encourages poor programming (poor use of memory)
  • Extra overhead for programs at run-time
  • Leads to pauses in program as program pauses to let GC do its thing (bad for real time programs)
46
Q

Manual Memory Management

A

Does not use GC. Programmer has to manage memory.

Problems well suited to this language: video and audio streaming.

Advantages:
1) Allows precise control of how memory is used and allocated

Disadvantages:

1) Can lead to memory leaks
2) Can be hard to keep track of memory references. Programmer has to be careful.

47
Q

Memory leak

A
  • An undesirable state in which a program keeps allocating memory but never releases it.
  • Can eventually prevent other programs from running/ lead to the program crashing
48
Q

Method dispatch

A

Choosing a method that is appropriate for solving an issue or running a program

There are two types:
1) Static dispatch, which uses the type of the variable. Can be completely compiled away

2) Dynamic dispatch, which uses the type of the current object contained in the variable. It will need the compiler to output some code to pick a method at runtime

49
Q

Multiple dispatch

A

Dispatching on the type of one or more objects

50
Q

Subsets of static typing

A

1) Manifest
- Program code includes the types of variables

2) Implicit
- The compiler infers any types it needs (as much as it can)

51
Q

Dependent type

A
  • A type depends on a value
  • May require the compiler to run arbitary code to check the type
52
Q

Mutable variable

A
  • A variable in which its state can be modified after creation

Advantage:
- Changes can be made in-place without reallocation

Disadvantage:
- Can lead to conflict with other objects

53
Q

Immutable variable

A
  • A variable in which its state can be modified after creation

Advantage:
- The compiler can spot a value trying to be modified when it shouldn’t be, therefore good when error checking

Disadvantage:
- Difficult to use when working with cyclic data structures

54
Q

Applicable method

A

A method is applicable to a call with args (a₁, a₂, . . .) if it is defined for classes (A₁, A₂, . . .) where for each i, the class of aᵢ is a subclass of Aᵢ

55
Q

More specific method

A

A method with domain (A₁, A₂, . . . , Aₙ) is more specific than a method with domain (B₁, B₂, . . . , Bₙ) for the arguments (a₁, a₂, . . . , aₙ) if they are both applicable and there is a k with Aᵢ = Bᵢ for i < k, but Aₖ appears before Bₖ in the CPL for argument aₖ

56
Q

CLOS

A
  • Stands for Common Lisp Object System
  • Classes that describe the structure and behaviour of classes
  • Methods that describe how objects should be created and initialised
  • Methods that describe how methods are looked up
  • Methods that describe how methods should be inherited or overridden or combined
  • And so on for all aspects of an OO system
57
Q

Compile once, run anywhere

A
  • Used to describe Java
  • Once compiled, the code can be executed on different devices without the need for compilation every time
  • This is because compilation of Java code generates a bytecode, which can run on any device on the condition it has a JVM (Java Virtual Machine)
58
Q

Compile anywhere, run everywhere

A
  • A program can be compiled on all platforms without needing to modify its source code
  • Cross-platform capability is implemented only at the source code, and not at binary level
59
Q

Compilers vs Interpreters

A
  • Interpreters take less time to analyse the source code but overall execution is slower
  • Interpreters don’t generate any immediate object code, therefore they are memory efficient
  • Compilers generate intermediate object code which further require linking, hence requiring more memory
  • Interpreters continue translating the program until the first error is met, in which case it stops, hence debugging is easy
  • Since compilers generate the error message only after scanning the whole program, debugging is comparatively harder
60
Q

Native compiler vs bytecode

A

Bytecode advantages

  • Platform independence: Inserting its virtual machine between the application and the real environment (OS + computer) limits compatibility issues regarding interpretations of bytecode on each system
  • Size: Since bytecodes don’t generate any object code, they are more memory efficient

Native compiler advantages

  • Overall execution is quicker as there are less intermediate execution steps
  • Harder to decompile (convert executable code into a readable higher-level language)