Definitions Flashcards

1
Q

Briefly describe the main differences between weakly typed and strongly typed languages.

A

Weakly typed languages allows a type to be interpreted as another.

Strongly typed languages, also called type safe, means that applying the wrong operation to typed data will result in error.

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

Explain what it means for a function call to be tail-recursive.

A

The recursive call is the very last thing done in the function or, more accurately, every possible path through the function returns either a result computed without recursion, or a result that is the unmodified result (i.e., no further work is done) of a recursive call.

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

Define the term uniform access principle.

A

The ability to get a value without having to know whether it is stored in a variable or being computed by a function.

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

Briefly explain the concept of referential transparency. You should provide appropriate examples using functional and imperative programming languages.

A

An expression is said to be referentially transparent if it yields the same effects & outputs on the same input.

For example, in an imperative language an expression may evaluate differently based on the program state, so imperative programming lacks referential transparency, or referential opacity.

In a functional language functions do not have side effects, i.e., they do not modify program state which means it has referential transparency.

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

Briefly describe the main differences between static typing and dynamic typing. What are the relative advantages and disadvantages?

A

Static typing means that types and their constraints are checked before executing the program.
• pro: less error-prone
• con: sometimes too restrictive

Dynamic typing mean that type checking is done during program execution.
• pro: more flexible
• con: harder to debug

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

Define the term atomic operation.

A

An operation that, from the viewpoint of another thread, is instantaneous; it either has been completed, or has not been started.

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

For many real-world applications it is often desirable for a programming language to support concurrency. This requires solutions to the problems of process synchronisation and communication.

(a) Explain how these problems arise.
(b) Describe the range of solutions that are available.

A

(a) Access to shared resources from different threads of control.
(b) Solutions including shared memory, monitors, and synchronous message passing (e.g., actors and agents)

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

Discuss how the following object-oriented concepts help a programmer design and implement an application. Illustrate your answer with appropriate examples:

  1. encapsulation
  2. inheritance
  3. polymorphism
A

Encapsulation the ability to provide users with a well-defined interface to a set of functions in a way which hides their internal workings. In object-oriented programming, the technique of keeping together data structures and the methods which act on them.

Inheritance the ability to derive new classes from existing classes. A derived class (“subclass”) inherits the instance variables and methods of the base class (“su- perclass”), and may add new instance variables and methods. New methods may be defined with the same names as those in the base class, in which case they override the original one.

Polymorphism in object-oriented programming, the term is used to describe variables which may refer at run-time to objects of different classes.

Pros:

  • implementation reuse
  • inheritance for interface extension and reuse
  • encapsulation for robustness and reliability
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Distinguish between lazy and eager evaluation in the implementation of applicative (functional) programming languages, illustrating your answer with suitable examples.

A

Lazy evaluation, or call-by-need is an evaluation strategy which delays the evaluation of an expression until its value is needed (non-strict evaluation) and which also avoids repeated evaluations (eval is remembered).

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

What are the different programming paradigms?

A

The main paradigms are functional, imperative, logical, object oriented and concurrent.

Every paradigm has pros and cons, strength and weaknesses.

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

What are Interpreted and Compiled languages and their pros and cons?

A

Compiled languages (C#, C++, Java, etc.) are translated into a form that can be run directly on the computer’s processor. Typically it’s translated before its run for greater speed and efficiency at the cost of lowering productivity.

Interpreted languages (ruby, python, JavaScript, etc.) are processed by a higher level virtual machine. Typically, the program or statements are translated on demand and then executed. This is for greater extensibility, agility and productivity at the cost of lowering runtime performance.

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

Define the functional paradigm and its pros & cons?

A

Functional programming treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data.

Functional programming makes concurrency easier, because:

  • functions are side-effect free and stateless
  • nothing to synchronize, so no locks, semaphores, mutexes
  • Functional paradigm encourages immutable data, which is good for concurrency

Pros:

  • functional languages behave very similar to mathematical functions it’s easy to translate those into functional languages
  • No side effects

Cons:

  • steep learning curve
  • potential lack of IO capabilities.

Languages: Haskell, Racket, Scheme, Closure

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

Define the imperative paradigm and its pros & cons?

A

Imperative programming (procedural) is based on the von Neumann architecture where incremental change of the program state is changed over time though commands governed by control structures.

The natural abstraction is a procedure which abstracts one or more statements as a single command, hence procedural programming.

Pros:

  • good for general purpose programming
  • many resources available - no need to reinvent the wheel

Cons:

  • difficult to maintain the larger the code gets
  • portions of the code are so interdependent that the code in one application will not be useable in another, unlike in OOP

Languages: Fotran, Pascal, C

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

Define the logical paradigm and its pros & cons?

A

Logical programming is based on formal logic and is written as a set sentences in logical form expressing facts and rules about a problem domain where answers are systematically searched for by inferencing from rules and facts.

Pros:

  • Good for AI, and niche applications
  • Well suited to express complex ideas, allowing the dev to focus on what letting the program figure out how.

Cons:

  • Steep learning curve a
  • Inefficient and doesn’t scale well with large knowledge bases.

Languages: Prolog, Datalog

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

Define the object oriented paradigm and its pros & cons?

A

OO programming is based on the concept of objects which model the real world problem domain. Data and operations are encapsulated into objects and objects interact by means of passing messages.

Pros:

  • Encapsulation -
  • Inheritance -
  • Reusability and extensible -

Cons:
- Side effects

Languages: Java, Ruby

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

Define the concurrent paradigm and its pros & cons?

A

Concurrent programming has multiple threads of control allowing it to perform multiple computations in parallel and control external activities to happen at the same time.

Note that parallelism != concurrency. Parallelism is about speed and concurrency is distribution, redundancy, etc.

Pros:

  • allows a process to overlap IO and computation
  • can make a program more responsive (e.g., a GUI thread can respond to button clicks while another thread performs some task in the background). ?
  • can speedup performance.

Cons:
- Considered to be very hard!

Langages: Erlang, Scala

17
Q

Define the polyglot paradigm and its pros & cons?

A

Polyglot programming combes multiple programming languages / paradigms.

Pros:

  • able to use the best tool for a particular job
  • minimize the amount of code required
  • better decoupling between components

Cons:

  • multiple tools, languages, libraries to manage and learn
  • need to manage the different metadata models
  • overhead of calls between languages
18
Q

What is a programming paradigm?

A

A pattern that serves as a school of thought for programming.