Lesson1-Introduction to Computer Programming
Lesson1-Introduction to Computer Programming
Before getting into computer programming, let us first understand computer programs and what
they do.
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 −
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.
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
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.
C Programmer
C++ Programmer
Java Programmer
Python Programmer
PHP Programmer
Perl Programmer
Ruby Programmer
Algorithm
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 −
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.
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.
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.
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.
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
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
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.
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.
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.