Monday, March 26, 2012

Programming Languages

So, what exactly is a programming language? As a loose definition, a programming language is a tool used by a programmer to give the computer very specific instructions in order to serve some purpose for the user. A program is like a recipe. It outlines exactly the steps needed to create something or perform a certain task. For, example, when baking chocolate chip cookies, there are certain steps that need to be followed:
mix eggs, butter, sugar in a bowl
add flour, baking soda, and flavorings
mix until creamy
add chocolate chips
bake in the oven.
For a person who has made cookies before and knows the amounts of each ingredient to use, this recipe is sufficient, however, for a person who has never baked cookies before, this recipe will not do. That person would need a recipe like the following:
place two eggs in a bowl
add 1.5 c. butter to the eggs
...
bake cookies for 10-12 minutes at 375 degrees or until brown
There is still a problem with the preceding recipe. The first instruction says to put two eggs in the bowl, but it doesn't say to shell them first! This may seem like common sense, but it illustrates a fundamental concept: computers do exactly what they are told, no more, no less. When writing a program, a programmer must outline every possible step and scenario that could occur.
The first programming languages that emerged, were assembly languages. These languages are exactly the instruction set of a specific processor. These languages are very low-level and hard to understand. For example, say we wanted to add two numbers, 3 and 4 and get a result:
in C++: in assembly:
int a = 3 + 4;
ldl  3, R1
ldl  4, R2
addl R1, R2, R3
The version in C++ is easier to understand and simpler to write. This is analagous to the differences in the first recipe presented and the second recipe presented. The first recipe expressed the method of baking cookies on a high level, while the second method went more in depth on how to actually mix and bake the cookies. Programmers write their code in a high level language and then use a compiler to translate their code into an assembly language and then into a machine language that will run on the machine they are using.
Programs consist of algorithms. An algorithm is just a well-outlined method for completing a task. The above recipes could be called algorithms for the task of baking cookies. A high level algorithm for adding two numbers could be as follows:
ask the user for the first number
ask the user for the second number
add the two numbers
display the result on the screen
This high-level abstraction is not actual code. However, it does express the ideas of a program, and is called pseudo-code. Often, programmers will design their programs in pseudo-code, and then use this to write their actual code.
So, why is there more than one programming language? It may seem that a standard language should be agreed on, since all languages are translated using a compiler anyways. However, languages are often designed with a specific use in mind, and some are better than others for dealing with certain problems. So if a programmer is capable of writing a compiler (which is a very complex piece of software) then they can design and create a language.
The most important thing to remember about programming languages is that they are only an abstraction! Programming languages were created so developers could express their ideas on a higher level than a computer can understand. Once a user has a good concept of how computers work, and has learned a few computer languages, it becomes much easier to pick up new languages.
A programming language is a tool used by programmers in order to specifically outline a series of steps that a computer is to take in a certain instance. High-level programming languages allow a programmer to express ideas on an abstract level, and forces the compiler to worry about the low-level implementation details. This allows for faster development of applications, since applications are easier to write. There are even fourth generation languages emerging as viable programming languages. Recall that machine code is considered first generation, assembly languages are second generation, compiled languages are third generation. Fourth generation languages are actually code-generating environments, such as Microsoft's Visual Basic. These fourth generation languages allow programmers to express their ideas visually, and the environment then writes the code to implement these ideas.

No comments:

Post a Comment