Programming Paradigms Lecture Notes

Verified

Added on  2019/09/18

|2
|647
|530
Homework Assignment
AI Summary
This document appears to be a set of lecture notes on programming paradigms. It covers various topics including variable scope (file, block, function prototype, function scope), comparing scopes and shadowing issues. It delves into object-oriented programming principles like inheritance, encapsulation, and polymorphism, providing examples and highlighting the differences between static and dynamic typing. The notes also discuss function overloading and overriding, duck typing in Ruby, and the use of generics for static typing. A significant portion is dedicated to concurrency, including concepts like deadlock, livelock, independent processing, and transactions, along with explanations of lazy and eager evaluation. The notes conclude with a revision section highlighting key topics for review and further study, including abstract data types, Java interfaces, and Google MapReduce.
Document Page
Programming paradigms
Lecture 14 Variables and scopes
Pass function to another function, what would be the scope of the
function?
Four types of scope: file scope, block scope, function prototype scope, and
function scope. Block scope maybe nested
Java scope- Block scope and class and package scope
Ruby scope- class definition, module definition, methods. We don’t
declare a type in ruby because it is weakly typed.
COMPARING SCOPES- MIGHT COME IN EXAM
Shadowing will cause problems because you don’t know which
variable is running, something like that. RESEARCH
Object oriented language should have three things: inheritance,
encapsulation and polymorphism
Polymorphism- inheritance is needed to have polymorphism. Static
type should be the super type. Dynamic type is the sub type of the
super type. Ian gave an example of the shape hierarchy.
Shape S= Circle (..). We cannot declare circle (..) =new shape S
Look up polymorphism array slide. Polymorphism is also called
dynamic binding.
Lecture: Static typing and parsing
No information about type is attached to the variable or its value – Weak
typing
Function/procedure overloading and Operating overloading
Same name, different signature- Function overloading
Overriding- inheritance hierarchy
In dynamic typing, variables do not have assigned types, but types do.
Duck typing- dynamic typing in ruby. At runtime, a method is called on an
instance of an object. If the instance knows what to do with the method,
then it does it. Otherwise you get an error message.
In static typing, the compiler makes sure all values have right type for
each method.
Generics are the way of telling a data structures. E.g. ArrayList list
=newArrayList() – allows any object in the list in OO. Example of the
objects: student id, animals, furniture. As everything is an object in OO.
This is dynamic typing therefore we have to check the list every time we
run the code.
ArrayList<Duck> list – only allows ducks in the list. Therefore we don’t
have to check the list. Strongly typed.
Static typing has type interface.
REVISION
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
Look at abstract data types
Abstraction is the process of ignoring small details and focusing on main
stuff
Revise these topics- OVERRIDING, INHERITANCE, OVERLOADING
Adding functionality in classes. Class in java is fully abstract.
Look at java interfaces, fantom mixins, ruby modules and sacala traits.
Concurrency- two things working at the same time. Deadlock is the result
of synchronise. When things to a point when everything is stopped and
we cant move.
Live lock- when two processes are trying to do something to be able for
other functions to work. Same result as Deadlock.
Look at concurrency 3 lecture.
Google mapreduce- make sure you understand it
Lost/update problem
Independent processing- assumptions that we split up the task to make
the process quicker.
Transaction- Banks lock the account so anyone cant use it something like
that. Used in database as well. Example – a joint bank account has 100
quid. The couple tries to take out 100 quid at the same time.
Transactions are about keeping track of the version of a variable. It could
be a group of variables. Must avoid side effects.
Side effects- things that happen as a result. Unintended result.
Most concurrency is fake. Example: ruby
Lazy and eager evaluation- most programming language uses eager
evaluation.
Two types normal and applicative. Normal order is lazy and applicative
order s not.
chevron_up_icon
1 out of 2
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]