Definitions Flashcards
Briefly describe the main differences between weakly typed and strongly typed languages.
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.
Explain what it means for a function call to be tail-recursive.
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.
Define the term uniform access principle.
The ability to get a value without having to know whether it is stored in a variable or being computed by a function.
Briefly explain the concept of referential transparency. You should provide appropriate examples using functional and imperative programming languages.
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.
Briefly describe the main differences between static typing and dynamic typing. What are the relative advantages and disadvantages?
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
Define the term atomic operation.
An operation that, from the viewpoint of another thread, is instantaneous; it either has been completed, or has not been started.
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) Access to shared resources from different threads of control.
(b) Solutions including shared memory, monitors, and synchronous message passing (e.g., actors and agents)
Discuss how the following object-oriented concepts help a programmer design and implement an application. Illustrate your answer with appropriate examples:
- encapsulation
- inheritance
- polymorphism
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
Distinguish between lazy and eager evaluation in the implementation of applicative (functional) programming languages, illustrating your answer with suitable examples.
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).
What are the different programming paradigms?
The main paradigms are functional, imperative, logical, object oriented and concurrent.
Every paradigm has pros and cons, strength and weaknesses.
What are Interpreted and Compiled languages and their pros and cons?
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.
Define the functional paradigm and its pros & cons?
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
Define the imperative paradigm and its pros & cons?
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
Define the logical paradigm and its pros & cons?
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
Define the object oriented paradigm and its pros & cons?
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