Module Seven: Programming concepts (Notes)

A computer program is an organized list of instructions that, when executed, causes the computer to behave in a predetermined manner.

The distinction between computer program or software and hardware is sometimes confusing because they are so integrally linked. 

Program is a series of coded instructions in predetermined manner from which a computer behaves on execution

A computer software

Software refers to a collection of several programs and other procedures and documentation.

Clearly, when you purchase a program, you are buying software. 

But to buy the software, you need to buy the disk (hardware) on which the software is recorded or buying downloadable softcopy.

Programmer

Is someone who, designs and writes computer programs using a computer (Programming) language. 

Programming languages are to be run or executed on a computer including other activities associated with computer programs and computers.

Programmer environment is mostly the programs and the computers. The programmer runs, tests the program and documents the way the program works.

A programmer needs programming languages to write programs to be run by the computer. 

A programming language is a set of rules that provides a way of telling the computer what operations to perform.

This is the key to communicating with the computer, has a unique set of keywords (words that it understands) and a special syntax for organizing program instructions. 

It has a limited vocabulary. Each "word" in it has precise meaning.

There are many programming languages. However, computers are very primitive, in the sense that they understand only one language called the machine language or machine code which is a series of zeros (0’s) and ones (1’s). 

In other words, the information in a computer is represented as series of zeros and ones (Binary).

eg: -110010110001

      -100010011001

Program Execution

Interpreter

Each line of the program is sent to the interpreter that converts it into equivalent machine code instructions.

These machine code instructions are then executed. The next source line is then fetched from memory, converted and executed. This process is repeated till the entire program has been executed.

Compilers

Compilers accept programs written in a high level language and produce programs that are then converted to an executable file. 

Computer Programming Languages

a) Machine Language

b) Assembly language

c) High level languages

d) Fourth Generation Languages

Programming languages are said to be of two levels

i. Low Level: This is very close to the language the computer itself uses (0’s and 1’s) 

ii. High Level: This is very close to the language that people use (more English-like). 

a) Machine Languages

This is the lowest level programming language. Machine languages are the only languages understood by computers.

Machine languages represent information as a sequence of 0’s and 1’s. While easily understood by computers, machine languages are almost impossible for humans to use because they consist entirely of numbers. 

Machine languages and Assembly languages are machine dependent or machine oriented, that is they depend on the electronic nature of the computer.

Every CPU has its own unique machine language. Programs must be rewritten or recompiled, therefore, to run on different types of computers. 

This means that a program written in machine language  or assembly language on one computer model will not run on a different model

Tracing for errors is a complicated task, and they are prone to many errors. Machine languages and Assembly languages are generally referred to as Low Level Languages.

Any program written in one of the languages (2 – 4) must first be translated to machine language. The process is called compilation. 

The process of compilation can be demonstrated as follows:

b) Assembly Languages

Machine languages consist entirely of numbers and are almost impossible for humans to read and write.

Assembly languages have the same structure and set of commands as machine languages, but they enable a programmer to use names instead of numbers, such as ADD, SUBSTRACT, etc.

Assembly language programs are translated into machine language by a program called an assembler.

Each type of CPU has its own machine language and assembly language, so an assembly language program written for one type of CPU won't run on another. 

In the early days of programming, all programs were written in assembly language. Now, most programs are written in a high-level language such as FORTRAN or C.

Programmers still use assembly language when speed is essential or when they need to perform an operation that isn't possible in a high level language. 

For example, many embedded applications such as the code on a smart card, cellular phone, device drivers, etc. needs to be smaller.

Some procedures need complete access to the hardware, something usually impossible in high-level languages.

c) High Level Language (HLL) 

A programming language such as C, BASIC, COBOL, FORTRAN, Java, C++ or Pascal that enables a programmer to write programs that are more or less independent of a particular type of computer.

Such languages are considered high level because they are closer to human languages and further from machine languages. 

The main advantage of high-level languages over low level languages is that they are easier to read, write, and maintain

All HLL statements must be converted to machine code in order for a processor to run them. 

There are two ways in which high level language statements are converted into machine code, either at runtime (interpreted using interpreter) or before runtime (compiled using compiler).

The first high level programming languages were designed in the 1950s. Now there are dozens of different languages.

d) Fourth Generation Languages

Languages called very high-level languages are often known by their generation number. 

They are called fourth generation languages or more simply, 4GLs. e.g. Standard query language (SQL)

4GLs are somewhat nonprocedural. A procedural language tells the computer how a task is done i.e. add this, compare that, do this if something is true, and so forth; a very specific step by step process

The first three generations of languages are procedural. In a nonprocedural language, the concept changes. 

Users define only what they want the computer to do; the user does not provide the details of how to be done. It is much easier to just say what you want rather than explain how to get it done

