Programming: The Basic Concept

You might also like

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

2013

Programming: The basic concept

Ogbonna Ifeanyichukwu Charles

WE ALL ARE PROGRAMMERS

Introduction to programming
In our daily lives, we plan our activities to follow and order that we see fit for us and the circumstances surrounding our existence at that particular time. In a day, one might have to go to work, go to the bank, and go to the gym. This person might not start by going for shopping in the morning by 8am when he/she is aware that 8am is the time for him to be at his office. The person will probably plan the day as follows: since work starts by 8am and at about 1pm, it will be time for lunch. The person most probably will start by going to the office in the morning. During the lunch hour, he will then go to the bank and from the bank he goes for shopping. He returns to the office to complete his work at the office until the office hours is over. He then goes to gym and from there return his house. Except for eccentric fellows, most people will follow this approach in order be able to perform all these tasks and efficiently too. These activities can be represented in the figure below.

A department might need to compute the CGPA of the students. There are some basic tasks that the department has to carry out to be able to compute the students CGPA. They will start by collecting the results from the various lectures that must have taught the students. The department vets the results if they are comfortable with them otherwise they return it to the lecturer for correction. The vetting of the results is followed by the results been sent to the examination office who is meant to calculate the CGPA. The staff on collecting the vetted results, applies the formula that

is used to calculate the CGPA. The CGPA is then sent to the department for final vetting and it is the department that is responsible for sending it to the requesting party.

Collect result from lecturers

Vetting the results

Calculation of CGPA by Ex. Officer

Stamping the CGPA by Dept.

In the morning, to get ready for work, one is likely to do the following: get out of the bed, take off pajamas, take shower, get dressed, eat breakfast, and leave for work. The person doesnt wake up, get dressed, and take shower. Or wake up, leave for wake and take off pajamas. The above instances show us that we human beings arrange our activities according to the order that suites us or our situation at that particular time. The tasks we do daily are arranged sequentially in ways that we think fits us the most. This leads us to the definition of the word programming. Programming is setting the order and time of execution of planned events. Relating this definition to the instances above, we find out that we program most of our activities for one will wake up by 6am in the morning, and in order to prepare for work, the person does some predefined activities in a predefined order.

Computer programming:
Programming as we defined it earlier is setting the order and time of execution of planned events. Now computer programming, it is the setting the order and time of execution of planned computer events. It can also be defined as creating a sequence of instructions to enable a computer do something. Most people mistake programming for computer programming but the truth is that computer programming is a kind of programming because there are many things to program

that are not computer events. An instance of a computer programme is a program that adds two numbers, to create this program, we create an algorithm for it. The algorithm might go as follows: Collect the first number, collect the second number, add both numbers together to get the answer and print out the answer for the user. Unless one is eccentric, the person will not start by adding the numbers first especially when he has not collected the numbers.

The above instance show that computer programming is a type of programming. Computer programming seems too different from other types of programming in that for you to create a computer program, you must have a special knowledge which is the knowledge of computer programming language. If it is desired to give a definition of THE BASIC IDEA BEHIND computer programming, one might say that it is an PROGRAMMING IS activity by which a digital computer is made to do KNOW WHAT YOU WANT a mans will, by expressing this will suitably on TO DO, KNOWING THE other input medium punched tapes, or whatever PROCESSES THAT ARE machine. This is that is accepted by the INVOLVED, AND THEN working up from normally achieved by ARRANGING THE requirements to more relatively simple complex ones. Thus for PROCESSES IN THE MOST instance if it is desired to do a Fourier analysis on SUITABLE WAY the machine, it would do well to arrange first one that can calculate cosines on it. For each process that one wishes the machine to be able to carry out one constructs a routine of the process. This consists mainly of set of instructions

which are obeyed in the process as part of the routine. Many of them will belong to other routines, previously constructed and carrying out simpler processes. Thus for instance the Fourier analysis process would involve obeying instructions in the routine for forming cosines as well as one in the analysis routine proper. In a case like this, the cosine routine is described as a subroutine of the analysis routine. The subroutines of any routine may themselves have subroutines. This is like the case of the bigger and lesser fleas. I am not sure if the exact meaning the poet attached to the phrase and so ad infinitum, but am inclined to think that he meant there was no limit that one could assign to the length of a parasitic chain of fleas, rather than that, he believed in infinitely long chains. This is certainly the case with the subroutines. One always eventually comes down to a routine without subroutines. Expertise in computer programming is achieved more by practice rather than from reading. There are basic principles that can be taken to make computer programming easier with more expertise. Principles of computer programming 1. Program planning: When you are faced with a programming problem, one the first things you do is to plan how you will be able to solve the problem. You might need to write a computer program that will do a numerical calculations, you will not start writing the code without knowing the formulae that are going to use for the computations. For example if one were calculating the Bessel function jox one would have, amongst others, the alternatives of using the power series in x, various other power series with other origins, interpolation from a table, various definite integrals, integration of the differential equation by small arcs, and asymptotic formulae. It may be necessary to give some small consideration to a number of the alternative methods. There are also things that you consider while making this plan which include: i. To carry the process through as fast as possible ii. To use little storage for the program iii. To finish the program as quickly as possible iv. To finish the program with great accuracy To have made a good decision is for one to have satisfied a great percentage of the above consideration. The considerations work hand in hand in that fulfilling one without the other is bad. Imagine taking 3 years to write a program that solves the Bessels function accurately but the application takes

