0% found this document useful (0 votes)
3 views

7.ICP - Preventing or fixing errors in structured programs.

Uploaded by

Leo Nembaware
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

7.ICP - Preventing or fixing errors in structured programs.

Uploaded by

Leo Nembaware
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Preventing or fixing errors in structured

programs
To prevent or resolve errors in structured programs,
programmers should consider using variable identifiers with
meaningful and consistent names, adding comments to explain
the code, following a clear flow of execution, and utilising
debugging techniques such as incremental program
development and backtracking. Moreover, by designing the
overall logic and structure of the program using tools like
flowcharts and pseudocode, programmers can minimise errors
and reduce debugging time. Additionally, handling exceptions
and using error codes can help prevent runtime errors.

-The key strategies to prevent or fix errors in structured


programs are:

Choosing appropriate variable identifiers:


Choosing appropriate variable names is a fundamental aspect
of programming that can significantly impact code readability
and maintainability. By following established naming
conventions and selecting descriptive identifiers, programmers
can enhance comprehension and facilitate error identification
within their programs.

-When choosing variable names, it is important to follow


conventions such as using letters, numbers, or underscores but
avoiding spaces and slashes. This helps maintain clarity and
readability in the code.
-Assign suitable and appropriate variable names that accurately
reflect the purpose or function of the variable in the program.
-Hungarian notation can be used to provide additional context
about the variable, rather than just indicating its type.

1
-Common conventions within programs can help provide extra
information about the function or role of specific variables,
making it easier to understand and troubleshoot code.

Making use of comments in code:


-Comments serve as valuable aids in documenting code logic
and providing context for developers working on a project. By
using comments effectively, programmers can communicate
essential information, explain complex algorithms, and adhere
to best practices for code documentation, thereby promoting
code clarity and easing the debugging process.

-They are used to embed annotations in the source code,


providing explanations or additional information to make the
code easier to understand.
-Comments help to clarify and document the code, making it
easier for other developers to work with or modify the code.
-Understanding language specifications, syntax, and
conventions is important when writing comments to ensure they
are clear and follow standard practices.
-Comments can be used for various purposes such as adding
information, generating external documents, or integrating with
programming tools.
-Block, prologue, and stream comments are used to provide
overall explanations or summaries of code sections.
-Line or inline comments are used to add specific comments on
individual lines or sections of code.
-Inline comments can also be used to generate documentation
or other information automatically.

2
Tracing the flow of execution:
-Understanding the flow of program execution is essential for
pinpointing errors and optimising code performance. By
employing techniques to trace the program's execution path,
programmers can identify potential issues, analyse program
behaviour, and enhance overall code efficiency.
-Identifying the stages of flow execution helps in understanding
how the program functions and where errors may occur.
-Using appropriate techniques to trace the flow of execution,
such as manually tracing the code, using debuggers, or
analysing output information.
-Keeping track of the trace can be done by using markers,
debuggers, or other methods to track the execution path of the
program.

Using debugging techniques:


-Effective debugging techniques are critical for identifying and
resolving bugs and errors in structured programs. By planning
testing strategies, utilising debugging tools, and focusing on
common error sources such as function calls, variable usage,
and syntax errors, programmers can optimise the debugging
process and create more robust software solutions.
-Planning to test a program involves identifying a method and
stages, for example using single-step or breakpoint methods to
track the program's execution you have to understand the
stages involved such as:
1.​ Identify the problem
2.​Establish a theory of probable cause
3.​Test the theory to determine the cause
4.​Establish a plan of action to resolve the problem and
implement the solution.
5.​Verify full system functionality and, if applicable,
implement preventive measures,

3
6.​Document findings, actions, and outcomes.

-Running the program with an appropriate technique or


software tool to identify and debug various types of bugs or
errors, such as calling wrong functions, using incorrect variable
names, uninitialized variables, calculation errors, off-by-one
errors, ambiguities, syntax, or semantic errors.

Error Type Example


Calling wrong Int result = subtraction(5,3);// calling subtraction function instead of addition.
functions

Using incorrect Int valu = 10; //using ‘valu’ instead of ‘value’


variable names

Uninitialised variables Int num1, num2; //not assigning values to num1 and num2 before using them.

Calculation errors Int total = num1*num2;//multiplying instead of adding.

Off-by-one errors for(int i =0; i<=5; i++)//this loop was intended to be i<5

Ambiguities Int x =5; int y = 10; int result = x + y *2; //unclear operator precedence.

Syntax errors Int number = 10 //missing semicolon at the end

Semantic errors int total = num1 * num2; //semantically incorrect operation for the context.

You might also like