Good Programming Practice Flashcards

1
Q

What are the aims of good programming practice?

A

Good programming practice is important to use to:

  • Ensure the clarity of the code and facilitate code review.
  • Minimise the need for code maintenance by robust programming
  • Minimise the development effort by development and re-use of standard code and by use of dynamic (easily acceptable) code.
  • Minimise the resources needed at execution time (improve efficiency of the code).
  • Reduce the risk of logical errors.
  • Meet regulatory requirements.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are coding best practices?

A

A set of informal rules that the software development community has learned over time which can help improve the quality of software.

Many computer programs remain in use for far longer than the original authors ever envisaged (sometimes 40 years or more), so any rules need to facilitate both initial development and subsequent maintenance and enhancement by people other than the original authors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the prerequisites which should be completed before coding starts?

A

Prerequisites should cover

  • How the development is structured (i.e. life cycle)?
  • What the software is meant to do? (requirements)
  • The overall structure of the software system (architecture)
  • More detailed design of individual components (design)
  • Choice of programming language(s)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the standards which should be adhered to when coding?

A
  • Know what the code block must perform
  • Maintain naming conventions which are uniform throughout.
  • Indicate a brief description of what a variable is for (reference to commenting)
  • Correct errors as they occur.
  • Keep your code simple
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What should be considered when using commenting?

A

Due to time restrictions or enthusiastic programmers who want immediate results for their code, commenting of code often takes a back seat. Programmers working as a team have found it better to leave comments behind since coding usually follows cycles, or more than one person may work on a particular module. However, some commenting can decrease the cost of knowledge transfer between developers working on the same module.

In the early days of computing, one commenting practice was to leave a brief description of the following:

Name of the module
Purpose of the Module
Description of the Module
Original Author
Modifications
Authors who modified code with a description on why it was modified.

The “description of the module” should be as brief as possible but without sacrificing clarity and comprehensiveness.

However, the last two items have largely been obsoleted by the advent of revision control systems. Modifications and their authorship can be reliably tracked by using such tools rather than by using comments. (i.e. GIT)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is naming convention?

A

Use of proper naming conventions is considered good practice. Sometimes programmers tend to use X1, Y1, etc. as variables and forget to replace them with meaningful ones, causing confusion.

In order to prevent this waste of time, it is usually considered good practice to use descriptive names in the code since it’s about real data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When writing the code, what step is made to help anyone working on the code in the future and therefore aid maintenance.

A

Keep the code simple

The code that a programmer writes should be simple. Complicated logic for achieving a simple thing should be kept to a minimum since the code might be modified by another programmer in the future. The logic one programmer implemented may not make perfect sense to another. So, always keep the code as simple as possible

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can you make code ‘portable’?

A

Program code should not contain “hard-coded” (literal) values referring to environmental parameters, such as absolute file paths, file names, user names, host names, IP addresses, URLs, UDP/TCP ports. Otherwise the application will not run on a host that has a different design than anticipated. A careful programmer can parametrize such variables and configure them for the hosting environment outside of the application proper (for example in property files, on an application server, or even in a database). Compare the mantra of a “single point of definition”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the steps which should be carried out as part of code development?

A
  • Code building
  • Debugging the code and correcting errors
  • Deployment
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is code refactoring?

A

When you “refactor,” you make changes to the code without changing any of its functionality. You can think of it like a “clean up,” for the sake of improving readability and quality.

This doesn’t include bug fixes or the addition of any new functionality. You might refactor code that you have written the day before, while it’s still fresh in your head, so that it is more readable and reusable when you may potentially look at it two months from now. As the motto says: “refactor early, refactor often.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly