0% found this document useful (0 votes)
18 views16 pages

1) Role of Programming Languages?

The document discusses the role, characteristics, and paradigms of programming languages, emphasizing the importance of understanding various languages to enhance algorithm development, efficiency, and language choice. It outlines key characteristics that a programming language should possess, such as simplicity, efficiency, and good documentation, while also detailing different programming paradigms like imperative, declarative, and object-oriented programming. Additionally, it addresses language design and translation issues, highlighting principles like the Single Responsibility Principle and Open-Closed Principle in object-oriented design.

Uploaded by

Narendra Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views16 pages

1) Role of Programming Languages?

The document discusses the role, characteristics, and paradigms of programming languages, emphasizing the importance of understanding various languages to enhance algorithm development, efficiency, and language choice. It outlines key characteristics that a programming language should possess, such as simplicity, efficiency, and good documentation, while also detailing different programming paradigms like imperative, declarative, and object-oriented programming. Additionally, it addresses language design and translation issues, highlighting principles like the Single Responsibility Principle and Open-Closed Principle in object-oriented design.

Uploaded by

Narendra Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

1) Role of programming languages?

1. To improve your ability to develop effective algorithms


Many languages provide features that can be extremely useful
when used properly but waste a large amount of time when used
improperly. Algorithms behave similarly, so the habit of making
correct decisions with a programming language can carry over to
making correct decisions with an algorithm.
2. To improve your use of your existing programming language
By understanding exactly how the features in a programming
language are implemented, you learn how to effectively use them.
When you know how the language components such as
lists/arrays/strings work, you can use them more efficiently.
3. To increase your vocab of useful programming constructs
When thinking about a set of data/program structures to solve a
problem, it's typical to only think about the structures that are
immediately available within the programming language you're
working with. By knowing the constructs of other programming
languages, you can find one that fits your scenario better and
possibly implement it yourself.
4. To allow a better choice of programming language
Some languages are better suited than others for particular
projects. You can reduce effort by picking the one that works best.
5. To make it easier to learn a new language
A thorough knowledge of programming language constructs and
implementation techniques allows programmers to learn new
languages more easily.
6. To make it easier to design a new language
Though you may not be making the next C or Java programming
language, it's actually fairly common to create a form of
programming language on a small scale within a project.

2) Characteristics of programming languages?


• A programming language must be simple, easy to learn and use,
have good readability, and be human recognizable.
• Abstraction is a must-have Characteristics for a programming language
in which the ability to define the complex structure and then its degree
of usability comes.
• A portable programming language is always preferred.
• Programming language’s efficiency must be high so that it can be easily
converted into a machine code and executed consumes little space in
memory.
• A programming language should be well structured and documented
so that it is suitable for application development.
• Necessary tools for the development, debugging, testing, maintenance
of a program must be provided by a programming language.
• A programming language should provide a single environment known
as Integrated Development Environment(IDE).
• A programming language must be consistent in terms of syntax and
semantics.
3) Various programming paradigm?
Paradigm can also be termed as method to solve some problem or do
some task. Programming paradigm is an approach to solve problem using
some programming language or also we can say it is a method to solve a
problem using tools and techniques that are available to us following
some approach. There are lots for programming language that are known
but all of them need to follow some strategy when they are implemented
and this methodology/strategy is paradigms. Apart from varieties of
programming language there are lots of paradigms to fulfil each and every
demand. They are discussed below:
1. Imperative programming paradigm:
It is one of the oldest programming paradigm. It features close relation to
machine architecture. It is based on Von Neumann architecture. It works
by changing the program state through assignment statements. It
performs step by step task by changing state. The main focus is on how to
achieve the goal. The paradigm consist of several statements and after
execution of all the result is stored.
Advantage:
1. Very simple to implement
2. It contains loops, variables etc.
Disadvantage:
1. Complex problem cannot be solved
2. Less efficient and less productive
3. Parallel programming is not possible

Examples of Imperative programming paradigm:

C : developed by Dennis Ritchie and Ken Thompson


Fortan : developed by John Backus for IBM
Basic : developed by John G Kemeny and Thomas E Kurtz
Imperative programming is divided into three broad categories:
Procedural, OOP and parallel processing. These paradigms are as follows:
• Procedural programming paradigm –
This paradigm emphasizes on procedure in terms of under lying
machine model. There is no difference in between procedural and
imperative approach. It has the ability to reuse the code and it was
boon at that time when it was in use because of its reusability.
Examples of Procedural programming paradigm:

