Coding best practices or programming best practices are a set of informal, sometimes personal, rules (best practices) that many software developers, in computer programming follow to improve software quality. Many computer programs require being robust and reliable for long periods of time, so any rules need to facilitate both initial development and subsequent maintenance of source code by people other than the original authors. In the ninety–ninety rule, Tom Cargill explains why programming projects often run late: "The first 90% of the code takes the first 90% of the development time. The last 10% takes another 90% of the time." Any guidance which can redress this lack of foresight is worth considering. The size of a project or program has a significant effect on error rates, programmer productivity, and the amount of management needed.
Software quality
As listed below, there are many attributes associated with good software. Some of these can be mutually contradictory (e.g. being very fast versus performing extensive error checking), and different customers and participants may have different priorities. Weinberg provides an example of how different goals can have a dramatic effect on both effort required and efficiency. Furthermore, he notes that programmers will generally aim to achieve any explicit goals which may be set, probably at the expense of any other quality attributes. Sommerville has identified four generalized attributes which are not concerned with what a program does, but how well the program does it: Maintainability, dependability, efficiency and usability. Weinberg has identified four targets which a good program should meet:
Does a program meet its specification ("correct output for each possible input")? Is the program produced on schedule (and within budget)? How adaptable is the program to cope with changing requirements? Is the program efficient enough for the environment in which it is used? Hoare has identified seventeen objectives related to software quality, including:
Clear definition of purpose. Simplicity of use. Ruggedness (difficult to misuse, kind to errors). Early availability (delivered on time when needed). Reliability. Extensibility in the light of experience. Brevity. Efficiency (fast enough for the purpose to which it is put). Minimum cost to develop. Conformity to any relevant standards (including programming language-specific standards). Clear, accurate and precise user documents.
Prerequisites Before coding starts, it is important to ensure that all necessary prerequisites have been completed (or have at least progressed far enough to provide a solid foundation for coding). If the various prerequisites are not satisfied, then the software is likely to be unsatisfactory, even if it is completed. From Meek & Heath: "What happens before one gets to the coding stage is often of crucial importance to the success of the project." The prerequisites outlined below cover such matters as:
How is the development structured? (life cycle) What is the software meant to do? (requirements) What is the overall structure of the software system? (architecture) What is the detailed design of individual components? (design) What is the choice of programming language(s)? For small simple projects it may be feasible to combine architecture with design and adopt a very simple life cycle.
Life cycle
A software development methodology is a framework that is used to structure, plan, and control the life cycle of a software product. Common methodologies include waterfall, prototyping, iterative and incremental development, spiral development, agile software development, rapid application development, and extreme programming. The waterfall model is a sequential development approach; in particular, it assumes that the requirements can be completely defined at the start of a project. However, McConnell quotes three studies that indicate that, on average, requirements change by around 25% during a project. The other methodologies mentioned above all attempt to reduce the impact of such requirement changes, often by some form of step-wise, incremental, or iterative approach. Different methodologies may be appropriate for different development environments. Since its introduction in 2001, agile software development has grown in popularity, fueled by software developers seeking a more iterative, collaborative approach to software development.
Requirements
McConnell states: "The first prerequisite you need to fulfill before beginning construction is a clear statement of the problem the system is supposed to solve." Meek and Heath emphasise that a clear, complete, precise, and unambiguous written specification is the target to aim for. Note that it may not be possible to achieve this target, and the target is likely to change anyway (as mentioned in the previous section). Sommerville distinguishes between less detailed user requirements and more detailed system requirements. He also distinguishes between functional requirements (e.g. update a record) and non-functional requirements (e.g. response time must be less than 1 second).
Architecture
Hoare points out: "there are two ways of constructing a software design: one way is to make it so simple that there are obviously no deficiencies; the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." (Emphasis as in the original.) Software architecture is concerned with deciding what has to be done and which program component is going to do it (how something is done is left to the detailed design phase below). This is particularly important when a software system contains more than one program since it effectively defines the interface between these various programs. It should include some consideration of any user interfaces as well, without going into excessive detail. Any non-functional system requirements (response time, reliability, maintainability, etc.) need to be considered at this stage. The software architecture is also of interest to various stakeholders (sponsors, end-users, etc.) since it gives them a chance to check that their requirements can be met.
Design
… excerpt ends here. Continue reading the full article.