What is Programming Language

9
1. What is Programming Language  A programming language is a computer language programmers use to develop applications, scripts , or other set of instructions for a computer to execute.  A programming language is an artificial  language  designed to communicate  instructions  to a machine, particularly a computer. Programming languages can be used to create programs  that control the behavior of a machine and/or to express  algorithms  precisely.  2. Types of Programming Language The progression of computer programming languages was made possible by the programmer's search for efficient translation of human language into something that can be read and understood by computers. The languages generated, called machine code, have high levels of abstraction, which hide the computer hardware and make use of representations that are more convenient to programmers. As programs evolve and become more sophisticated, programmers found out that certain types of computer languages are easier to support. As expected in a dynamic discipline, there is no standard for categorizing the languages used in programming. There are, in fact, dozens of categories. One of the most basic ways to categorize the languages is through a programming paradigm, which gives the programmer's view of code execution. Among the languages classifications according to programming paradigm are:  Object-Oriented Programming Languages  Known as the newest and most powerful paradigms, object-oriented programming requires the designer to specify the data structures as well as the types of operations to be applied on those data structures. The pairing of data, and the operations that can be done on it is called an object. A program made using this language is therefore made up of a set of cooperating objects instead of an instructions list. The most famous object-oriented programming these days are C#, C , Visual Basic, Java, and Python.  Structured Programming Languages  An exceptional type of procedural programming, structured programming provides programmers with additional tools to handle the problems created by larger programs. When using this language, programmers are required to cut program structure into small

Transcript of What is Programming Language

Page 1: What is Programming Language

7/31/2019 What is Programming Language

http://slidepdf.com/reader/full/what-is-programming-language 1/9

1.  What is Programming Language

  A programming language is a computer language programmers use to develop

applications, scripts, or other set of instructions for a computer to execute.

 A programming language is an artificial language designed tocommunicate instructions to a machine, particularly a computer. Programming languages

can be used to create programs that control the behavior of a machine and/or to

express algorithms precisely. 

2.  Types of Programming Language

The progression of computer programming languages was made possible by the programmer's

search for efficient translation of human language into something that can be read and

understood by computers. The languages generated, called machine code, have high levels of 

abstraction, which hide the computer hardware and make use of representations that are more

convenient to programmers.

As programs evolve and become more sophisticated, programmers found out that certain types of 

computer languages are easier to support. As expected in a dynamic discipline, there is no

standard for categorizing the languages used in programming. There are, in fact, dozens of 

categories. One of the most basic ways to categorize the languages is through a programming

paradigm, which gives the programmer's view of code execution. Among the languages

classifications according to programming paradigm are:

  Object-Oriented Programming Languages 

Known as the newest and most powerful paradigms, object-oriented programming

requires the designer to specify the data structures as well as the types of operations to be

applied on those data structures. The pairing of data, and the operations that can be done

on it is called an object. A program made using this language is therefore made up of a

set of cooperating objects instead of an instructions list.

The most famous object-oriented programming these days are C#, C , Visual Basic,

Java, and Python.

  Structured Programming Languages 

An exceptional type of procedural programming, structured programming provides

programmers with additional tools to handle the problems created by larger programs.

When using this language, programmers are required to cut program structure into small

Page 2: What is Programming Language

7/31/2019 What is Programming Language

http://slidepdf.com/reader/full/what-is-programming-language 2/9

pieces of code that can easily be understood. Instead of using global variables, it employs

variables that are local to every subroutine. Among the popular features of structured

programming is that it doesn't accept GOTO statement which is usually associated with

the top-down approach. Such approach starts with an opening overview of the system

with minimal details about the various parts. To add these details, design iterations are

then included to complete the design.

Commonly used structured languages include C, Pascal, and ADA.

  Procedural Programming Languages 

Procedural Programming involves a list of operations the program needs to complete to

be able to attain the preferred state. It is a simple programming paradigm where every

program comes with a starting phase, a list of tasks and operations, and an ending stage.

Also called imperative programming, this approach comes with small sections of codethat perform certain functions. These sections are made up of procedures, subroutines, or

methods. A procedure is made up of a list of computations that should be done.

Procedural programming lets a part of the code to be used again without the need to make

several copies. It achieves this by dividing programmatic tasks into small sections.

Because of this, programmers are also capable of maintaining and understanding program

structure.

Among the known procedural languages are BASIC and FORTRAN.

3.  Program Design Techniques

  FLOW CHART

Step-form and pseudocode program designs are both text-based, the statements are

written. Flow charts are a graphical method of designing programs and once the rules are

learned are very easy to draw. A well-drawn flow chart is also very easy to read since it

