Monday, May 10, 2010

PROGRAMMING LANGUAGES


The earlier first section was Binary numbers. Some people said that I ought to reduce the math in this tutorial and I felt that perhaps I should start off differently. And so I've altered the sequence of sections in this first unit.
Recap of important computer concepts:
When we talk of computers, we refer to ‘hardware’ and ‘software’. All the physical components like monitor, keyboard, mouse, modem, printer etc. fall under the hardware category. We need computers to do something useful for us but computers aren’t smart enough to know what we want them to do (at least not yet!). We need to explicitly tell the computer our requirements in the form of instructions. A set of instructions for doing something useful forms a ‘program’. And we refer to these programs as software (i.e. unlike hardware, software is something that we can’t touch and feel). 
Major hardware parts in a computer: 
1.       Input and Output devices: Computer can receive input from input devices (like a keyboard, mouse or a scanner). Output devices are used by the computer to send out information to the user; example: monitor, printer, plotter etc.
2.       Arithmetic and Logical Unit (ALU): As the name implies this unit is responsible for all arithmetic calculations. It is part of the central processing unit.
3.       Memory: When our computer wants to work on some information, it will require some place where it can store data; where it can store the instructions; where it can store intermediate results of operations etc. Memory serves this purpose and there are different types of memory (for different requirements):
            Primary memory: This memory can be quickly accessed by the computer (in technical jargon we say that this memory has low access time; i.e. time taken to access data in primary memory is less). Generally, instructions and data needed by the computer immediately for processing are placed in primary memory. Data in primary memory is not permanent. Each time we restart the computer, the memory would get refreshed.
            Secondary memory/ storage: This is the place where we store all our data. It’s a long-term storage device (like a hard-disk). Access times are higher but secondary memory is cheaper than primary memory.  

CPU (Central Processing Unit):
            We’ve seen computer parts to get input, store information, display output and also to perform calculations. But there needs to be someone at a higher level to control the individual units; someone to decide when to capture the input, when to send output information to the monitor etc. The CPU takes up this responsibility and is termed the ‘brain’ of the computer. The CPU is also called the processor (a microprocessor chip).

The language computers understand:
We have a lot of languages in this world but all computers can understand only binary language. The vocabulary is very simple and small; it consists of only 2 things: 0 and 1. This is all that a computer understands. (Humans are comfortable with the decimal system - consisting of the numbers 0 to 9). We’ll look at the binary system later in this chapter.  
Remember: A computer finally needs everything in binary language (instructions and data).
Programming Languages:
Programs are written to tell the computer to do something useful for us. It might be as simple a task as adding two numbers or as complex as transferring data between 2 computers in a network.
There are several reasons why we need programs. Imagine searching through a stack of papers to search for some telephone bill. Imagine a company maintaining its accounts (expenses and income on a day-to-day basis) - if this was done using the traditional file and paper method, someone would have to keep entering all the details in sheets of paper and then stack them into files. If, in future, someone wants to find out when a particular product was sold they would have to manually read through each and every paper in each and every file. Computers can be programmed to perform such tasks and they will do it faster. Basically, the computer is very good in performing repetitive tasks. One point to note: man created computers and man programs computers to perform certain tasks. A program is a set of instructions that can be executed by the computer. The computer will obediently follow whatever the programmer instructs it to do (as long as it understands the instructions). The downside to this is that the computer does not have any special intelligence; it is only as intelligent as it is programmed to be. For instance, a robot can be programmed to walk. If it is not programmed to detect obstacles, the robot will simply bang into obstacles because it does not have the intelligence to recognize and avoid obstacles. If the programmer provides such provisions, then the robot will be able to handle such scenarios.
With many software programs already existing, you may wonder why do we need more software; why not just buy and use what already exists? Software is usually not custom designed for the requirements of a particular company and you may not even have software for your own special requirement. For example, dentists never used to have any software specifically for their use but now you can see a range of dental software (the dentist can maintain details of each of his patients’ tooth in the computer). Programs needn’t be as complicated as dental software; you may want to have a little software to calculate your CGPA or to calculate your rank in class. To perform such tasks a programmer has to write a program (or a set of instructions). These instructions are written in a specific programming language and the programmer can chose to write the instruction in any one of the available languages.
Evolution of Programming Languages:
Any programming language can be categorized into one of the following categories:
·         High Level
·         Middle Level
·         Low Level (machine and assembly languages)
Middle level languages are sometimes clubbed together under the category of high-level languages.