C : developed by Dennis Ritchie and Ken Thompson


C++ : developed by Bjarne Stroustrup
Java : developed by James Gosling at Sun Microsystems
ColdFusion : developed by J J Allaire
Pascal : developed by Niklaus Wirth
Then comes OOP,
• Object oriented programming –
The program is written as a collection of classes and object which are
meant for communication. The smallest and basic entity is object and
all kind of computation is performed on the objects only. More
emphasis is on data rather procedure. It can handle almost all kind of
real life problems which are today in scenario.
Advantages:
• Data security
• Inheritance
• Code reusability
• Flexible and abstraction is also present
Examples of Object Oriented programming paradigm:

Simula : first OOP language


Java : developed by James Gosling at Sun Microsystems
C++ : developed by Bjarne Stroustrup
Objective-C : designed by Brad Cox
Visual Basic .NET : developed by Microsoft
Python : developed by Guido van Rossum
Ruby : developed by Yukihiro Matsumoto
Smalltalk : developed by Alan Kay, Dan Ingalls, Adele Goldberg
• Parallel processing approach –
Parallel processing is the processing of program instructions by
dividing them among multiple processors. A parallel processing system
posses many numbers of processor with the objective of running a
program in less time by dividing them. This approach seems to be like
divide and conquer. Examples are NESL (one of the oldest one) and
C/C++ also supports because of some library function.
2. Declarative programming paradigm:
It is divided as Logic, Functional, Database. In computer science
the declarative programming is a style of building programs that
expresses logic of computation without talking about its control flow. It
often considers programs as theories of some logic.It may simplify writing
parallel programs. The focus is on what needs to be done rather how it
should be done basically emphasize on what code code is actually doing. It
just declares the result we want rather how it has be produced. This is the
only difference between imperative (how to do) and declarative (what to
do) programming paradigms. Getting into deeper we would see logic,
functional and database.
• Logic programming paradigms –
It can be termed as abstract model of computation. It would solve
logical problems like puzzles, series etc. In logic programming we have
a knowledge base which we know before and along with the question
and knowledge base which is given to machine, it produces result. In
normal programming languages, such concept of knowledge base is not
available but while using the concept of artificial intelligence, machine
learning we have some models like Perception model which is using
the same mechanism.
In logical programming the main emphasize is on knowledge base and
the problem. The execution of the program is very much like proof of
mathematical statement, e.g., Prolog
sum of two number in prolog:

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:

JavaScript : developed by Brendan Eich


Haskell : developed by Lennart Augustsson, Dave Barton
Scala : developed by Martin Odersky
Erlang : developed by Joe Armstrong, Robert Virding
Lisp : developed by John Mccarthy
ML : developed by Robin Milner
Clojure : developed by Rich Hickey
The next kind of approach is of Database.
• Database/Data driven programming approach –
This programming methodology is based on data and its movement.
Program statements are defined by data rather than hard-coding a
series of steps. A database program is the heart of a business
information system and provides file creation, data entry, update,
query and reporting functions. There are several programming
languages that are developed mostly for database application. For
example SQL. It is applied to streams of structured data, for filtering,
transforming, aggregating (such as computing statistics), or calling
other programs. So it has its own wide application.
CREATE DATABASE databaseAddress;
CREATE TABLE Addr (
PersonID int,
LastName varchar(200),
FirstName varchar(200),
Address varchar(200),
City varchar(200),
State varchar(200)
);
4) State the language design issues and translations issues.
Design Issues

In the code generation phase, various issues can arises:

1. Input to the code generator


2. Target program
3. Memory management
4. Instruction selection
5. Register allocation
6. Evaluation order

1. Input to the code generator


o The input to the code generator contains the intermediate
representation of the source program and the information of the
symbol table. The source program is produced by the front end.
o Intermediate representation has the several choices:
a) Postfix notation
b) Syntax tree
c) Three address code
o We assume front end produces low-level intermediate representation
i.e. values of names in it can directly manipulated by the machine
instructions.
o The code generation phase needs complete error-free intermediate
code as an input requires.

2. Target program:

The target program is the output of the code generator. The output can be:

a) Assembly language: It allows subprogram to be separately compiled.

b) Relocatable machine language: It makes the process of code generation


easier.

c) Absolute machine language: It can be placed in a fixed location in memory


and can be executed immediately.

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

Register can be accessed faster than memory. The instructions involving


operands in register are shorter and faster than those involving in memory
operand.

The following sub problems arise when we use registers:

Register allocation: In register allocation, we select the set of variables that


will reside in register.
6. Evaluation order

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.

Register assignment: In Register assignment, we pick the register that


contains variable.

Certain machine requires even-odd pairs of registers for some operands and
result.

ISSUES IN LANGUAGE TRANSLATION


A programmer code a program using subprograms, statements, conditions, declaration
etc. But a translator looks programming languages as a collection of symbols made up of
thousands of characters. During translation a program is analyzed character by character.

During language translation issues occurs in the following way:


1. Lexical analysis
2. Syntax analysis
3. Semantic analysis
4. Symbol table
5. Error handler

1) Lexical analysis: In this phase isuue is with grouping of charcters in to


meaningfull words known as lexems. Here meaningfull words means
identifiers, numbers, keywords, comments etc. The basic units means
characters on which this analysis is performed known as tokens.
Lexical analyzer must analyze the type of each lexems and with a type tag
that lexems is sends for higher analysis i.e, syntax analysis. This phase
requires much translation time as compared to other phases.

2) Syntax analysis: Here syntax of lexems are checked using parse/syntax


tree. Structures defined by the programmer are validated here. If getting any
error during language translation in this phase, compiler throws a syntax
error.

3) Semantic analysis: Semantic analysis judges whether the syntax structure


constructed in the source program derives any meaning or not.

4) Symbol table: Symbol Table is an important data structure created and


maintained by the compiler. All the phases uses symbol table as follows:
1. Lexical Analysis: Creates new table entries in the symbol table, like tokens.
2. Syntax Analysis: Adds information regarding attribute type, scope etc in
the table.
3. Semantic Analysis: Uses available information in the table to check for
semantics i.e. to verify that expressions and assignments are semantically
correct(type checking) and update it accordingly.
4. Intermediate Code generation: Refers symbol table for knowing how much
and what type of run-time is allocated and table helps in adding temporary
variable information.
5. Code Optimization: Uses information present in symbol table removing
unnecessary codes from Intermediate codes.
6. Target Code generation: Generates code by using address information of
identifier present in the table.
5) Error handler: The tasks of the Error Handler is to detect each error,
report it to the user, and then recover and implement them to handle error.
During this process processing time of program should not be slow. An Error
is the blank entries in the symbol table.

6) State a design principle of object oriented


programming
As a part of an overall strategy of agile and adaptive programming, a
number of object-oriented design principles were proposed for the design
and programming of computer software system that is easy to maintain
and extend over time. These principles are guidelines intended for
programmers to apply while working on software to remove "code smells"
(potentially buggy code) by refactorizing the source code until it is both
legible and extensible. In this page, we introduce the SOLID principles, that
is, Single responsibility, Open-closed, Liskov substitution, Interface
segregation and Dependency inversion. The following information was
integrated from various sources on the Web.

Single Responsibility Principle (SRP)

The SRP requires that a class should have only a single responsibility.

Example: If a class SalesOrder keeps information about a sales order, and in


addition has a method saveOrder() that saves the SaleOrder in a database
and a method exportXML() that exports the SalesOrder in XML format, this
design will violate the SRP because there will be different types of users of
this class and different reasons for making changes to this class. A change
made for one type of user, say change the type of database, may require the
re-test, recompilation, and re-linking of the class for the other type of users.

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.

Example: Suppose an OrderValidation class has a method validate(Order


order) that is programmed to validate an order based on a set of hard-
coded rules. This design violates the OCP because if the rules
change, the OrderValidation class has to be modified, tested, and compiled.

A better design will be to let the OrderValidation class contain a collection


of ValidationRule objects each of which has a validate(Order order) method
(perhaps defined in a Validation interface) to validate an Order using a
specific rule, and the validate(Order order) method
of OrderValidation class can simply iterate through
those ValidationRule objects to validate the order. The new design will
satisfy the OCP, because if the rules change, we can just create a
new ValidationRule object and add it to an OrderValidation instance at run
time (rather than to the class definition itself).

