Monday, August 24, 2015

Introduction of Programming

Introduction to Programming
Computers are really very dumb machines and cannot do anything without instruction. They do only what they are told to do. Most computer systems can perform some very basic operation such as adding two binary digits or testing whether a number is equal to zero. The basic operation a computer can perform is known as computer’s instruction set.
To solve a problem using a computer one must express the solution of the problem in term of the instruction of the particular computer. A computer program is just a collection of the instructions necessary to solve a specific problem. More formally, a computer program is a sequence of instructions that is used to operate a computer to solve a specific problem and produce expected result.

Programming Language
A language is the method to communicate another person or community and a programming language is the method to communicate or instruct computer. More formally, a programming language is a standardized communication technique for describing instructions for a computer. Each programming language has a set of syntactic and semantic rules used to define computer programs. A language enables a programmer to precisely specify what data a computer is to act upon, how these data are to be stored/transmitted and what actions are to be taken under various circumstances.   
On a fundamental level, all computer programs do the same thing. They direct a computer to accept data (input), to manipulate the data (process), and to produce desire result (output). This implies that all computer programming languages must provide essentially the same capabilities for performing these operations.
If all programming languages provide essentially the same features, why are there so many of them? The answer is that there are vast differences in the types of input data, calculations needed, and output reports required by various applications. For example, scientific and engineering application required high-precession numerical outputs, accurate to many decimal places. In addition, these applications typically use many algebraic and trigonometric formulas to produce their results. For such applications, the FORTRAN programming language, with its algebra like instruction, was initially developed. FORTRAN, whose name is an acronym derived from FORmula TRANslation, was introduced in 1957.
Business applications usually deal in whole numbers, representing inventory quantities, for example, dollars and cents data accurate to only two decimal places. These applications require simpler mathematical calculations than are needed for scientific applications. The outputs required from business programs frequently consists of report containing extensive columns of neatly formatted dollars and cents numbers and totals. For these applications the COBOL programming language, with its picture output formats, is an ideal language. COBOL, which was commercially introduced in the 1960s, stands for COmmon Business Oriented Language.   

Types of Programming Language
Programming languages are classified mainly in two categories on the basis of creating instruction.
v Low level language
v High level language

Low level language
These are much closer to hardware. Before creating a program in low level language it is required to have through knowledge of the hardware. A program cannot be run on different hardware. Low level languages are specific to hardware but they run faster compare to high level language. Low level language is also divided in two types.
v Machine language
v Assembly language

Machine language
Machine language is also known as binary language is the only language a machine or computer can understand. Why? Because, a computer is an electronic machine, it can feel only electricity. It cannot understand human languages. So computer can understand a language which is directly related to electricity. Binary language consists of only two digits (0 and 1), is directly related to electricity where 0 represent low voltage and 1 represent high voltage. While easily understood by computers, machine languages are almost impossible for humans to write. Early computers were programmed using machine language. Programs written in machine language are faster and efficient. Writing program in machine language is very tedious, time consuming, difficult to find bugs in longer programs.

Assembly language
To overcome the difficulties of programming in machine language assembly language was developed. An assembly language contains the same instructions as a machine language, but each instruction has a symbol instead of just numbers. These symbols are called mnemonic or opcode. For example if 10111001 is the number to add two numbers, ADD could be used to replace it. After developing assembly language, it was easier to program using symbol instead of numbers. But the program written in assembly language must be converted to machine language which could be done by assembler. Each type of CPU has its own machine language and assembly language instruction. So an assembly language program written for one type of CPU won’t run on another. This shows that assembly language is also machine dependent and time consuming. 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.

High level language
The languages are called high level language if their syntax is closer to human language. High level languages were developed to make programming easier. Most of the high level languages are English like languages. They use familiar English words, special symbols (!, &, # etc), and mathematical symbols (+, - , * % etc) in their syntax. Therefore high level languages are easier to read, write, understand and programming, which is the main advantage of high level language over low level language. Each high level language has their own set of grammar and rules to represent set of instructions. Programming language such as C, C++, C#, Java, FORTRAN, BASIC, Pascal, Lisp, Python, PHP, Ruby, Perl, R are some examples of high level language. These enable a programmer to write programs that are more or less independent of a particular type of computer. Like assembly language programs, programs written in a high-level language also need to be translated into machine language. This can be done either by a compiler or an interpreter.

Assembler, Compiler and Interpreter
A computer will not understand any program written in a language, other than machine language. The program written in other languages is called source program and must be translated into machine language, which is called an object program. A translator is required for such translation. There are three types of translator programs.
Translators are as follows.
v Assembler
v Compiler
v Interpreter

Assembler
A program which translate assembly language program into a machine language is called an assembler. If an assembler which run on a computer and produce the machine code for the same computer then it is called self assembler or resident assembler. If an assembler that run on a computer and produce the machine code for other computer then it is called Cross Assembler. Assembler checks each instruction for its correctness and generates diagnostic messages, if there are mistakes in the program.

Compiler
It is a program which translates a high level language program into a machine language program. The program which is to be translated is called source program and after translation the object code is generated. The source program is input to the compiler. The object code is output for the secondary storage device. The entire program will be read by the compiler first and generates the object code.  A compiler is more intelligent than an assembler. It checks all kinds of limits, ranges, errors etc. But it takes more time to run and occupies a larger part of the memory. It has slow speed.

Interpreter
An interpreter is a program which translates statements of a program into machine code. Unlike compiler interpreter translates only one statement of the program at a time. It reads only one statement of a program, translate it and execute it. Then it reads the next statement of the program again translate it and execute it. In this way it produces further till all the statements are translate and execute. On the other hand, a compiler goes through the entire program and then translates the entire program into machine codes. A compiler is 5 to 25 times faster than interpreter.

By the complier, the machine codes are saved permanently for future reference. On the other hand, the machine codes produced by interpreter are not saved. An interpreter is a small program compare to compiler. It occupies less memory space, so it can be used in a system which has limited memory space.

No comments:

Post a Comment