Chapter 1. Introduction To Computer Programming
Chapter 1. Introduction To Computer Programming
A Computer is an electronic device that accepts data, performs computations, and makes logical
decisions according to instructions that have been given to it; then produces meaningful
information in a form that is useful to the user. In current world we live in, computers are almost
used in all walks of life for different purposes. They have been deployed to solve different real
life problems, from the simplest game playing up to the complex nuclear energy production.
Computers are important and widely used in our society because they are cost-effective aids to
problem solving in business, government, industry, education, etc.
In order to solve a given problem, computers must be given the correct instruction about how
they can solve it. The terms computer programs, software programs, or just programs are the
instructions that tells the computer what to do. Computer requires programs to function, and a
computer programs does nothing unless its instructions are executed by a CPU. Computer
programming (often shortened to programming or coding) is the process of writing, testing,
debugging/troubleshooting, and maintaining the source code of computer programs. Writing
computer programs means writing instructions, that will make the computer follow and run a
program based on those instructions. Each instruction is relatively simple, yet because of the
computer's speed, it is able to run millions of instructions in a second. A computer program
usually consists of two elements:
Data – characteristics
Code – action
1.2. Reasons to study Programming
There is no best programming language. Each language is better than others for certain things,
and which one you are using depends on what you want to do with it. Having said that, the fact
remains, though, that the world runs on C and C++. People use numerous C/C++ powered
devices on a daily basis, whether they realize it or not, and there are all the signs that C/C++ will
remain omnipresent in the future.
There are probably as many views on what the best language for beginners is as there are
teachers of programming. We are not saying C/C++ is the best choice; we are saying, however,
that C/C++ is a good choice. Why? Well, for several reasons: to name just a few, there have been
millions or even billions of lines of code written in C/C++, so it is particularly advantageous
when you are starting your adventure with programming and looking for examples – yes, the
C/C++ languages are simple, readable and flexible, and yes, they are versatile, portable, and fast;
what is more, there is a large and very active C/C++ community, which will lend you a hand
whenever you encounter a programming challenge.
There is nothing more valuable at the start than support that comes from other programming
professionals.
The C/C++ languages have influenced and been the backbone of a number of other languages
(for example, Java derives much of its syntax from C/C++). They are very powerful
programming tools.
Learning C/C++ gives you a wider perspective. First, it will give you a solid foundation and pave
your way to learning other programming languages much easier and much faster. And second,
when you code in C/C++, you actually have to understand everything you write. This means you
will understand everything the machine will do with your code, which, in turn, gives you full
control over what the machine will do and, consequently, gives you a better understanding of
how it works.
Knowledge of C/C++ helps you delve into the details of programming and the language is a
great foundation for learning more and more. Do not forget that.
Computer programs (also know as source code) is often written by professionals known as
Computer Programmers (simply programmers). Source code is written in one of programming
languages. A programming language is an artificial language that can be used to control the
behavior of a machine, particularly a computer. Programming languages, like natural language
(such as Amharic), are defined by syntactic and semantic rules which describe their structure
and meaning respectively. The syntax of a language describes the possible combinations of
symbols that form a syntactically correct program. The meaning given to a combination of
symbols is handled by semantics. Many programming languages have some form of written
specification of their syntax and semantics; some are defined only by an official implementation.
In general, programming languages allow humans to communicate instructions to machines.
Available programming languages come in a variety of forms and types. Thousands of different
programming languages have been developed, used, and discarded. Programming languages can
be divided in to two major categories: low-level and high-level languages.
Low-level languages
Computers only understand one language and that is binary language or the language of 1s and
0s. Binary language is also known as machine language, one of low-level languages. In the
initial years of computer programming, all the instructions were given in binary form. Although
the computer easily understood these programs, it proved too difficult for a normal human being
to remember all the instructions in the form of 0s and 1s. Therefore, computers remained
mystery to a common person until other languages such as assembly language was developed,
which were easier to learn and understand. Assembly language correspondences symbolic
instructions and executable machine codes and was created to use letters (called mnemonics) to
each machine language instructions to make it easier to remember or write. For example:
ADD A, B – adds two numbers in memory location A and B
Assembly language is nothing more than a symbolic representation of machine code, which
allows symbolic designation of memory locations. However, no matter how close assembly
language is to machine code, computers still cannot understand it. The assembly language must
be translated to machine code by a separate program called assembler. The machine instruction
created by the assembler from the original program (source code) is called object code. Thus
assembly languages are unique to a specific computer (machine). Assemblers are written for
each unique machine language.
High-level languages
Although programming in assembly language is not as difficult and error prone as stringing
together ones and zeros, it is slow and cumbersome. In addition it is hardware specific. The lack
of portability between different computers led to the development of high-level languages—so
called because they permitted a programmer to ignore many low-level details of the computer's
hardware. Further, it was recognized that the closer the syntax, rules, and mnemonics of the
programming language could be to "natural language" the less likely it became that the
programmer would inadvertently introduce errors (called "bugs") into the program. High-level
languages are more English-like and, therefore, make it easier for programmers to "think" in the
programming language. High-level languages also require translation to machine language
before execution. This translation is accomplished by either a compiler or an interpreter.
Compilers translate the entire source code program before execution. Interpreters translate source
code programs one line at a time. Interpreters are more interactive than compilers. FORTRAN
(FORmula TRANslator), BASIC (Bingers All Purpose Symbolic Instruction Code), PASCAL,
C, C++, Java are some examples of high-level languages.
The question of which language is best is one that consumes a lot of time and energy among
computer professionals. Every language has its strengths and weaknesses. For example,
FORTRAN is a particularly good language for processing numerical data, but it does not lend
itself very well to organizing large programs. Pascal is very good for writing well-structured and
readable programs, but it is not as flexible as the C programming language. C++ embodies
powerful object-oriented features
As might be expected in a dynamic and evolving field, there is no single standard for classifying
programming languages. Another most fundamental ways programming languages are
characterized (categorized) is by programming paradigm. A programming paradigm provides
the programmer's view of code execution. The most influential paradigms are examined in the
next three sections, in approximate chronological order.