Thomas Knapman- NAB 03
For a professional programmer to create consistently good quality code it takes time and a lot of practise. There are a number of errors and problems in writing programs that can only be learnt through experience.
For a professional programmer to create consistently good quality code it takes time and a lot of practise. There are a number of errors and problems in writing programs that can only be learnt through experience.
There are a number of attributes that help in the creation of well written code. The first attributes are reliability and robustness. A well-written robust program will be able to cope with a user error and display an error message instead of crashing. The optimum way to ensure a program is as robust as possible is by thoroughly testing it to ensure it works correctly, and can cope with being used correctly.
Another attribute of good quality code is usability. The best programs that are written are easy to use and intuitive. Each program that is written normal has its own subject of usability (called HCI- Human Computer Interface) but there are some features that are easily added when designing the user interface to make a program easier to use. Clearly labelled controls (that are arranged in the order they are likely to be used) and controls grouped by function all make easier for the programmer to work out how the program is to be used.
Portability is the ability of a program to run on different hardware or software platforms. This may be important for a number of systems. Some languages such as Java support many different types of hardware.
Maintainability is an important attribute in writing good quality code. Every commercial software product needs to be maintained with updates, bug fixes and new features. There are a number of techniques that can be used to make software easier to maintain, these include-
· Decent, detailed technical documentation describing the design and implementation of the software.
· Well-written programs have features such as adding comments, using meaningful variable names and indenting loop and selection instructions.
How to improve readability of code
Complex software. To help the readability of code programmers would add comments to the programming code they write. Comments are ignored by the system, but will make it easier for the programmer and anybody else who reads the code to understand. Adding comments is a important process during large projects, in particular during the maintenance phase, when bug fixes or modifications may need to be completed by someone other than the programmer who wrote the original code. Even adding comments to the program instructions fo projects will more than likely have standards set which the professional programmers on the project must followr small software developments is seen as good practise.
Another example of good practise which improves readability of code is indenting loop or selection blocks of code. This makes it easier to see where they start and finish. Some programs, such as Visual Basic does this for the user.
Here is an example of where comments have been added to a programming code (programming language is C)-
The basic program structures of sequence, selection and iteration
Sequence is a structure where there is a set path to get from the original starting point to the end result. The structure of sequence can be shown using an Activity Diagram. They are similar to flow charts, but are set out more clearly.
Selection is similar to sequence, although there are times when selection requires a logical test. This test must equate to either True or False, the flow of tasks then changes depending on which option has been chosen until the end output.
Iteration is a structure used when a section of code is needed to be repeated using a loop. Iteration requries a control variable and the initialisation of the control variable. Iteration normall contains a update of the control variable and a test against the ocntrol value.
Every variable on each programming language has a data type. This judges what type of data will be stored and the range of values that the variable will accept. Data types can also define how the data will be formatted when displayed.
Choosing the right data type for a variable is important. Wrong choices could result in excessive amounts of storage space being set aside. If a variable is unable to accomodate the size of value assigned to it, the system will crash.
If a data type needs to be used in more than one part of a program, then it is important the data type is consistent. Data that the user needs to do calculations with must be placed in a numeric data type such as interger or single. However, you must ensure that only numeric data gets placed in these variables, otherwise the porgram will crash.
Every variable on each programming language has a data type. This judges what type of data will be stored and the range of values that the variable will accept. Data types can also define how the data will be formatted when displayed.
Choosing the right data type for a variable is important. Wrong choices could result in excessive amounts of storage space being set aside. If a variable is unable to accomodate the size of value assigned to it, the system will crash.
If a data type needs to be used in more than one part of a program, then it is important the data type is consistent. Data that the user needs to do calculations with must be placed in a numeric data type such as interger or single. However, you must ensure that only numeric data gets placed in these variables, otherwise the porgram will crash.