1) Role of Programming Languages?
1) Role of Programming Languages?
predicates
sumoftwonumber(integer, integer)
clauses
sum(0, 0).
sum(n, r):-
n1=n-1,
sum(n1, r1),
r=r1+n
• Functional programming paradigms –
The functional programming paradigms has its roots in mathematics
and it is language independent. The key principle of this paradigms is
the execution of series of mathematical functions. The central model
for the abstraction is the function which are meant for some specific
computation and not the data structure. Data are loosely coupled to
functions.The function hide their implementation. Function can be
replaced with their values without changing the meaning of the
program. Some of the languages like perl, javascript mostly uses this
paradigm.
Examples of Functional programming paradigm:
2. Target program:
The target program is the output of the code generator. The output can be:
3. Memory management
o During code generation process the symbol table entries have to be
mapped to actual p addresses and levels have to be mapped to
instruction address.
o Mapping name in the source program to address of data is co-
operating done by the front end and code generator.
o Local variables are stack allocation in the activation record while
global variables are in static area.
4. Instruction selection:
o Nature of instruction set of the target machine should be complete and
uniform.
o When you consider the efficiency of target machine then the
instruction speed and machine idioms are important factors.
o The quality of the generated code can be determined by its speed and
size.
5. Register allocation
The efficiency of the target code can be affected by the order in which the
computations are performed. Some computation orders need fewer
registers to hold results of intermediate than others.
Certain machine requires even-odd pairs of registers for some operands and
result.
The SRP requires that a class should have only a single responsibility.
A better design will be to have the SalesOrder class only keeps the
information about a sales order, and have different classes to save order
and to export order, respectively. Such a design will confirm to SRP.
Open-Closed Principle (OCP)
The OCP requires that each software entity should be open for extension,
but closed for modification.
The users must be able to use objects of subclasses via references to base
classes without noticing any difference. When using an object through its
base class interface, the object of a subclass must not expect the user to
obey preconditions that are stronger than those required by the base class.
The ISP requires that clients should not be forced to depend on interfaces
that they do not use.
This violates ISP because clients are forced to depend on methods they do
not use: HighWay does not use stopRadio() or ejectCD(),
and ParkingLot does not need accelerate() or ejectCD().Dependency
Inversion Principle (DIP)
The DIP requires that high level modules should not depend on low level
modules, both should depend on abstraction. Also, abstraction should not
depend on details, details should depend on abstractions.
For example, when you wash your laundry in a laundry machine, you put
your laundry and detergent inside the machine and wait for the machine to
perform its task. But how does the machine was your clothes? What
mechanism does it use? A user is not required to know the engineering
behind its workings. This process is similar data abstraction; it keeps all the
unnecessary information hidden from the users.
Types of Abstraction
This is a form of inheritance in which a class inherits only one parent class.
This is the simple form of inheritance and hence also referred to as simple
inheritance.
2. Multiple Inheritance
3. Multi-level Inheritance
For example, a class_1 is inherited by a class_2 and this class_2 also gets
inherited by class_3 and this process goes on. This is known as multi-level
inheritance.
4- Hierarchical inheritance
In this, various Child classes inherit a single Parent class. The example
given in the introduction of the inheritance is an example of Hierarchical
inheritance since classes BMW and Audi inherit class Car.
5- Hybrid Inheritance
The classic example is of the Shape class and all the classes that
are inherited from it, such as:
• Rectangle
• Triangle
• Circle
Types of polymorphism:
• Runtime polymorphism
Advantages of polymorphism: