ArticleslgStudy

computer science

Coding best practices

Coding best practices is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Coding best practices rather than just read about it. In short: 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 ori…

Key takeaways

  • Coding best practices belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Coding best practices to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Coding best practices from memory before moving on to harder problems.

Reference excerpt

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.

Worked examples

Example 1 — a first encounter with Coding best practices

Start with the simplest possible case. Write down what Coding best practices claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Coding best practices before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Coding best practices ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Coding best practices

In research
Coding best practices appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Coding best practices in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Coding best practices is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer programming, Software development process, so understanding it makes those chapters shorter.
In everyday life
Look for Coding best practices outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Coding best practices” →

How to study Coding best practices in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Coding best practices means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Coding best practices out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Coding best practices in simple terms?

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…

Why does Coding best practices matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Coding best practices?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Coding best practices.

Tags

  • Computer programming
  • Software development process

Keep exploring