Machine Level Languages:
A computer has a processor and if we want the computer to do something then we need to direct instructions at the processor. The problem is that computers can understand only binary language (i.e. the language which comprises of only 1s and 0s). All instructions to the processor should be in binary and so a programmer can write programs using a series of 1s and 0s. Every processor will understand only some instructions (this depends on how the processor was designed). An instruction to increment a variable might be:
110110100011101
Imagine having 100 such instructions in a program! The advantage is that no conversion (or translation) is needed because the computer can understand the 1s and 0s. This is called machine level language and this was used at the time computers came into existence.
The drawbacks are quite clear. By using machine language writing programs is very tedious and also prone to error (even if one bit is wrong, the entire program functionality could get altered). Trying to identify the error will also be a very tedious job (imagine reading a series of 1’s and 0’s trying to locate the mistake).
Assembly Languages:
Since it is very difficult for us to write instructions in binary language, assembly languages were developed. Instead of using a set of 1s and 0s for a particular instruction, the programmer could use some short abbreviations (called ‘mnemonics’) to write the program (for example: ADD is a mnemonic to add two numbers). Every processor has an instruction set that describes the various commands that the processor can understand. A normal instruction set will have instructions like JMP (jump), ADD (for addition) and so on. A programmer will write the program using these instructions and an assembler will convert the mnemonics into binary form so that the processor can understand it. The problem is that assembly level languages are specific to each processor. For example the 8085 (the simplest microprocessor) has an instruction set different from the 8086 microprocessor. Thus you would have to rewrite the program for each microprocessor. Another problem with assembly level programming is that the programmer needs to know details about the processor’s architecture such as the internal registers where values can be stored, how many internal registers are available for use etc.
Low level languages are very close to the hardware but difficult for writing programs.
High Level Languages:
Writing larger programs in assembly language is quite difficult and hence, high-level languages were developed (like BASIC). These languages were not close to the actual computer hardware but were very close to the English language. They tried to simplify the process of programming. In these languages the programmer needn’t worry about internal registers and processor architecture; instructions could be typed in almost normal English. The English-like instructions had to be converted to machine language using a compiler. One simple example of an English like command in COBOL is:
ADD incentive TO basic GIVING salary.
The instruction is quite self-explanatory (Add ‘incentive’ and ‘basic’ and store the result in ‘salary’). COBOL is also a high-level language.
                As programs grew larger (for example: maintaining a record of all employees, accounts maintenance etc.), even high level languages had certain drawbacks. These languages are also referred to as unstructured form of programming. The reason they are unstructured is because when a large program is written, it becomes very difficult to analyze the program at a later date (by someone else or even by the original programmer himself). There are many reasons for this; one is the use of statements like GOTO in high-level languages. In any program some tasks will either be performed repetitively or the programmer might want the program to execute a different set of instructions if some condition is satisfied. For example in a division program, in case the denominator is 0 then the program should not divide the two numbers; instead it should display an error message. Only if the denominator is not 0 should the program divide the two numbers. This kind of programming is referred to as program flow control. In a larger program there could be various other possibilities and all this was dealt with by using the GOTO statement. If you’ve used BASIC you will be aware that for every instruction that you type, you have to specify a line number (example 10,20,30 and so on). GOTO will be followed by some line number (indicating the instruction that has to be executed next. Ex: 1020 GOTO 50 means that now you want the program flow to go to line number 50).
                The problem with this is that in a large program it will become very difficult for anyone to understand the program logic. Imagine reading through 100 lines and then finding one GOTO statement to the 200th line. Then on the 205th line there could be another GOTO statement directing you to the 150th line. This should make it clear as to what is meant by the term ‘unstructured’. This is a major problem with high level languages. Another fact is that high level languages are very far away from the actual hardware. Examples of high-level languages are BASIC, Fortran (Formula Translation), COBOL (Common Business Oriented Language) and LIST (List processing).
Thus to take advantage of high level and low level languages, middle level languages like C and C++ were developed. They were easy to use and tried to retain the advantages of low level languages (i.e. being closer to the architecture).

Object oriented programming VS Procedural programming

Programming had many revolutions in it’s history. In the beginning it was something only for computer engineers. In order to program we need to turn on or off a lot of switches. And even after that hard work we cold only do some simple math equation. The first compilers and text editors made programming look like we know it.




Revolutions in computer programming are the product of crisis in computer industry. Â Hardware is always better and better and when people buy new computers they expect from it to do lot more then previous generations. That makes pressure on programmers to make better programs and that leads to crisis. Like the crisis which led to birth of object oriented programming.



Procedural programming

Procedural programming was born before 30-40 years but it is still popular. Many very popular programming languages like C, Visual Basic and Pascal are procedural programming languages. Many of them are popular because they are easy to learn and are easy way to come in programming world. Pascal and Visual Basic are representing this part of programming world.



First of all don’t think that you can program something only in object oriented languages or that there is something that is only possible to do in procedural programming languages. There is none problem that can not be solved in both object oriented and procedural languages. Example: Linux kernel is very complex collection of programmes and services and it’s done in c (procedural) and microsoft office is done in Visual C++. So even complex programs can be done in procedural languages.



