You are on page 1of 2

CODING GUIDELINES AND TESTING-DEBUGGING TECHNIQUES

LEARNING CONTENTS (C++ GENERAL CODING GUIDELINES)

Code Organization and Style

- The first rule we need to remember is the “use of common sense”.


- Common sense is required eve when rules and guidelines do not exist.

we are going to improve the code readability of our code through:

 Appropriate use of whitespaces

Whitespaces are ignored by the compiler, so it does not affect our codes, but affect how we read our codes.

 Use a small, consistent indentation style

Code block delimiters (curly braces, { }) should be vertically aligned. Statements inside the code block shall be
indented.

The opening and closing curly braces ({ }) are vertically aligned specifying that they are inside the function body
of main(). Also, statements inside the code block are indented uniformly to specify that they are within the
function.

 Use comments

Comments should be used to complement the source codes. Do not put on comments on those things that are
obvious, duplicating the language syntax. Also, it is not necessary to comment on each statement. Well chosen
identifiers and the use of self-documenting code generally eliminates the need for comments on some parts of
your code.

The use of a comment in this code is not necessary in this case, it just duplicates the language syntax.

However, the code presented can be further improved.

 Use clear, legible, meaningful names

Better to choose names from a usage perspective. The identifiers should explain themselves what they are. For
example, if you need a variable to store age, better to use “age” as an identifier.

LEARNING CONTENTS (CODE ERRORS)

Syntax Errors

- refers to the grammatical rules of a language, be it a natural language such as English or a


programming language such as C++.
- a syntax error is a violation of the language’s syntax.
- a syntax error occurs not in the line flagged by the compiler but in some line above that line or the
previous line. Thus, check the surrounding lines where the line is flagged by the compiler to have a
syntax error.
Some other common syntax errors are:

 Undeclared variable name


 Unmatched parentheses
 Unterminated strings (unmatched double quotes)
 Unterminated character (unmatched single quotes)

Semantic Errors

- refers to meaning in the language.


- a semantic error is a violation of the rules of the meaning of the language.
- Semantic errors are harder to find than syntax errors because the compiler cannot detect
semantic errors.
- The compiler will still compile the source code into executable code even with semantic
errors.

LEARNING CONTENTS (TESTING AND DEBUGGING TECHNIQUES)

Software Bug

- a problem in the source code that causes the program to produce an incorrect or unexpected result.

Testing and Debugging Process

- When you have written a piece of code, it is important to test if it works correctly or not. If you find errors,
you need to debug it.

Debugging involves the following steps:

 Identify the problem


 Isolate the source of the problem
 Correct the problem

Use of Debugger

- another program that helps us in identifying how a program executes and examine the program state
while the program is running.
- We can use the debugger to execute a program line by line and examine the value of the variables.

Using breakpoints

- a code marker that tells the debugger to halt the execution of the program at the breakpoint.

Using Stepping

- stepping lets us execute our code line by line or statement by statement.

You might also like