Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

comp120classNotes-Intro To Programming

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

COMP 120 INTRODUCTION TO

PROGRAMMING

Introduction to programming
“Computers are everywhere. Be it departmental stores, hotels, atomic power stations or
defense. Computers aid human force in effectively administering a task. The growth of
computers is exponential, so is the need for good programmers. By good programmers we do
not mean programmers who can give solutions, but programmers who can give effective
solutions. Good programmers are not born rather they are groomed. A programmer’s skills wear
out well with experience and practice” (Priya and Ranjeet, 2006).
Therefore, this interesting unit introduces you to what programming is and also help you to
familiarize yourself with frequently applied terms in the programming world. “At the end of the
unit you will be speaking the language of programmers”. We are also interested in knowing how
and probably when programming started, and where we are in programming; that is, the current
state of programming in terms of programming language generations which includes types of
programming languages and various programming styles also known as programming
paradigms.

Topic Objectives

Upon completion of this unit you should be able to:

● Explain basic programming concepts


● Describe developments in programming languages and influences on evolution of
language designs
● Describe the levels and generations of programming languages
● Describe the characteristics of a good language
● Describe characteristics of programming language paradigms

1|Page
Key Terms

Programming: is the activity of writing instructions to be executed by the computer. These


instructions tell the computer to do something. For example solve a particular problem, say,
read in student marks then compute and grade scores per student and provide a list of students
proceeding to the next class and another list of students retaking the course. All these are
instructions (logic). A computer is not able to act without instructions. Also, programming is the
art of performing computational tasks and converting these tasks into machine readable form
(Priya and Ranjeet, 2006)
Programming language: is a series of instructions for writing programs.
Programming language Paradigms: define the way programs are structured or programming
styles.
Programmer: is the person writing instructions or develops a program through the act of
programming.
A program: is a series of instructions that directs the computer to do something. It is the end
product of programming activity also known as software.
Syntax: of a computer language is the set of rules that defines the combinations of symbols that
are considered to be a correctly structured document or fragment in that language
(http://en.wikipedia.org).
Semantics: define the meaning of syntactically legal strings defined by a specific programming
language, showing the computation involved (http://en.wikipedia.org).

History of Programming

Introduction

Programming can be defined as the act of using a programming language to write instructions
that can be executed by the computer with the aim of solving problems by applying the correct
language syntax and semantics. Hundreds of programming languages have been developed
and some are in existence while some are not. This means that programming language
development has come a long way thus having long history; from Plankalkul, Prolog,

2|Page
FORTRAN, C, Visual Basic.Net, to Rust and to Swift. Some of these languages were improved
and gained more popularity than others. Below is a summary of the history of programming
languages as presented by Seema Kedar; see reference.
1951–55: Experimental use of expression compilers.
1956–60: FORTRAN, COBOL,LISP,Algol60.
1961–65:APL notation, Algol 60 (revised), SNOBOL, CPL.
1966–70:APL, SNOBOL 4, FORTRAN 66, BASIC,SIMULA,Algol 68, Algol-W, BCPL.
1971–75:Pascal, PL/1 (Standard), C, Scheme, Prolog.
1976–80:Smalltalk, Ada, FORTRAN 77, ML.
Read: http://en.wikipedia.org/wiki/Plankalk%C3%BCl and the handouts
Activity (individual)
This activity requires you to read on the history of programming; how programming started and
the application of the program, their descendants - to the current languages. Influences on
evolution of languages design and development. The readings can be obtained from
http://www.softpanorama.org/History/lang_history.shtml#General and
https://theory.stanford.edu/~jcm/books/cpl-sample.pdf (page 6-13). After reading, you are
required to;
● List at least five problems that can be solved using a computer (just to check
understanding on what programming is)
● Describe how programming started and the situations that led to development of
programs
● Using a chart, describe the proliferation of programming languages; Name and
describe the applications and significance of the programming languages. Show and
describe all the descendants of a particular language.

Levels, generations and paradigms of programming languages

Introduction

Programmers use programming languages to write programs. These programming languages


have evolved over time with the earliest languages also known as first generation language
which used machine code to program the computer - this can be dated back to 1940-1950. This
language is termed as a low level language. The next development was the second generation

3|Page
language dated back to 1950-58 which used the assembly language to represent machine
language instructions. These were then translated into machine code by an assembler. This
language was still a low level language. Then the third generation languages, also known as
high-level programming languages such as C, Pascal, FORTRAN and COBOL, can be dated
back to 1958-85. These languages were easier to use than assembly languages and machine
code and helped to improve quality and productivity. Compilers and interpreters are used to
translate instructions in a high level language to machine language. There are also fourth
generation languages dated 1985-onwards. These languages include report generators which
are said to reduce programming effort. The fifth generation programming languages dated
1990-onwards are mainly used in the field of artificial intelligence.
Each generation of programming language has its own features and the newer generation
languages are more improved than the older one. A programming language may be supported
by more than one programming paradigm. Paradigm define how the program is structured (We
shall discuss paradigms later in this unit).
There are two major levels of programming languages; low level and high level programming
languages.
Machine language: Using this language, programs written using 0’s and 1’s. It was used in the
earlier days to program a computer. It is faster because instructions are directly executable, and
makes most efficient use of resources like the registers and storage units. Currently, this
language is not highly appreciated because programs are not portable meaning they are
machine dependent, it is more prone to errors and hard to debug, requires high level
programming skills thus high cost of training.
Assembly language: This language uses mnemonics or short abbreviation representing an
instruction. It is easier to use than machine language simply because mnemonics are nearer to
the programmer than the computer (machine). Assembler is used to convert instructions to
machine language.
High level languages: Programs are written in English like statements. They are not directly
executable, therefore, translators which include compilers and interpreters are used to convert
instructions to computer language. Languages that fall in this category are highly appreciated
because, they are portable, easier to learn and write a program, availability of libraries, easy to
maintain and document. High level languages have various attributes or characteristics which

include; portability, readability, concurrency support, mixed language support, reliability,


modularity, real-time support and orthogonality.

4|Page
Fourth generation languages: These languages also known as 4GL emphasize on what is to be
accomplished than how it should be accomplished. For example Oracle, VB, SQL e.t.c. They
are mainly used to access the database. 4GLs increases productivity. 4GL has various feature
that makes it attractive. These include;
● Ease of use
● Limited range of functions
● Availability of options
● Default options
Visual programming languages (VPL): is any programming language that lets users create
programs by manipulating program elements graphically rather than by specifying them
textually. A VPL allows programming with visual expressions, spatial arrangements of text and
graphic symbols, used either as elements of syntax or secondary notation. For example, many
VPLs (known as dataflow or diagrammatic programming) are based on the idea of "boxes and
arrows", where boxes or other screen objects are treated as entities, connected by arrows, lines
or arcs which represent relations. An instructive counterexample for visual programming
languages is Microsoft Visual Studio. The languages it encompasses (Visual Basic, Visual C#,
Visual J#, etc.) are commonly confused with, but are not visual programming languages. All of
these languages are textual and not graphical. MS Visual Studio is a visual programming
environment, but not a visual programming language, hence the confusion
(https://en.wikipedia.org/wiki/Visual_programming_language).
Compilers
A compiler translates a high level program to a machine language. The high level program is
called a source code, which is translated to produce machine readable code known as object
code. Most or all high level languages are compiler based. For example, C compiler, C++, e.t.c

Interpreters
Just like the compilers, interpreters translate high level language program to machine readable
format. The difference with the compilers is that, interpreters translate code statement by
statement and if an error is encountered, it stops and will continue after the error has been
corrected. While compilers translate the entire program, then list the errors, if any. This means
that, compilers are faster than the interpreters.

Influences on evolution of language design


Seema Kedar discussed six influences;
i. Computer capabilities: Computers have greatly improved in the way they process
information. There have been major improvements in the hardware and at the same time

5|Page
software (operating systems). This improvements calls for the design of better languages.
ii. Applications: Application means the use of computers. They started from performing small
computations, handling military activities, scientific activities like research, medical, business
to games and the internet. The requirements of the new application areas lead to the
improvement of existing languages or the design of new languages
iii. Programming methods: As problems become more complex, new methods are invented to
aid reduce complexities and improve productivity.
iv. Implementation methods: The development of better implementation methods has affected
the choice of features to include in new language designs
v. Theoretical studies: Research into the conceptual foundation for language design and
implementation using formal mathematical methods has increased our understanding of the
strengths and weaknesses of language feature which has influenced the inclusion of these
features in new language design
vi. Standardization: The need for a standard language that can be implemented easily using a
computer systems which allow programs to be translated from one computer to another has
provided a strong influence on evolution of language designs.

Languages have different strengths. Some languages support particular applications than
others. What therefore, define a good programming language?
i. Clarity, simplicity and unity
ii. Orthogonality
iii. naturalness for the application
iv. Support for abstraction
v. Ease of program verification
vi. Programming environment
vii. Portability of the programs
viii. cost, which include;
● cost of training
● cost of writing the program
● cost of executing the program
● cost of translation
● cost of implementation
● cost of maintenance

6|Page
Programming language paradigms
Programming languages are structured in different ways. Therefore languages can be grouped
according to the way they are structured or designed simply known as paradigm. paradigms
include;
i. Imperative or procedural languages: is a type of imperative programming in which the
program is built from one or more procedures (also known as subroutines or functions).
ii. Declarative languages: These languages contrasts with imperative and procedural
programming. Declarative programming is a non-imperative style of programming in which
programs describe their desired results without explicitly listing commands or steps that must
be performed.
iii. Rule-based or logical languages: They support decision making based on the provided
conditions
iv. Object oriented languages: It is a paradigm that provides solutions that depict the real world
scenario. It emphasizes more on data. It uses the concept of classes where an object is
seen in terms of data (what it can process) and what it can do (methods).
v. Concurrent languages: They apply the concept of a process. A process corresponds to a
sequential computation, with its own thread of control.

Activity Details
In this activity you are required to read on the levels (other authors call this types of
programming languages) and generations of programming languages; note the characteristics,
advantages and disadvantages of each type/level including generations of programming
languages. Read on the characteristics of a good programming language. Read also on
programming language paradigm; characteristics of each paradigm including languages that fit
in each paradigm. Describing the levels and generations of programming languages and
naming programming languages that fall into a particular level and generation.
● Describing the features of the programming languages that belong to a particular level
and generation.
● Describing the characteristics of a good programming language. How is a good
programming language defined?
● Describing the features of the programming languages that are grouped to a particular
programming paradigm.

Activity – Teamwork activity (collaboration)

7|Page
Introduction
This activity entails a group activity where the learners will be required to understand the
practicality of programming languages and paradigms. The learners are required to do a small
study on the commonly used languages and the paradigms supported by those languages using
accessible individual developer e.g senior Bsc. Computer science students in your institution
especially the fourth year students.

Activity Details
By visiting individual developers and/or firms;
● Find out the most popular programming languages in the industry and the paradigms
supported by the languages. Give reasons for their popularity.
● Find out how programmers select the programming language to be used in solving a
particular problem problem.

Summary
Computer programming has a very long history which can be dated back to 1940s or earlier.
Computer programming (often shortened to programming) is a process that leads from an
original formulation of a computing problem to executable computer programs. Programming
involves activities such as analysis, developing understanding, generating algorithms,
verification of requirements of algorithms including their correctness and resources
consumption, and implementation (commonly referred to as coding) of algorithms in a target
programming language. Source code is written in one or more programming languages. The
purpose of programming is to find a sequence of instructions that will automate performing a
specific task or solving a given problem.The notion of programming paradigms is a way to
classify programming languages, according to styles of computer programming. Features of
various programming languages determine which programming paradigms they belong to.
Some programming languages fall into only one paradigm, while others fall into multiple
paradigms. Some paradigms are concerned primarily with implications for the execution model,
of the language, for example, whether the sequence of operations is defined by the execution
model. Other paradigms are concerned primarily with the way that code is organized, such as
grouping code into units along with the state that is modified by the code. Common
programming paradigms include imperative which allows side effects, functional which does not
allow side effects, declarative which does not state the order in which operations execute,
object-oriented which groups code together with the state the code modifies, procedural which
groups code into functions, logic which has a particular style of execution model coupled to a
particular style of syntax and grammar, and symbolic programming which has a particular style
of syntax and grammar. Upto here, the learner understands the basic concepts of programming
and is ready to move to the next unit.
Jace glenn October 9th
My note. From here just read everything and write anything that is high profile and

8|Page
beenficiary

REMEMBER! We summarized paradigms into three categories;


Software Evaluation Ernest Tello, A well known writer in the field of artificial intelligence,
compared the evolution of software technology to the growth of the tree. Like a tree, the
software evolution has had distinct phases “layers” of growth. These layers were building up
one by one over the last five decades as shown in figure below, with each layer representing
and improvement over the previous one. However, the analogy fails if we consider the life of
these layers. In software system each of the layers continues to be functional, whereas in the
case of trees, only the uppermost layer is functional

*****procedural oriented is structured programming paradigms


Alan Kay, one of the promoters of the object-oriented paradigm and the principal designer of
Smalltalk, has said: “As complexity increases, architecture dominates the basic materials”. To
build today’s complex software it is just not enough to put together a sequence of programming
statements and sets of procedures and modules; we need to incorporate sound construction

MY NOTES , AS SOFTWARES COMPLEXITY INCREASES , SOUND ARTICTECHTURES


AND SOUNDS DESIGN SYSTEMS ALSO NEED IN PLACE FOR GOOD SYSTEMS

techniques and program structures that are easy to comprehend implement and modify.
With the advent of languages such as c, structured programming became very popular and was
the main technique of the 1980’s. Structured programming was a powerful tool that enabled

9|Page
programmers to write moderately complex programs fairly easily. However, as the programs
grew larger, even the structured approach failed to show the desired result in terms of bug-free,
easy-tomaintain, and reusable programs. Object Oriented Programming (OOP) is an approach
to program organization and development that attempts to eliminate some of the pitfalls of
conventional programming methods by incorporating the best of structured programming
features with several powerful new concepts. It is a new way of organizing and developing
programs and has nothing to do with any particular language. However, not all languages are
suitable to implement the OOP concepts easily.

Computer programming paradigms (as presented in class).


There are many programming languages in the market (C, C++, Java, C# etc). These
languages may hold common features or instructions (as indicated below) but have various
differences like the syntax rules applied to individual program or the type of paradigm they
belong to. Different programming languages support different styles of programming called
programming paradigms. The paradigm here define how a particular language is structured.
These include:-
1. Unstructured programming paradigm
During the 1950’s and 1960’s many people did not think about the question of developing
general method for organizing a program. Instead, programs were written much the same way
you might off the top of your head give someone instructions on how to change a tire or worse
build a house. When program did not work, it was simply “patched” (fixed) error by error until the
programmer felt that he had found them all. Usually, however, errors continued to appear even
after the program was released for use.
Unstructured programming has been heavily criticized for producing hardly-readable
("spaghetti") code and is sometimes considered a bad approach for creating major projects, but
had been praised for the freedom it offers to programmers. This paradigm uses a GOTO
statement as a control statement.
There are both high- and low-level programming languages that use non-structured
programming. These include early versions of BASIC (such as MSX BASIC and GW-BASIC),
FORTRAN, JOSS, FOCAL, MUMPS, TELCOMP, COBOL, machine-level code etc.
A program in a non-structured language usually consists of sequentially ordered commands, or
statements, usually one in each line. The lines are usually numbered or may have labels: this
allows the flow of execution to jump to any line in the program using GOTO statement.

10 | P a g e
Q.
Based on the class discussion and the above description, identify various disadvantages and
advantages of unstructured programming paradigm.

2. Structured programming paradigm

11 | P a g e
12 | P a g e
13 | P a g e
14 | P a g e
15 | P a g e
16 | P a g e
From the above discussions (text), we realize that, in the strucrured/procedure oriented
approach, the problem is viewed as the sequence of things to be done such as reading,
calculating and printing such as cobol, fortran and c. The primary focus is on functions. A typical
structure for procedural programming is shown below.

The technique of hierarchical decomposition has been used to specify the tasks to be completed
for solving a problem.
Structured/Procedure oriented programming basically consists of writing a list of instructions for
the computer to follow, and organizing these instructions into groups known as functions. We
normally use flowcharts to organize these actions and represent the flow of control from one
action to another. In a multi-function program, many important data items are placed as global so
that they may be accessed by all the functions. Each function may have its own local data.
Global data are more vulnerable to an inadvertent change by a function. In a large program it is
very difficult to identify what data is used by which function. In case we need to revise an
external data structure, we also need to revise all functions that access the data. This provides an
opportunity for bugs to creep in. Another serious drawback with the procedural approach is that

17 | P a g e
we do not model real world problems very well. This is because functions are action-oriented
and do not really corresponding to the element of the problem.
Some Characteristics exhibited by structured or procedure-oriented programming are:
• Emphasis is on doing things (algorithms).
• Large programs are divided into smaller programs known as functions.
• Most of the functions share global data.
• Data move openly around the system from function to function.
• Functions transform data from one form to another.
• Employs top-down approach in program design.

3 Object Oriented Paradigm


The major motivating factor in the invention of object-oriented approach is to remove some of
the flaws encountered in the procedural approach. OOP treats data as a critical element in the
program development and does not allow it to flow freely around the system. It ties data more
closely to the function that operate on it, and protects it from accidental modification from
outside function. OOP allows decomposition of a problem into a number of entities called
objects and then builds data and function around these objects. The organization of data and
function in object-oriented programs is shown in fig.1.3. The data of an object can be accessed
only by the function associated with that object. However, function of one object can access the
function of other objects.

Some of the features of object oriented programming are:


• Emphasis is on data rather than procedure.
• Programs are divided into what are known as objects.
• Data structures are designed such that they characterize the objects.
• Functions that operate on the data of an object are ties together in the data structure.
• Data is hidden and cannot be accessed by external function.
• Objects may communicate with each other through function.
• New data and functions can be easily added whenever necessary.

18 | P a g e
• Follows bottom up approach in program design.
Object-oriented programming is the most recent concept among programming paradigms and
still means different things to different people.

19 | P a g e

You might also like