Procedural languages are in many cases easier to learn and easier to use. For all of you who are now starting to dive in programming world i would recommend to use C or Pascal. C is a little bit harder to learn but i recommend it because it’s a good start point before you start to learn C++ which i heighley prefer. Pascal is also good and later you can start with Delphi, object oriented version of Pascal, but Pascal and Delphi tools are commercial and don’t have Linux versions.



As i already written above procedural languages are good as starting point and are maybe better for some smaller project but it is not a rule some small programs can be easily done also in object oriented.



Object oriented programming

The object oriented programming is a newest methodology in programming. In short words it has classes in which you can incorporate a lot of functions and variables that are common for some  part. They can have parents and children and by that share some of it’s properties.



Object oriented programming is much more complicated than procedural programming. But it has many good attributes: Â code is much more synoptic, that means that its easy to have many people working on the code without getting confused, it’s easier to change some part of the code without screwing anything. There is also one very important point in object oriented programming and that is software reuse. Classes are included in modules and modules can be added to new programs you write. So if you really want to be a serious programmer you need to learn some object oriented and that is C++.



You can start to learn C++ even if you are a beginner but you need some good literature plenty of time and good examples.

introduction to programming

Introduction to Programming


A program is a set of instructions that tell the computer to do various things; sometimes the instruction it has to perform depends on what happened when it performed a previous instruction. This section gives an overview of the two main ways in which you can give these instructions, or “commands” as they are usually called. One way uses an interpreter, the other a compiler. As human languages are too difficult for a computer to understand in an unambiguous way, commands are usually written in one or other languages specially designed for the purpose

Interpreters

With an interpreter, the language comes as an environment, where you type in commands at a prompt and the environment executes them for you. For more complicated programs, you can type the commands into a file and get the interpreter to load the file and execute the commands in it. If anything goes wrong, many interpreters will drop you into a debugger to help you track down the problem.

The advantage of this is that you can see the results of your commands immediately, and mistakes can be corrected readily. The biggest disadvantage comes when you want to share your programs with someone. They must have the same interpreter, or you must have some way of giving it to them, and they need to understand how to use it. Also users may not appreciate being thrown into a debugger if they press the wrong key! From a performance point of view, interpreters can use up a lot of memory, and generally do not generate code as efficiently as compilers.

In my opinion, interpreted languages are the best way to start if you have not done any programming before. This kind of environment is typically found with languages like Lisp, Smalltalk, Perl and Basic. It could also be argued that the UNIX® shell (sh, csh) is itself an interpreter, and many people do in fact write shell “scripts” to help with various “housekeeping” tasks on their machine. Indeed, part of the original UNIX philosophy was to provide lots of small utility programs that could be linked together in shell scripts to perform useful tasks.

Compilers
Compilers are rather different. First of all, you write your code in a file (or files) using an editor. You then run the compiler and see if it accepts your program. If it did not compile, grit your teeth and go back to the editor; if it did compile and gave you a program, you can run it either at a shell command prompt or in a debugger to see if it works properly. [1]

Obviously, this is not quite as direct as using an interpreter. However it allows you to do a lot of things which are very difficult or even impossible with an interpreter, such as writing code which interacts closely with the operating system--or even writing your own operating system! It is also useful if you need to write very efficient code, as the compiler can take its time and optimize the code, which would not be acceptable in an interpreter. Moreover, distributing a program written for a compiler is usually more straightforward than one written for an interpreter--you can just give them a copy of the executable, assuming they have the same operating system as you.

Compiled languages include Pascal, C and C++. C and C++ are rather unforgiving languages, and best suited to more experienced programmers; Pascal, on the other hand, was designed as an educational language, and is quite a good language to start with. FreeBSD does not include Pascal support in the base system, but both GNU Pascal Compiler (GPC) and the Free Pascal Compiler are available in the Ports Collection as lang/gpc and lang/fpc.

As the edit-compile-run-debug cycle is rather tedious when using separate programs, many commercial compiler makers have produced Integrated Development Environments (IDEs for short). FreeBSD does not include an IDE in the base system, but devel/kdevelop is available in the Ports Collection and many use Emacs for this purpose

Computer Programming & Languages

Computer Programming & Languages


Computer programming & programming languages. Computer programmers develop programs, definable as sequences of instructions, telling how to operate the computer. Without programs, computer hardware is virtually useless. Operating systems process input/output requests, run applications, and connect the individual computer to a network. Applications do specific tasks such as word processing, payrolls creation, mechanic design, and more. Programs must be written in detail, aptly named a programming language. Elementary processes are low-level languages, extensive capabilities in programs require a high-level language. Programming consists of requirements definitions, design specification, coding, testing, and maintenance. Each step of the program must be calculated carefully to perform that particular function.

Types of operating Systems

