0% found this document useful (0 votes)
3 views

Lesson1-Introduction to Computer Programming

The document provides an introduction to computer programming, defining a computer program as a sequence of instructions written in a programming language to perform specific tasks. It discusses various programming languages, their uses, and the role of computer programmers, along with the importance of algorithms and different types of programming languages. Additionally, it outlines programming paradigms, including imperative, logical, functional, and object-oriented approaches, highlighting their advantages and disadvantages.
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)
3 views

Lesson1-Introduction to Computer Programming

The document provides an introduction to computer programming, defining a computer program as a sequence of instructions written in a programming language to perform specific tasks. It discusses various programming languages, their uses, and the role of computer programmers, along with the importance of algorithms and different types of programming languages. Additionally, it outlines programming paradigms, including imperative, logical, functional, and object-oriented approaches, highlighting their advantages and disadvantages.
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/ 10

Introduction to Computer Programming

Before getting into computer programming, let us first understand computer programs and what
they do.

A computer program is a sequence of instructions written using a Computer Programming


Language to perform a specified task by the computer.

The two important terms that we have used in the above definition are −

 Sequence of instructions
 Computer Programming Language

To understand these terms, consider a situation when someone asks you about how to go to a
nearby KFC. What exactly do you do to tell him the way to go to KFC?

You will use Human Language to tell the way to go to KFC, something as follows −

First go straight, after half kilometer, take left from the red light and then drive around one
kilometer and you will find KFC at the right.

Here, you have used English Language to give several steps to be taken to reach KFC. If they are
followed in the following sequence, then you will reach KFC −

1. Go straight
2. Drive half kilometer
3. Take left
4. Drive around one kilometer
5. Search for KFC at your right side

Now, try to map the situation with a computer program. The above sequence of instructions is
actually a Human Program written in English Language, which instructs on how to reach KFC
from a given starting point. This same sequence could have been given in Spanish, Hindi,
Arabic, or any other human language, provided the person seeking direction knows any of these
languages.

Now, let's go back and try to understand a computer program, which is a sequence of instructions
written in a Computer Language to perform a specified task by the computer. Following is a
simple program written in Python programming Language −

print "Hello, World!"

The above computer program instructs the computer to print "Hello, World!" on the computer
screen.
 A computer program is also called a computer software, which can range from two lines
to millions of lines of instructions.
 Computer program instructions are also called program source code and computer
programming is also called program coding.
 A computer without a computer program is just a dump box; it is programs that make
computers active.

As we have developed so many languages to communicate among ourselves, computer scientists


have developed several computer-programming languages to provide instructions to the
computer (i.e., to write computer programs). We will see several computer programming
languages in the subsequent chapters.

Introduction to Computer Programming

If you understood what a computer program is, then we will say: the act of writing computer
programs is called computer programming.

As we mentioned earlier, there are hundreds of programming languages, which can be used to
write computer programs and following are a few of them −

 Java
 C
 C++
 Python
 PHP
 Perl
 Ruby

Uses of Computer Programs

Today computer programs are being used in almost every field, household, agriculture, medical,
entertainment, defense, communication, etc. Listed below are a few applications of computer
programs −

 MS Word, MS Excel, Adobe Photoshop, Internet Explorer, Chrome, etc., are examples of
computer programs.
 Computer programs are being used to develop graphics and special effects in movie
making.
 Computer programs are being used to perform Ultrasounds, X-Rays, and other medical
examinations.
 Computer programs are being used in our mobile phones for SMS, Chat, and voice
communication.

Computer Programmer
Someone who can write computer programs or in other words, someone who can do computer
programming is called a Computer Programmer.

Based on computer programming language expertise, we can name a computer programmers as


follows −

 C Programmer
 C++ Programmer
 Java Programmer
 Python Programmer
 PHP Programmer
 Perl Programmer
 Ruby Programmer

Algorithm

From programming point of view, an algorithm is a step-by-step procedure to resolve any


problem. An algorithm is an effective method expressed as a finite set of well-defined
instructions.

Thus, a computer programmer lists down all the steps required to resolve a problem before
writing the actual code. Following is a simple example of an algorithm to find out the largest
number from a given list of numbers −

1. Get a list of numbers L1, L2, L3....LN


2. Assume L1 is the largest, Largest = L1
3. Take next number Li from the list and do the following
4. If Largest is less than Li
5. Largest = Li
6. If Li is last number from the list then
7. Print value stored in Largest and come out
8. Else repeat same process starting from step 3

The above algorithm has been written in a crude way to help beginners understand the concept.
You will come across more standardized ways of writing computer algorithms as you move on to
advanced levels of computer programming.

Types of Programming Languages


There are two types of programming languages, which can be categorized into the following
ways:
1. Low level language
a) Machine language (1GL)
b) Assembly language (2GL)
2. High level language
a) Procedural-Oriented language (3GL)
b) Problem-Oriented language (4GL)
c) Natural language (5GL)
1. Low level language
This language is the most understandable language used by computer to perform its operations. It
can be further categorized into:
a) Machine Language (1GL)
Machine language consists of strings of binary numbers (i.e. 0s and 1s) and it is the only one
language, the processor directly understands. Machine language has an Merits of very fast
execution speed and efficient use of primary memory.
Merits:
¨ It is directly understood by the processor so has faster execution time since the programs
written in this language need not to be tanslated.
¨ It doesn’t need larger memory.
Demerits:
¨ It is very difficult to program using 1GL since all the instructions are to be represented by
0s and 1s.
¨ Use of this language makes programming time consuming.
¨ It is difficult to find error and to debug.
¨ It can be used by experts only.
b) Assembly Language
Assembly language is also known as low-level language because to design a program
programmer requires detailed knowledge of hardware specification. This language uses
mnemonics code (symbolic operation code like ‘ADD’ for addition) in place of 0s and 1s. The
program is converted into machine code by assembler. The resulting program is reffered to as an
object code.
Merits:
¨ It is makes programming easier than 1GL since it uses mnemonics code for programming.
Eg: ADD for addition, SUB for subtraction, DIV for division, etc.
¨ It makes programming process faster.
¨ Error can be identified much easily compared to 1GL.
¨ It is easier to debug than machine language.
Demerits:
¨ Programs written in this language is not directly understandable by computer so translaters
should be used.
¨ It is hardware dependent language so programmers are forced to think in terms of
computer’s architecture rather than to the problem being solved.
¨ Being machine dependent language, programs written in this language are very less or not
protable.
¨ Programmers must know its mnemonics codes to perform any task.
2. High level language

Instructions of this language closely resembles to human language or English like words. It uses
mathematical notations to perform the task. The high level language is easier to learn. It requires
less time to write and is easier to maintain the errors. The high level language is converted into
machine language by one of the two different languages translator programs; interpreter or
compiler.

High level language can be further categorized as:

a) Procedural-Oriented language (3GL)

Procedural Programming is a methodology for modeling the problem being solved, by


determining the steps and the order of those steps that must be followed in order to reach a
desired outcome or specific program state. These languages are designed to express the logic and
the procedure of a problem to be solved. It includes languages such as Pascal, COBOL, C,
FORTAN, etc.

Merits:

¨ Because of their flexibility, procedural languages are able to solve a variety of problems.

¨ Programmer does not need to think in term of computer architecture which makes them
focused on the problem.

¨ Programs written in this language are portable.


Demerits:

¨ It is easier but needs higher processor and larger memory.

¨ It needs to be translated therefore its execution time is more.

b) Problem-Oriented language (4GL)


It allows the users to specify what the output should be, without describing all the details of how
the data should be manupulated to produce the result. This is one step ahead from 3GL. These
are result oriented and include database query language.
Eg: Visual Basic, C#, PHP, etc.
The objectives of 4GL are to:
Ø Increase the speed of developing programs.
Ø Minimize user’s effort to botain information from computer.
Ø Reduce errors while writing programs.
Merits:
¨ Programmer need not to think about the procedure of the program. So, programming is
much easier.
Demerits:

¨ It is easier but needs higher processor and larger memory.

¨ It needs to be translated therefore its execution time is more.

c) Natural language (5GL)


Natural language are stil in developing stage where we could write statrments that would look
like normal sentences.
Merits:
¨ Easy to program.
¨ Since, the program uses normal sente
nces, they are easy to understand.
¨ The programs designed using 5GL will have artificial intelligence (AI).
¨ The programs would be much more interactive and interesting.
Demerits:
¨ It is slower than previous generation language as it should be completely translated into
binary code which is a tedious task.
¨ Highly advanced and expensive electronic devices are required to run programs developed
in 5GL. Therefore, it is an expensive approach.
These are the different types of programming languages with their merits and demerits.

Programming Paradigms
A programming paradigm is a style, or “way,” of programming.
A programming paradigm is the concept by which the methodology of a programming language
adheres to. Paradigms are important because they define a programming language and how it
works. A great way to think about a paradigm is as a set of ideas that a programming language
can use to perform tasks in terms of machine-code at a much higher level. These different
approaches can be better in some cases, and worse in others. A great rule of thumb when
exploring paradigms is to understand what they are good at. While it is true that most modern
programming languages are general-purpose and can do just about anything, it might be more
difficult to develop a game, for example, in a functional language than an object-oriented
language.

Some Common Paradigms

You should know these:

 Imperative: Programming with an explicit sequence of commands that update state.


 Declarative: Programming by specifying the result you want, not how to get it.
 Structured: Programming with clean, goto-free, nested control structures.
 Procedural: Imperative programming with procedure calls.
 Functional (Applicative): Programming with function calls that avoid any global state.
 Function-Level (Combinator): Programming with no variables at all.
 Object-Oriented: Programming by defining objects that send messages to each other.
Objects have their own internal (encapsulated) state and public interfaces. Object
orientation can be:
o Class-based: Objects get state and behavior based on membership in a class.
o Prototype-based: Objects get behavior from a prototype object.
 Event-Driven: Programming with emitters and listeners of asynchronous actions.
 Flow-Driven: Programming processes communicating with each other over predefined
channels.
 Logic (Rule-based): Programming by specifying a set of facts and rules. An engine infers
the answers to questions.
 Constraint: Programming by specifying a set of constraints. An engine finds the values
that meet the constraints.
 Aspect-Oriented: Programming cross-cutting concerns applied transparently.
 Reflective: Programming by manipulating the program elements themselves.
 Array: Programming with powerful array operators that usually make loops unnecessary.

Paradigms are not meant to be mutually exclusive; a single program can feature multiple
paradigms!
It can be shown that anything solvable using one of these paradigms can be solved using the
others; however, certain types of problems lend themselves more naturally to specific paradigms.
Imperative
The imperative programming paradigm assumes that the computer can maintain through
environments of variables any changes in a computation process. Computations are performed
through a guided sequence of steps, in which these variables are referred to or changed. The
order of the steps is crucial, because a given step will have different consequences depending on
the current values of variables when the step is executed.

 Imperative Languages:
Popular programming languages are imperative more often than they are any other
paradigm studies in this course. There are two reasons for such popularity:
1. the imperative paradigm most closely resembles the actual machine itself, so the
programmer is much closer to the machine;
2. because of such closeness, the imperative paradigm was the only one efficient
enough for widespread use until recently.
 Advantages
o efficient;
o close to the machine;
o popular;
o familiar.
 Disadvantages
o The semantics of a program can be complex to understand or prove, because of
referential transparency does not hold(due to side effects)
o Side effects also make debugging harder;
o Abstration is more limitted than with some paradigms;
o Order is crucial, which doesn't always suit itself to problems.

Logical

The Logical Paradigm takes a declarative approach to problem-solving. Various logical


assertions about a situation are made, establishing all known facts. Then queries are made. The
role of the computer becomes maintaining data and logical deduction.

o Logical Paradigm Programming:


A logical program is divided into three sections:
1. a series of definitions/declarations that define the problem domain
2. statements of relevant facts
3. statement of goals in the form of a query
Any deducible solution to a query is returned. The definitions and declarations
are constructed entirely from relations. i.e. X is a member of Y or X is in the
internal between a and b etc.

o Advantages:
The advantages of logic oriented programming are bifold:
1. The system solves the problem, so the programming steps themselves are
kept to a minimum;
2. Proving the validity of a given program is simple.

Functional

o The Functional Programming paradigm views all subprograms as functions in the


mathematical sense-informally, they take in arguments and return a single
solution. The solution returned is based entirely on the input, and the time at
which a function is called has no relevance. The computational model is therefore
one of function application and reduction.
o Languages
Functional languages are created based on the functional paradigm. Such
languages permit functional solutions to problems by permitting a programmer to
treat functions as first-class objects(they can be treated as data, assumed to have
the value of what they return; therefore, they can be passed to other functions as
arguments or returned from functions).
o Advantages
The following are desirable properties of a functional language:
1. The high level of abstraction, especially when functions are used,
supresses many of the details of programming and thus removes the
possibility of commiting many classes of errors;
2. The lack of dependence on assignment operations, allowing programs to
be evaluated in many different orders. This evaluation order independence
makes function-oriented languages good candidates for programming
massively parallel computers;
3. The absence of assignment operations makes the function-oriented
programs much more amenable to mathematical proof and analysis than
are imperative programs, because functional programs possess referential
transparency.
o Disadvantages
1. Perhaps less efficiencey
2. Problems involving many variables or a lot of sequential activity are
sometimes easier to handle imperatively or with object-oriented
programming.
Object-Oriented

Object Oriented Programming (OOP) is a paradigm in which real-world objects


are each viewed as seperate entities having their own state which is modified only
by built in procedures, called methods.

Because objects operate independently, they are encapsulated into modules which
contain both local environments and methods. Communication with an object is
done by message passing.

Objects are organized into classes, from which they inherit methods and
equivalent variables. The object-oriented paradigm provides key benefits of
reusable code and code extensibility.

o Features & Benefits


A new class (called a derived class or subclass) may be derived from another
class (called a base class or superclass) by a mechanism called inheritance. The
derived class inherits all the features of the base class: its structure and
behavior(response to messages). In addition, the derived class may contain
additional state (instance variables), and may exhibit additional behavior (new
methods to resond to new messages). Significantly, the derived class can also
override behavior corresponding to some of the methods of the base class: there
would be a different method to respond to the same message. Also, the
inheritance mechanism is allowed even without access to the source code of the
base class.

The ability to use inheritance is the single most distinguishing feature of the OOP
paradigm. Inheritance gives OOP its chief benefit over other programming
paradigms - relatively easy code reuse and extension without the need to change
existing source code.

The mechanism of modeling a program as a collection of objects of various


classes, and furthermore describing many classes as extensions or modifications
of other classes, provides a high degree of modularity.

Ideally, the state of an object is manipulated and accessed only by that object's
methods. (Most O-O languages allow direct manipulation of the state, but such
access is stylistically discouraged). In this way, a class' interface (how objects of
that class are accessed) is separate from the class' implementation (the actual
code of the class' methods). Thus encapsulation and information hiding are
inherent benefits of OOP.

You might also like