two months to do the calculation. So, all the considerations have to be greatly satisfied for one to be said to have made a good plan. 2. Break the main task into smaller units (subroutines): Every program that one wants to write can be divided into small parts or small chunks of code called subroutines which is a sequence of steps, parts of a larger computer program. For instance if one wants to write a program that solves a quadratic equation, the person starts by collecting the equation to be solved before he goes ahead to apply the formula that he desires to use in the computation. So, the program can be split into the following: collection of the equation to be solved, applying the chosen formula to the user entered value and outputting the result for the user. Subroutine is used in programming to represent a block of code that performs a particular function. 3. Create the small task or subroutines: Once the program is split into small parts, it will be easy for the programmer to start creating the subroutines of the main projects. This is done by combining the syntaxes of the programming language to create the sequence of instructions that will be used to achieve the main aim of the subroutine. 4. Merge the subroutines: The subroutines created by the programmer cannot work independently to achieve the main aim of the project, the programmer using a programming language will now call the subroutines at desired times and with desired arguments to be able to solve the problem that the program is meant to solve. This is done by creating the main routine of the program, it is this routine that calls all the subroutine of the program at the times that they are needed to be called. For example we want to create a program that will solve the following equation; cosx + siny - z. In writing a program that will solve the equation, we might decide to solve the equation using just one routine that does not have any subroutines or one routine with subroutines. This is thing we do in the planning phase. If we decide to use subroutines which is one of the things that the principles is teaching us, we then decide the parts of the program that we want to split. We might decide to create three subroutines that: calculate cosine, sine and square root. These subroutines does the above jobs and return their results to the main routine which then does a simple summation (a + b c) to get the result of the whole calculation. The whole process is represented in the diagram below.

As we stated earlier, for one to be able to do computer programming, the person must have at least the basic idea of a computer programming language. We now go ahead to get the brief knowledge of programming languages.

Programming Language
Programming Language, in computer science, artificial language used to write a sequence of instructions (a computer program) that can be run by a computer. Similar to natural languages, such as English, programming languages have a vocabulary, grammar, and syntax. However, natural languages are not suited for programming computers because they are ambiguous, meaning that their vocabulary and grammatical structure may be interpreted in multiple ways. The languages used to program computers must have simple logical structures, and the rules for their grammar, spelling, and punctuation must be precise. Programming languages vary greatly in their sophistication and in their degree of versatility. Some programming languages are written to address a particular kind of computing problem or for use on a particular model of computer system. For

instance, programming languages such as FORTRAN and COBOL were written to solve certain general types of programming problemsFORTRAN for scientific applications, and COBOL for business applications. Although these languages were designed to address specific categories of computer problems, they are highly portable, meaning that they may be used to program many types of computers. Other languages, such as machine languages, are designed to be used by one specific model of computer system, or even by one specific computer in certain research applications. The most commonly used programming languages are highly portable and can be used to effectively solve diverse types of computing problems. Languages like C, PASCAL, and BASIC fall into this category.

Language Types
Programming languages can be classified as either low-level languages or high-level languages. Low-level programming languages, or machine languages, are the most basic type of programming languages and can be understood directly by a computer. Machine languages differ depending on the manufacturer and model of computer. High-level languages are programming languages that must first be translated into a machine language before they can be understood and processed by a computer. Examples of high-level languages are C, C++, PASCAL, and Fortran. Assembly languages are intermediate languages that are very close to machine language and do not have the level of linguistic sophistication exhibited by other high-level languages, but must still be translated into machine language.

Machine Language
In machine languages, instructions are written as sequences of 1s and 0s, called bits, that a computer can understand directly. An instruction in machine language generally tells the computer four things: (1) where to find one or two numbers or simple pieces of data in the main computer memory (Random Access Memory, or RAM), (2) a simple operation to perform, such as adding the two numbers together, (3) where in the main memory to put the result of this simple operation, and (4) where to find the next instruction to perform. While all executable programs are eventually read by the computer in machine language, they are not all programmed in machine language. It is extremely difficult to program directly in machine language because the instructions are sequences of 1s and 0s. A typical instruction in a machine language might read 10010 1100 1011 and mean add the contents of storage register A to the contents of storage register B.

High-Level Languages
High-level languages are relatively sophisticated sets of statements utilizing words and syntax from human language. They are more similar to normal human languages than assembly or machine languages and are therefore easier to use for writing complicated programs. These programming languages allow larger and more complicated programs to be developed faster. However, high-level languages must be translated into machine language by another program called a compiler before a computer can understand them. For this reason, programs written in a high-level language may take longer to execute and use up more memory than programs written in an assembly language.

