A mainline Algorithm is a collection of all of the other modules present in the project, and determines when they run and in what order, as well as any loops or other anomalies in the order of modules.
A subroutine is a set of instructions to perform a frequently used function within a program. These routines are separate from other modules and may be called on by these to perform the function, eliminating the need for repetitive code.
Because of the nature of Subroutines they must be concise and logical, with each containing a specific task that runs smoothly and completes its intended goal.
A good example of this is in collisions in a game, where throughout many other scripts there will be a ‘CALL’ line to run the collision script.
A stub is intended as a stand in for a module or subroutine of a program. The stub will not run the module’s original functionality but is used to test whether the code of the original module is dysfunctional, or to test other sections of code with no real consequences.
In this example, the stub is being used to test the ‘averageGrades’ code, where it is sourcing the average of the grades of a cohort, but is using a stub of the actual grades system to only test the ‘averageGrades’ mechanic.
Control Structures, their definitions, and examples:
In the process of coding, errors are bound to happen to a programmer whether it is during the process of debugging the code or writing the code. Some of the errors that would be detected in this process include Syntax Errors, Logic Errors & Run-time Errors.
Syntax errors occurs within the source code of the a program. This error happens when the language is misused and prevents the program from being debugged making it not comprehend to the given task. This error happens when something has been entered by the programmer that is invalid or unsolvable. Due to this, it can do nothing else but display a Syntax Error. This type of error is a human made error, not a mechanical one.
A common Syntax error that happens is when you are using a variable and it has not been properly declared yet. Variables need to be declared for it to be recognised and registered within the coding.
In this example, the variable Number is shown with an error as it hasn't been declared anywhere else in the coding.
Another example is where an operator such as an Integer, Boolean and String is misused such as incorrectly converting and Integer to a Boolean.
Logic Errors are a type of error that occurs within the source code while is it being executed. When this happens, the program will be producing incorrect behaviors and producing the incorrect outputs which leads to the application crashing even if the programming is valid, it will not behave as coded. The Logic error is the difficult to spot as the coding is written fine and therefore cannot disclose the problem to the programmer. The worst result for a logic error is the crashing of the computer.
It is harder for a programmer to detect as it will come up as a valid statement within the code but will have a different meaning.
An example of this would be the incorrect number of equal signs such as two equal signs refers to as "Is equal to", while one equal refers to "While".
Another example would be using the less then operator when it should be the greater then operator and visa versa.
Runtime errors take place whilst the program is being executed and are commonly referred to as 'bugs'. They occur as a result of the program understanding what you have coded, but then runs into issues whilst executing the program. Runtime errors can be fixed by stopping each running program and checking to see if the error re-appears. One type of runtime error is a memory leak which causes a program to take up more RAM space whilst a program is being run and are commonly a result of an infinite loop.
Error is a condition when the output information does not match the input. To avoid this, we use error-detecting codes which are additional data added to a given digital message. An example of error-detecting code is parity check.
Whenever a message is transmitted, it may get scrambled by noise or data and be corrupted.
It is the simplest technique for detecting and correcting errors. The MSB of an 8-bits word is used as the parity bit and the remaining 7 bits are used as data or message bits. This can be either even parity or odd parity.
Even parity means the number of 1's in the given word including the parity bit should be even (2,4,6,....).
Odd parity means the number of 1's in the given word including the parity bit should be odd (1,3,5,....).
If it is known that the parity of the transmitted signal is always going to be "even" and if the received signal has an odd parity, then the receiver can conclude that the received signal is not correct.
Arithmetic overflow is a condition that occurs when a calculation produces a result that is greater than a given storage location can store or represent. A carry occurs when the result of an addition or subtraction does not fit in the result. Therefore, carry flags are checked after such calculations. An overflow proper occurs when the result does not have the sign that one would predict e.g. a negative result when adding two positive numbers. Therefore, it is useful to check the overflow flag. An overflow can be handled by propagation or avoidance. Propagation is when the value is too large to be stored, therefore it is assigned a specific value to indicate overflow and is useful at the end of long calculations. Avoidance is carefully ordering operations and selecting correct data types
Computers are mathematical machines and divide by 0 is undefined in Boolean algebra. This can result in crashes or incorrect program output. This issue can occur if software is being run on a computer that has hardware incompatible with the software. To solve this problem make sure all software installed on the computer is up-to-date. If the divide error happens while in a program verify that all software patches and upgrades have been obtained and applied.
If a programmer writes past the boundaries of a variable, the computer will end up corrupting another memory location. On a system with protected memory spaces (UNIX, Windows 98/NT), this sort of statement will cause the system to terminate execution of the program. On other systems (Windows 3.1, the Mac), however, the system is not aware of what you are doing. You end up damaging the code or variables in another application. C and C++ do not perform any sort of range checking when you access an element of an array, it is essential to pay careful attention to array ranges and keep within the array's appropriate boundaries to avoid such errors.
Debugging output statements are temporary lines of code added to display the value of a variable. Displays variables at various stages in the code. It may also be used to state that a particular part of code has been reached. Outputs are used as part of a Stub (explained above). The programmer views raw data before it is processed which allows a programmer to localise and fix errors. Some examples are flags and stubs.
If the programmer wants to check a certain part of the code is working, they use flags so that a certain part of the code is debugged instead of the whole code. It usually acts as a boolean variable indicating a condition to be either true or false to control what is being executed/ debugged.This is done to detect errors in certain areas instead of trying to find the error within a large amount of code. Programmers use flags to point something out in another program.
Involves the checking of the code along with another programmer. Peer checking is useful as it allows for better ways to overcome obstacles and find solutions to problems. The end result is that both developers are fully aware of the code, how it works, and why it was done that way. Chances are the code is better than one developer working alone. It's less likely to contain bugs and hacks and things that cause maintenance problems later.
Test data is used to compare the actual result with the expected results. Use structured walk through, to step through the code and find where errors occur. Desk checking should be performed on sub and whole programs. Desk checking is the process of manually reviewing the source code of a program. It involves reading through the functions within the code and manually testing them, often with multiple input values.
Structured walkthrough are more formal than peer checks, no attempt is made to correct problems but instead get feedback. They evaluate the design at different levels and this saves time and money as defects are found and rectified very early in the development. This provides value-added comments from reviewers with different technical backgrounds and experience. It creates awareness about different development or maintenance methodologies which can provide a professional growth to participants.
Breakpoints otherwise known as a pause is detectable in the duration of debugging the written code. Breakpoints are known for the intentional stopping or pausing of the program. While the code is being executed all of the contents will be running and when the Breakpoint is reached, a temporary halt will occur in the program. These are used so that the program can be tested and examined in intervals or to test if a programmed stop will happen at the right time. An advantage for using a breakpoint is the shortened time for the overall debugging process in a large program.
Breakpoints can be set at any line of executable code. A C# example includes the setting of a breakpoint in the variable declaration, a for loop or code located inside the for loop. A breakpoint cannot be set in the namespace, class declarations or on the method signature. If a breakpoint is being set on Visual Studios, it will be indicated with a red dot on the very left side of the code, this is shown in this photo where there is a breakpoint inside a for loop.
During the time the program is running, the stored value within a variable can change. The contents of a variable can be changed so that the value stored can be printed and have the coding determine if it is being properly processed and accurate. An example for where this is useful is with the use of complex mathematical equations. So, if the used variables are encoded to be simple to work with, the calculation for the equation will then be carried out. By doing this, it makes the process simpler for finding bugs.
Program Traces is the viewing of the progression of the program in detail. In Visual Studio, it allows the programmer to put a log message onto the main output window and is only seen when the program is being debugged. A Program Trace is a specified string argument that can have an unlimited amount of variable arguments. Program traces are usually set for following the progress of the program, within a nested loop which is a loop inside another loop and finally other complicated sections in the program.
void TRACETest ()
{
TRACE(_T("Trace Testing"));
}
Here in the first example, we have a Tracetest void and a program trace being called where it says TRACE(_T( and then the string “Trace testing” with it closed with two brackets after.
In the second example for Tracetest2 there is a character class for Maths, English and history and the Integer set for the number of classes to equal 3. By having this, it will say “Hello! You have three classes today; History, English and Maths” in the log message as the coding shows the program trace caller.
void TRACETest2 ()
{
char Class[] = {"Maths", "English", "History"};
int NumberClasses = 3;
TRACE(_T("Hello! You have three classes today; History, English & Maths"));
}
Single line stepping is the tracing of variables where it enables the programmer to recognise the value of variables when they are changing throughout the process of execution. Single line stepping allows the programmer to view every single line to ensure that it is being executed correctly. The variables which have the variables stored in them can be traced as well as the flow of control throughout the program.
To have this done in Visual Studios, the debugger needs to be attached and then press F5 to begin debugging the program. While this is debugging, the next line of code will to be executed is highlighted in yellow.