Understanding & Evolution of OOP
Lectures 3-5
Programing Language paradigms influencing programing language design and implementation
Program is sequence of statements. Following are the types of programing languages:
1. Imperative : It is programming with side effects. The result of a function depends on the history and state of program.
e.g. x = 5 ;
y = f(x);
x = 10;
y = f(x);
Here value of function depends on state of x.
2. Declarative : It is programming with only declarations like y = f(x). It only tells what is value of y but does not tell how to compute it.
3. Logical : It is programming based on logic.
e.g. LISP
4. Functional : Pure functional language is programming without side effects. The result of a function is independent of history and state of program. It can be declarative.
e.g. Haskell
5. Scripting : It is programing to do the things quickly without following much rules.
e.g. Python
6. Object Oriented : It is imperative programming. The result of a function depends on the history and state of program. Hence verification becomes difficult for imperative languages.
One programming language can have more than one paradigms. It is called impure language, impure does not mean bad but mix of paradigms. It has its own pros and cons.
e.g. Python and Java - Object Oriented, Imperative, Scripting
More on Cā¦
Evolution of object oriented programming from C
1. Procedural : It is language that contains procedures. e.g. C
Procedure: It is sequence of statements with some name.
Opposite of procedural language is flat language. e.g. old assembly language
2. Structural : It is language that has structures like procedures.
3. Modular : It is language that contains modules.
How is a module different from a procedure ?
- module can be compiled independently but a procedure cannot.
It puts all related things in one module. Interdependency between the modules is minimised, i.e. modules are loosely coupled. Structs in C makes it modular.
- A good module is one in which only interface is visible outside and rest details are hidden. In C this functionality is achieved using extern and static keywords.
- In C everything is by default extern.
- If we want to hide certain attributes(variables or functions) then we use static keyword while declaring attribute globally.
- Static keyword is also used in another context, where variable is declared static inside a function then even though scope of variable is local, the lifetime of that attribute is lifetime of full program. It is assigned memory on global memory
- Any variable assigned memory on global memory is always initiated.
4. Data Abstraction : It means to define our own data type and its behaviour. In C we achieve this by defining a structure with data fields and functions that apply on it.
e.g.In C structure stack can be implemented as an array with functions like push and pop.
5. C with Classes : Here we make a module as class. e.g. stack module as stack class. It is still not object oriented language.
6. Parameterised type : It is language that supports functions which can have types as their parameters.
Synergy of PLDI with Software Engineering
- Software Engineering is for developing reusable systems for maintenance and also for safer and trusted software systems. Object oriented systems have good maintainability for extension, correction and manipulation .
- Modularity can be achieved by modules that can be compiled independently
- If changes are made to one module then others must remain unchanged and need not be compiled
- In C language, if the header file is changed then the C code that uses its functions needs to be compiled again.(Only if the interface of the function changes)
- Interface, function declaration (in C) or API (in Java) all mean the same. Modules are distinguished by its signature i.e. function name, type of parameter and return type.
- Modularity leads to good systems that follow:
- Open Close system
- Separate interface and implementation
- Open System : System open for modification or extension. It is customisable to serve modified requirements.
- Close System : System closed to changes.
- Close system is not opposite of open system. Open system is ready for change and close system cannot be touched.
- Open Close System : It is modular system which can be modified, extended without touching the system. It is first principle of developing software.
- Modular C system is open but not close system. While object oriented system is a open close system. e.g. Override functionality of Java. Plug Ins are not open close system as they cannot make the existing system work differently
Code1: int ary[100];
for (int i = 0; i < 100; i++)
do_something();
Code 2: int [] ary = new int (100); // int ary [] ā¦
for (int i = 0; i < ary.length; i++)
do_something();
What is difference in above 2 code snippets?
- In the first code there is chance of getting errors like segmentation fault. While second code takes care of it. It is not due to object oriented approach but because it is using the length attribute of array.This length is updated by the system and is called as meta-data.
- Reflective system : It is system that uses meta data.
- Also in Java anything created by new is passed by reference.
- Object oriented computing is used for reusability and maintainability
- Virtual execution environment is used for trusted computing and realise more than intended computing.
- VEE is not an object oriented concept but easier to implement with OOPL. It can be done with C language also.
- Evolution of programming languages
- Object oriented languages did not come on their own but were inspired by the need felt while using imperative languages.
- Non-OOP languages are mother of almost all programing languages. ALGOL(1960) is mother of almost all imperative languages like C while LISP and SIMULA(1967) (used for simulation) are for object oriented programing languages like SmallTalk.
- SmallTalk(1969) is pure OOPL. It is not used for building object oriented systems but for research and development of object oriented languages.
- Then came imperative languages like Modula, Pascal and C while functional languages like Haskell (pure) and ML(impure)
- Clu(1970) and Ada are based on Abstract data type
- Then came C with classes(1980) that evolved to first widely used object oriented language C++. Cfont preprocessor was used to convert the C++ code to C code. Thus compiled the C++ code using C compiler and Cfont. This is called as bootstrapping.
Evolution of OOP continue..
- Cfont converts C++ program to C program which is compiled using C compiler. It behaves like a preprocessor and not like compiler or translator.
- What is the difference between preprocessor and compiler ?
- Preprocessor : It converts one high level language to another high level language. e.g. C preprocessor, it processes anything starting with preprocessor directive ā#ā like macros defined using #define.
- It does only text substitution
- May lead to errors
- Compiler /Translator : It converts a high level language to a low level language that is more closer to the machine.
- It requires language with proper grammar
- It has syntax analysis, semantic analysis, syntax directed translation, intermediate code generation, optimisation and target code generation.
- Other languages that evolved were:
- CLOS - (Object oriented version of LISP , not pure OOPL)
- Cecil - (developed in washington university, it is pure OOPL)
- Python - (procedural, object oriented, functional,scripting language)
- Java - (object oriented, imperative,scripting language)
- It has syntax similar to C and C++
- Along with language came the Virtual Execution Environment(VEE) because of which java lead to programming paradigm shift.
- x10 - It is upcoming language developed by IBM in 2010.
- It is comprehensive high-end object oriented programming language.
- It is used for concurrent programming. SInce systems today are multi-core, we require support for concurrency, high performance, high productivity computing on high end computers.
- aim of good programming language is to develop a system that is:
- Reusable
- Easy to program
- Safer and trustworthy
- PERCS (Productivity Easy to use Reliable Computer System)
- Object oriented programming has following features.
- Abstract Data Type (ADT)
- Inheritence
- Dynamic binding
Issues to be addressed
- Issue 1: OOPL: Pure and Mixed
- Our aim is not to have a pure object oriented programming but have a good system (reusable, easy to program, safer and trusted)
- Impure does not mean it is bad but it means it has something more that adds to the power.
- Pure languages were used for research and thats how many object oriented features were added to them. Impure languages are used for day to day development of good software systems.
- Issue 2: Major ingredients of OOPL
- Inheritance : It is fundamental to object oriented programming.
- what are we inheriting ? (will be answered in future classes)
- Dynamic binding : Dynamic means during runtime while static means during compile time. When binding is done at the linking phase it is called dynamic binding.