basically uses just two symbols, two decision constructs. and two iteration constructs:  

  the sequence symbol,

  the decision symbol,

  the decision construct if ... then

  the decision construct if ... then ... else

  the repetition construct - repeat,

  the repetition construct - while,

Page 3: What is Programming Language

7/31/2019 What is Programming Language

http://slidepdf.com/reader/full/what-is-programming-language 3/9

there are other symbols but the real work is depicted by the two symbols and the constructs. This

shouldn't come as a surprise since in the step-form and pseudocode that is what you have beenlearning.

The language of flow charts

The major symbols are the DECISION (alsoknown as selection) and the SEQUENCE (or

process) symbols. The START and STOP symbols

are called the terminals. The SUBPROCESS

symbol is a variation on the sequence symbol.There are also connectors drawn between the

symbols and you will see these used in the

examples below. There is at least one other

sequence symbol which is used to representinput/output processes but I think it is unnecessary

so I don't use it.

There are some important rules concerning the symbols and these rules apply also to other ways

of stating algorithms:

  Processes have only one entry point and one exit point.

  Decisions have only one entry point, one TRUE exit point and one FALSE exit point.

Repeat loop. Note that the repeat loop has the process

preceding the decision. This means that a repeat loop willalways execute the process part at least once. This is an

important point to remember because it may not be what youwant to do. For instance assume you are a world power in

control of an arsenal of nuclear weapons and have written aprogram to launch missiles in the event of an attack. Your

program contains a loop which launches a missile each time

you are struck by an enemy missile, for example:

REPEAT

LAUNCH MISSILEUNTIL ENEMY STOPS

Is a repeat loop a good idea in this case? Probably not since, if we assume you are not under attack and you run the program, the repeat loop executes the

process at least once and you will probably start the next world war. A while loop would be a

safer and more humane choice

Page 4: What is Programming Language

7/31/2019 What is Programming Language

http://slidepdf.com/reader/full/what-is-programming-language 4/9

While loop. The while loop is basically the reverse of the

repeat loop, the decision comes first, followed by theprocess. The while loop is usually written so that it

iterates while the condition is true, the repeat

iterates until the condition becomes true. An interesting

question is: When should a repeat loop be used rather than awhile loop? and vice-versa. The while loop should be used

when it is possible that the process or processes which are in

the scope of the decision (that is, in the loop) may not needto execute. For example assume you have a designed an air-

conditioner controller program and the program turns on the

compressor while the ambient temperature is above thedesired temperature. A while loop is a good choice here

since the ambient temperature may be at the desired level

before the compressor part of the program is executed. If a

repeat loop was used then the compressor would be turned

on but it wouldn't be necessary. That would be wickedlyignorant of green sensitivities. A repeat loop would be a good candidate for the kind of situation

in which a program needs to check for an external event at least once. For example: assume youhave now written a program for a video cassete recorder and it has a menu for doing things like

tuning TV channels, setting the date and time, programming events and so on. When the menu is

displayed it is a QUIT option along with all the others, the VCR doesn't know which option willbe chosen so it stays in the menu mode, that is repeats it, until QUIT is selected.

The IF ... THEN construct is shown here and is

also known as the NULL ELSE, meaning that there is no ELSE part. I have use lines with arrow-heads (connectors) to indicate the flow of sequence. Although this is important in flow charts

once you have gained some skill in using them and if you draw them carefully you will find that

determining the sequence is straight forward. A typical rule is to use arrow-heads on connectors

where flow direction may not be obvious. 

Page 5: What is Programming Language

7/31/2019 What is Programming Language

http://slidepdf.com/reader/full/what-is-programming-language 5/9

 

The IF ... THEN ... ELSE ... construct has

a process at each branch of the decisionsymbol. The only difference here is that

each value of the decision

(TRUE/FALSE) has a process associatedwith it.

Using flow charts to design programs

With other topics I've explained the use of 

technique with an example. There is somethingof a precedent there. This flow chart example

uses all the symbols except the subprocess

symbol.

The algorithm sums all the even numbers

between 1 and 20 inclusive and then displays thesum. It uses a repeat loop and contains a null else

within the repeat loop.

The equivalent pseudocode is:

sum = 0count = 1

REPEAT

IF count is even THEN sum = sum + countcount = count + 1

UNTIL count > 20

DISPLAY sum

You can see quite clearly from this examplewhat the price of flow charting is. There is quite

a bit of drawing to do in addition to writing thelegend in the symbols. The pseudocode is quite

simple by comparison so why would you use

flow charts?

Page 6: What is Programming Language

7/31/2019 What is Programming Language

http://slidepdf.com/reader/full/what-is-programming-language 6/9

The major reasons are that the flow chart.

  is easier to read

  more closely follows a standard, this is not the the case with pseudocode

  probably lends itself more readily to computer-aided techniques of program design