An operating system is a software component of a computer system that is responsible for the management of various activities of the computer and the sharing of computer resources. It hosts the several applications that run on a computer and handles the operations of computer hardware. Users and application programs access the services offered by the operating systems, by means of system calls and application programming interfaces. Users interact with operating systems through Command Line Interfaces (CLIs) or Graphical User Interfaces known as GUIs. In short, operating system enables user interaction with computer systems by acting as an interface between users or application programs and the computer hardware. Here is an overview of the different types of operating systems.




Real-time Operating System: It is a multitasking operating system that aims at executing real-time applications. Real-time operating systems often use specialized scheduling algorithms so that they can achieve a deterministic nature of behavior. The main object of real-time operating systems is their quick and predictable response to events. They either have an event-driven or a time-sharing design. An event-driven system switches between tasks based of their priorities while time-sharing operating systems switch tasks based on clock interrupts.



Multi-user and Single-user Operating Systems: The operating systems of this type allow a multiple users to access a computer system concurrently. Time-sharing system can be classified as multi-user systems as they enable a multiple user access to a computer through the sharing of time. Single-user operating systems, as opposed to a multi-user operating system, are usable by a single user at a time. Being able to have multiple accounts on a Windows operating system does not make it a multi-user system. Rather, only the network administrator is the real user. But for a Unix-like operating system, it is possible for two users to login at a time and this capability of the OS makes it a multi-user operating system.



Multi-tasking and Single-tasking Operating Systems: When a single program is allowed to run at a time, the system is grouped under a single-tasking system, while in case the operating system allows the execution of multiple tasks at one time, it is classified as a multi-tasking operating system. Multi-tasking can be of two types namely, pre-emptive or co-operative. In pre-emptive multitasking, the operating system slices the CPU time and dedicates one slot to each of the programs. Unix-like operating systems such as Solaris and Linux support pre-emptive multitasking. Cooperative multitasking is achieved by relying on each process to give time to the other processes in a defined manner. MS Windows prior to Windows 95 used to support cooperative multitasking.



Distributed Operating System: An operating system that manages a group of independent computers and makes them appear to be a single computer is known as a distributed operating system. The development of networked computers that could be linked and communicate with each other, gave rise to distributed computing. Distributed computations are carried out on more than one machine. When computers in a group work in cooperation, they make a distributed system.



Embedded System: The operating systems designed for being used in embedded computer systems are known as embedded operating systems. They are designed to operate on small machines like PDAs with less autonomy. They are able to operate with a limited number of resources. They are very compact and extremely efficient by design. Windows CE, FreeBSD and Minix 3 are some examples of embedded operating systems.



The operating systems thus contribute to the simplification of the human interaction with the computer hardware. They are responsible for linking application programs with the hardware, thus achieving an easy user access to the computers.

OPERATING SYSTEM

OPERATING SYSTEM (OS):-

The most important program that runs on a computer. Every general-purpose computer must have an operating system to run other programs. Operating systems perform basic tasks, such as recognizing input from the keyboard, sending output to the display screen, keeping track of files and directories on the disk, and controlling peripheral devices such as disk drives and printers.


For large systems, the operating system has even greater responsibilities and powers. It is like a traffic cop -- it makes sure that different programs and users running at the same time do not interfere with each other. The operating system is also responsible for security, ensuring that unauthorized users do not access the system.



Operating systems can be classified as follows:



multi-user : Allows two or more users to run programs at the same time. Some operating systems permit hundreds or even thousands of concurrent users.

multiprocessing : Supports running a program on more than one CPU.

multitasking : Allows more than one program to run concurrently.

multithreading : Allows different parts of a single program to run concurrently.

real time: Responds to input instantly. General-purpose operating systems, such as DOS and UNIX, are not real-time.

Operating systems provide a software platform on top of which other programs, called application programs, can run. The application programs must be written to run on top of a particular operating system. Your choice of operating system, therefore, determines to a great extent the applications you can run. For PCs, the most popular operating systems are DOS, OS/2, and Windows, but others are available, such as Linux.



As a user, you normally interact with the operating system through a set of commands. For example, the DOS operating system contains commands such as COPY and RENAME for copying files and changing the names of files, respectively. The commands are accepted and executed by a part of the operating system called the command processor or command line interpreter. Graphical user interfaces allow you to enter commands by pointing and clicking at objects that appear on the screen

System and application software

SYSTEM:-

(1) A group of interdependent items that interact regularly to perform a task.


(2) An established or organized procedure; a method.

(3) A computer system refers to the hardware and software components that run a computer or computers.

(4) An information system is a system that collects and stores data.

(5) On Macintoshes, System is short for System file, an essential program that runs whenever you start up a Macintosh. The System provides information to all other applications that run on a Macintosh. The System and Finder programs together make up the Mac OS.

(6) System often simply refers to the operating system.

 
APPLICATION SOFTWARE:-