This is can also be achieved by using subclasses of a base


class AbstractValidationRule that has an override-able
function validate(Order order). Subclasses can implement the method
differently without changing the base class functionality.

Liskov Substitution Principle (LSP)

The LSP requires that objects in a program should be replaceable with


instances of their subclasses without altering the correctness of that
program.

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.

Example: Suppose a Rectangle class has two instance


variables height and width, and a method setSize(int a, int b), which
set height to a and width to b. Suppose Square is a subclass
of Rectangle and it overrides the inherited method by setting
both height and width to a. This design will violate LSP. To see this,
consider a client uses a reference variable of type Rectangle to call
the setSize() method to assign different values of a and b, and then
immediately verify if the sizes were set correctly or the area is correctly
computed. The results will be different if the variable references to
a Rectangle object than to a Square object.

It turns out that in OO programming, a Square is not a Rectangle at all


because it behaves differently from a Rectangle.

Interface Segregation Principle (ISP)

The ISP requires that clients should not be forced to depend on interfaces
that they do not use.

Example: Suppose a Vehicle interface shown in the figure is designed for


clients to 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.

Example: Making a class Button associate to another class Lamp (because


a Lamp has a Button) is a violation of DIP. A better design will be associate
an AbstractButton with an AbstractButtonClient, and define Button as a
subclass of the AbstractButton and a Lamp a subclass of the
AbstractButtonClient.

Example: Making an EBookReader class to use PDFBook class is a violation


of DIP because it requires to change the EBookReader class to read other
types of e-books. A better design is to let EBookReader use an
interface EBook and let PDFBook and other types of e-book classes
implement EBook. Now adding or changing e-book classes will not require
any change to EBookReader class.

7) Explain the characteristics of object oriented programming

The characteristics of object-oriented programming are:

1. It follows a bottom-up approach.


2. The program resulting from object-oriented programming is a
collection of objects. Each object has its own data and a set of
operations.
3. OOP restricts the free movement of data and the functions that
operate on it.
4. A properly defined class can be reused, giving way to code
reusability.
5. The concept of object-oriented programming models real-world
entities very well.
6. Due to its object-oriented approach, it is extremely useful in solving
complex problems.

8) explain in brief abstraction, inheritence, polymorphism

Abstraction is used to hide background details or any unnecessary


implementation about the data so that users only see the required
information. It is one of the most important and essential features of object-
oriented programming.

Pre-defined functions are similar to data abstraction.

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

Abstraction using classes

Abstraction can be implemented with classes. Classes have private and


public identifiers to limit the scope of any variable or a function.

Abstraction in header files

Header files of many languages store some pre-defined function, for


example, the pow() function in C++, .sort(), etc. A user knows how and
when to use them; however, their workings are kept hidden in these
header files/libraries.

Inheritance is one of the most important aspects of Object Oriented


Programming (OOP). The key to understanding Inheritance is that it
provides code re-usability. In place of writing the same code, again and
again, we can simply inherit the properties of one class into the other. OOP
is all about real-world objects and inheritance is a way of representing real-
world relationships. Here’s an example – car, bus, bike – all of these come
under a broader category called Vehicle. That means they’ve inherited the
properties of class vehicles i.e all are used for transportation.

We can represent this relationship in code with the help of inheritance.

There are broadly five forms of inheritance based on the involvement of


parent and child classes.
1. Single inheritance

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

An inheritance becomes multiple inheritances when a class inherits more


than one parent class. The child class after inheriting properties from
various parent classes has access to all of their objects.

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

When there is a combination of more than one form of inheritance, it is


known as hybrid inheritance.

Polymorphism is an object-oriented programming concept that refers to


the ability of a variable, function, or object to take on multiple forms. In a
programming language exhibiting polymorphism, class objects belonging
to the same hierarchical tree (inherited from a common parent class) may
have functions with the same name, but with different behaviors.
Example:

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:

• Compile time polymorphism

o Example: Method overloading

• Runtime polymorphism

o Example: Method overriding

Advantages of polymorphism:

• It helps programmers reuse code and classes once written, tested,


and implemented.

• A single variable name can be used to store variables of multiple data


types (float, double, long, int, etc).

• It helps compose powerful, complex abstractions from simpler ones.

You might also like