Program Design (The Programming Process)

Program design is the process of writing computer instructions using a computer language for solving a particular problem. 

The program has to be written in a logical manner so that the computer will actually do what you want it to do. 

The process of designing computer programs is known as programming. Although programs vary in complexity, they all have three things in common:

i. Programs input information

ii. Programs manipulate data

Data manipulation includes changing the data the program reads in from the user, as well as creating new data from data it already has into a new result.

iii. Programs output information

When you write a program you must decide how the program will handle data, and how the operations performing the data handling will relate to each other.

A program rarely inputs all the information it needs, does all the manipulation, then does all the output. More often processes overlap, performed many times through the program’s run.

Knowing what a program should do is very different from knowing how to make the program do it.

There are various ways of creating computer programs. But generally one should consider the following steps: 

1. Defining the problem

2. Make a plan of the solution

3. Coding the program

4. Testing the program

5. Documenting the program

1. Defining the Problem

Before any program can be constructed, the programmer must have a clear understanding of precisely what the program must do. Often the program must solve more than one problem. In most cases, we solve problems every day, often unaware of the process you are going through. In a learning environment, you are usually given most of the information you need a clear statement of the problem, the necessary input. 

In real life, the process is not always so simple. You often have to define the problem yourself, and then decide what you have to work with and what the results should be. After you understand and analyze a problem, you must come up with a solution algorithm.

An algorithm is step by step procedure for solving a problem in a finite amount of time. To this end it is useful to focus on three aspects of the program: input, processing and output.

- Input

> The programmer has to ask himself the questions: what will be the structure, content and format of the data which the program is to process. 

> Is it to be created by the program itself, is it to be input via a VDU(VISUAL DISPLAY UNIT)? Is it  to be read from a file on a storage device? Is it to be read by a Bar Code Reader?

- Input

> Is it be entered item by item by an operator or user using a keyboard? 

> Is the data to be alphanumeric or numeric, text etc?

> Is the input data required for an artificial intelligence?

> Here it means you may need may be voice, fingerprint, eye – retina, or any human body recognition system.

Processing

What is the algorithm required to operate on the input to produce the desired output? What calculations are needed? 

Does the format of the data need changes between its input form and that in which it is to be output? Do any validation checks need to be applied to the input data to ensure that it is acceptable? 

Do any totals or counters need to be accumulated? 

Output

What is the structure, content and format of the required output? Is the data to be printed, displayed on a screen, or written to secondary storage?

Here you may also need an output to be in different form for instance motion, movements or actuation (To trigger even mechanical device; think of an ATM) 

2. Planning a Solution

A solution can be thought of as an ordered set of activities that will convert the given input into the desired output. This is the most complex part of the entire programming process.

There are many approaches to planning solutions. There two common approaches (ways) of planning the solution to a programming problem:

Drawing a flowchart and writing an algorithms and or pseudo code.

Flowchart

 Is a tool developed in the computer industry, for showing the steps involved in a process. 

A flowchart is a diagram made up of boxes, diamonds and other shapes, connected by arrows  each shape represents a step in the process, and the arrows show the order in which they occur.

Flowcharting combines symbols and flow lines, to show figuratively the operation of an algorithm.

Pseudo code 

- Is a tool that can be used to write a preliminary plan of a program; it is not a standard language, programmers usually use terms, which closely resemble the actual computer language.

- Its purpose is to describe the algorithm in a form that can be easily understood and translated into the actual programming code required. 

- The syntax and the details of the program are ignored until writing the source code. 

3. Coding the program

Coding the Program refers to the process of transferring a pseudo code program or flowchart into a computer program using a programming language.

The program statements are written in such a way that they are in accordance with the language syntax.

This is a compulsory set of programming rules to foster the habit of following some convention consistently. 

4. Program Testing

- Assuming your program has compiled successfully with no warning messages, what comes next? The answer is testing, but this is not as simple as it seems.

- Any program needs testing in order to show that it works in the desired fashion.

- Testing is a formal evaluation technique in which software is examined in detail by a person or group other than the author to see if the program behave as desired and to detect faults, violations of development standards, and other problems. 

5. Documenting the program

- Documentation or the preparation of documents that explains the program is an essential but sometimes neglected part of the programming process. 

- Because the provision of the necessary documentation to support a program is not seen as a challenge or intellectual exercise, it is seldom done or done not properly.

- It should be one of the fundamental principles of programmer management that no program is allowed to be used without having been provided with sufficient documentation.

- Documentation is valuable because it helps the next programmer who is later asked to update the program.

- Program Documentation can substantially reduce the amount of time the new programmer will have to spend learning about the program to know how best to make a change.

- Documentation of the program is also necessary for the users who will be using the program to understand what’s the required input, the nature of the processing carried out by the program and the output.

No comments