Some rules for flow charts

Well-drawn flow charts are easy to read. What must you do to draw well-drawn flow charts?

Here are a few rules:

1.  Every flow chart has a START symbol and a STOP symbol2.  The flow of sequence is generally from the top of the page to the bottom of the page. This

can vary with loops which need to flow back to an entry point.

3.  Use arrow-heads on connectors where flow direction may not be obvious.

4.  There is only one flow chart per page

5. 

A page should have a page number and a title6.  A flow chart on one page should not break and jump to another page

7.  A flow chart should have no more than around 15 symbols (not including START and

STOP)

  ALGORITHMS

An algorithm is a sequence of precise instructions for solving a problem in a finite amount of 

time.

Properties of an Algorithm:

�It must be precise and unambiguous

�It must give the correct solution in all cases

�It must eventually end. Algorithms and Humans

Algorithms are not a natural way of stating a problem’s solution, because we do not normally 

state our plan of action.

�We tend to execute as we think about the problem. Hence, there are inherent

difficulties when writing an algorithm.

Page 7: What is Programming Language

7/31/2019 What is Programming Language

http://slidepdf.com/reader/full/what-is-programming-language 7/9

�We normally tailor our plans of action to the particular problem at hand and not to a

general problem (i.e. a nearsighted approach to problem solving)

�We usually do not write out our plan, because we are usually unaware of the basic

ideas we use to formulate the plan. We hardly think about it  – we just do it.

�Computer programmers need to adopt a scientific approach to problem solving, i.e.

writing algorithms that are comprehensive and precise.

�We need to be aware of the assumptions we make and of the initial conditions.

�Be careful not to overlook a step in the procedure just because it seems obvious.

�Remember, machines do not have judgment, intuition or common sense!

  PSEUDOCODE

Introduction 

Before developing an application it needs to be somehow designed - on a piece of paper, usingUML or just by creating a prototype. Another way to design the application logic is using

pseudo-code.

What is pseudo-code and how to use it? 

Pseudo-code is a non-formal language, a way to create a logical structure, describing the actions,

which will be executed by the application. Using pseudo-code, the developer describes theapplication logic using his native language, without applying the structural rules of a specific

programming language. The big plus of the pseudo-code is that the application logic can be

easily understood by any developer in the development team (in this case, it doesn’t depend,

which programming language knows each team member). Also, when the application algorithmis described in pseudo-code, it is very easy to transform the pseudo-code into real code (using

any programming language). For a better understanding of what is pseudo-code, let’s take a look 

at an example. Suppose that you have to develop an application, that gets the number of students

in a high school and then it gets each student’s final grade (100, 90, 80, 60 and 50) and processesthe average grade for the whole school. Instead of creating the program at a computer, let’s

describe the application logic using pseudo-code. First, I will describe the general purpose of the

Page 8: What is Programming Language

7/31/2019 What is Programming Language

http://slidepdf.com/reader/full/what-is-programming-language 8/9

application:

1 Process the average grade for the whole school

Now, I need to specify the fundamental actions that are needed to process the final result:  1 Request the number of students;

2 Get the grade for each student;

3 Process the average grade for the whole school;

This is a generalized description, but it describes the basic application logic. Now, I have to

specify some more details (how the above actions are performed):

01 Application start;

02 Declare an integer variable numberOfStudents;

03 Declare an integer variable counter;

04 Declare an integer variable sum;

05 Declare a decimal variable average;

06

07 Set the numberOfStudents value to 0;

08 Set the counter value to 0;

09 Set the sum value to 0;

10

11 Request the number of students (numberOfStudents);

12

13 If the entered number of students is 0 then

14 Exit the application

15 Else

16 While the counter is less or equal to the number of students

17 Get the student grade

18 Add the student grade to the sumvariable

19 Increment the counter by 1.20 Get the next student information

21

22When the student information is entered, setthe average variable to the result of the division

(sum divided by the number of students).

23 Show the result.

24 Application end.

Page 9: What is Programming Language

7/31/2019 What is Programming Language

http://slidepdf.com/reader/full/what-is-programming-language 9/9

 

As you see, human language is used to describe the application logic. Also, to better see the code

fragments, a specific indentation style is used, so we can easily see which part of the algorithm is

executing a specific action.

Some developers may think that using pseudo-code to design the application instead of creating

and testing the application on the computer is a waste of time. This is true for small modules, that

were created many times and which require just some small modifications to accomplish aspecific task, but when it comes to large projects, it’s pretty easy to be lost in the hundreds or even thousands of code lines. In this case, the pseudo-code clearly describes the application

algorithms, so these can be easily implemented and it gives the developer an opportunity to think on the algorithm before implementing it.