Assembly language
Computer programmers use assembly languages to make machine-language programs easier to write. In an assembly language, each statement corresponds roughly to one machine language instruction. An assembly language statement is composed with the aid of easy to remember commands. The command to add the contents of the storage register A to the contents of storage register B might be written ADD B,A in a typical assembly language statement. Assembly languages share certain features with machine languages. For instance, it is possible to manipulate specific bits in both assembly and machine languages. Programmers use assembly languages when it is important to minimize the time it takes to run a program, because the translation from assembly language to machine language is relatively simple. Assembly languages are also used when some part of the computer has to be controlled directly, such as individual dots on a monitor or the flow of individual characters to a printer.

Classification of High-Level languages


High-level languages are commonly classified as procedure-oriented, functional, object-oriented, or logic languages. The most common high-level languages today are procedure-oriented languages. In these languages, one or more related blocks of statements that perform some complete function are grouped together into a program module, or procedure, and given a name such as procedure A. If the same sequence of operations is needed elsewhere in the program, a simple statement can

be used to refer back to the procedure. In essence, a procedure is just a miniprogram. A large program can be constructed by grouping together procedures that perform different tasks. Procedural languages allow programs to be shorter and easier for the computer to read, but they require the programmer to design each procedure to be general enough to be used in different situations. Functional languages treat procedures like mathematical functions and allow them to be processed like any other data in a program. This allows a much higher and more rigorous level of program construction. Functional languages also allow variables symbols for data that can be specified and changed by the user as the program is runningto be given values only once. This simplifies programming by reducing the need to be concerned with the exact order of statement execution, since a variable does not have to be redeclared, or restated, each time it is used in a program statement. Many of the ideas from functional languages have become key parts of many modern procedural languages. Object-oriented languages are outgrowths of functional languages. In objectoriented languages, the code used to write the program and the data processed by the program are grouped together into units called objects. Objects are further grouped into classes, which define the attributes objects must have. A simple example of a class is the class Book. Objects within this class might be Novel and Short Story. Objects also have certain functions associated with them, called methods. The computer accesses an object through the use of one of the objects methods. The method performs some action to the data in the object and returns this value to the computer. Classes of objects can also be further grouped into hierarchies, in which objects of one class can inherit methods from another class. The structure provided in object-oriented languages makes them very useful for complicated programming tasks. Logic languages use logic as their mathematical base. A logic program consists of sets of facts and if-then rules, which specify how one set of facts may be deduced from others, for example: If the statement X is true, then the statement Y is false. In the execution of such a program, an input statement can be logically deduced from other statements in the program. Many artificial intelligence programs are written in such languages.

Language structure and components


Programming languages use specific types of statements, or instructions, to provide functional structure to the program. A statement in a program is a basic sentence that expresses a simple ideaits purpose is to give the computer a basic instruction. Statements define the types of data allowed, how data are to be manipulated, and the ways that procedures and functions work. Programmers use statements to manipulate common components of programming languages, such as variables and macros (mini-programs within a program). Statements known as data declarations give names and properties to elements of a program called variables. Variables can be assigned different values within the program. The properties variables can have are called types, and they include such things as what possible values might be saved in the variables, how much numerical accuracy is to be used in the values, and how one variable may represent a collection of simpler values in an organized fashion, such as a table or array. In many programming languages, a key data type is a pointer. Variables that are pointers do not themselves have values; instead, they have information that the computer can use to locate some other variablethat is, they point to another variable. An expression is a piece of a statement that describes a series of computations to be performed on some of the programs variables, such as X + Y/Z, in which the variables are X, Y, and Z and the computations are addition and division. An assignment statement assigns a variable a value derived from some expression, while conditional statements specify expressions to be tested and then used to select which other statements should be executed next. Procedure and function statements define certain blocks of code as procedures or functions that can then be returned to later in the program. These statements also define the kinds of variables and parameters the programmer can choose and the type of value that the code will return when an expression accesses the procedure or function. Many programming languages also permit minitranslation programs called macros. Macros translate segments of code that have been written in a language structure defined by the programmer into statements that the programming language understands.

Brief History of computer programming languages


Programming languages date back almost to the invention of the digital computer in the 1940s. The first assembly languages emerged in the late 1950s with the introduction of commercial computers. The first procedural languages were developed in the late 1950s to early 1960s: FORTRAN (FORmula TRANslation), created by John Backus, and then COBOL (COmmon Business Oriented Language), created by Grace Hopper. The first functional language was LISP (LISt Processing), written by John McCarthy in the late 1950s. Although heavily updated, all three languages are still widely used today. In the late 1960s, the first object-oriented languages, such as SIMULA, emerged. Logic languages became well known in the mid-1970s with the introduction of PROLOG, a language used to program artificial intelligence software. During the 1970s, procedural languages continued to develop with ALGOL, BASIC, PASCAL, C, and Ada. SMALLTALK was a highly influential object-oriented language that led to the merging of object-oriented and procedural languages in C++ and more recently in JAVA. Although pure logic languages have declined in popularity, variations have become vitally important in the form of relational languages for modern databases, such as SQL (Structured Query Language).

You might also like