




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































2
Therefore, in learning a programming language’s syntax and semantics, we look for the commands or statements that we will use to perform inputs, i.e., how to read in data into the computer via the keyboard, files, databases or any other source. We then learn the commands or statements to process the data, i.e., the process logic. Finally, we learn how to display our results as outputs to users of our programs. That is, how to display via the monitor, store results into a file or database and/ or send the results to other computing system(s).
4
Is Programming an Art or a Science or Both? Programming is on one hand an artistic or creative endeavour, and on other hand, a scientific endeavour. As a scientist, the programmer begins with a clearly defined set of principles, or axioms of programming. He or she then applies them systematically to a problem, in such a way that at any stage in the process the (mathematical) correctness of the program can be routinely demonstrated. For instance, in testing our programs and their designs, scientific approaches are usually employed. 5
Programming is both scientific and artistic These two philosophies of programming have some implications. The art of programming demands a variety of “tools” or a “programming environment” within which the total process of program development can take place. The science philosophy demands a language, which supports the axiomatic proof of program behaviour 7
Programming Environment The programming environment includes all the facilities and tools, which a programmer requires in the design, development, testing, implementation and maintenance of a system of programs. Thus, text editors, compilers, interpreters, diagnostic tools, optimizers, measurement tools and other aids comprise a complete programming environment. Apart from the tools mentioned as comprising the programming environment, the following are additional tools needed in programming: A previous knowledge of the pros and cons of programming languages syntax and semantics; Logical reasoning ability; and Algorithms and flow charts. 8
10
Illustration: suppose we want to add some numbers together continuously until when we encounter any negative data, which shall terminate the addition. In addition, we also want to report the total number of valid data added so far before the program halts. The Algorithm:
**1. Set up a counter, count = 0
Step 1. Analysis and understanding of the problem to be solved. This involves the following subtasks: (i)Having a basic understanding of the problem. If you don’t understand a problem, then you cannot solve it even with a computer. The problem we are solving should be well understood before we can write a meaningful functional program for it. (ii)Identification and designing of input data. All the data (variables) to be used in the program must be well analysed. What type(s) they are, in which format are they going to be, from which medium (keyboard, files in disks, etc) will they come from, etc. By types, we mean whether they are whole numbers (called integers), numbers with decimal points, for example 3. 6 (called Real), characters or texts. The data input could come from the keyboard, a file or some signals from other electronic systems. 4/30/ 13
(iii) Identification of any suitable solution model. If it is mathematics-based, is there any model formula for solving the problem? For instance, we have a formula for solving quadratic equations. Can you remember the ‘almighty formula’? We shall soon come to it. (iv) Identification and designing of outputs. We have to decide on their type(s), in which format they are going to be, from which medium (monitor, printer, files in disks, etc) will they be directed to, etc.
14
Step 6. Documenting the program. Documentation is very essential in programming. We have two types – internal and external. Internal documentation involves putting comments and white spaces in our program source codes. They are there to introduce the functionality of the program as well as to introduce the different sections of the code for readability and maintenance of the code. External documentation are in form of a manual for operating and maintaining the program by any user of the program. The user will specify the functionality of the program, inputs and their formats, expected outputs and their formats, operating instructions for the program, etc. To maintain any code, the documentation on the code will have to be consulted first.
16
Choose appropriate names for your variables. The names you use for your variables should be meaningful and suggest clearly the purpose of the variable. They should communicate what the variable is meant for at least. For example, Area_of_Rect suggests that the variable is for the area of a rectangle. For a program to work properly, it is of utmost importance to know exactly what each variable represents, and to know exactly what each subprograms must be included with their names chosen with care to identify their meanings clearly. 17
4/30/ 19
Modularize the program for easy maintenance. The program should be broken down into various functional units. This is achieved through the use of subroutines and functions in programs. Appropriate documentation formats such as comments and white spaces (blank lines) must be used in the program. The white spaces separate the program into logical functional sections for ease of debugging and maintenance. Test the program with different sets of data (both valid and invalid) to ascertain that the program is error-free.
20