Thursday, December 16, 2010

Program 12 - Program Test Data, Debugging and Termination: Program Test Data

For this project I will be discussing Program Test Data, and how it relates to the following languages: C++, C#, and Java.

To ensure that a program is as solid as possible, programmers must attempt to address any and all possible errors that can occur within their program. Some of these errors may produce incorrect results while others can crash a program entirely. To detect and correct bugs, programmers must use test data. Test data will be a range of input values ran through the program to determine if it creates the "typical" expected output. If it doesn't, then there is an error.

Limits Testing (also referenced as Range Testing) is a technique that is used to check the extreme conditions in which errors like to hide. These conditions are known as Boundary Conditions. To test the limits of a program, there must be input values that run at or near the boundaries of the value range. This usually begins with the lowest value of 0.

Data type testing is a technique that can be used to locate bugs within a program based on the ranges of different data types. When creating program test data, one thing a programmer can do is run the entire range of values for a data type. Depending on the data type, this may be done sparingly (especially if you consider how wide the range may be for some types.

In C++, the different data types have the following (unsigned) ranges:

Name

Size

Range

char

1byte

0 – 255

short int

2bytes

0 – 65535

int

4bytes

0 – 4294967295

long int

4bytes

0 – 4294967295

bool

1byte

True or False

float

4bytes

~7 digits

double

8bytes

~15 digits

long double

8bytes

~15 digits


 

Both Java and C# share a similar list of data types with C++.

By creating test data that covers as much of these ranges as possible, you will be able to find bugs that would otherwise go undetected until a user stumbles over one of them.

Logic Testing (also known as white-box testing) is testing method used to test the internal workings of an application. This is opposed to black-box testing, which focuses on functionality.

In logic testing, the programmer must develop a series of test cases. The programmer then selects inputs (with known outcomes) to test each path of code for logical accuracy. If the output produced from the test is correct, that path is working. If the output is incorrect, it means that there is faulty logic within that path or branch of code.

Logic testing is a valuable technique in finding many errors within the code. That is true, only if the inputs are vast enough to truly test every path.

Program 12 - Program Test Data, Debugging and Termination: Program Termination and Return Codes

For this project, I have chosen to compare JAVA, C++, AND C#. Within this section, I will be discussing Program Termination and Return Codes, in relation to the three programming languages.

Normal (program) Termination comes from completing the main function or by calling a function to exit the program.

Within C++, Normal Program Termination can be achieved by calling the function exit.

Exit ();

By calling this function, a value will be returned that will indicate whether or not the program terminated normally.

If the value returned on the exit function is 0, the program has been terminated normally. This will appear as:

Exit (0);

Normal termination in C++ based programs can also be achieved by completing the body of the program, or by executing a return function

Java expresses normal termination in almost the exact same way, give or take a few minor differences. The exit function can be explicitly called with:

System.exit()

Just like in C++, Normal Termination is indicated by a returned value of 0.

C# uses the same concept, but has a call function that differs from both Java and C++.

No matter what the naming convention may be for the call function, the rule behind the value is the same. If it returns a value of 0, the program has terminated correctly.

If the value is anything other than 0, it means that there was an abnormal program termination.

Return Codes are a way to indicate whether a process has completed successfully, or abnormally terminated due to an error. When defining values for a call function, it is a best practice to define the successful completion and normal termination of the process or program with the value of 0.

With this in mind, the programmer can then set other integer values (preferably on the lower scale) for errors that would represent abnormal program termination.

These values cannot simply be read as integers, as they would not be able to give an explanation of why the program abnormally terminated. Return Codes provide context to a return value. An example of this, using JAVA can be seen in the code below:

Prodedure Raise_On_Class

(Class : INTEGER) is

Begin

Case Class is

When 0 => null;

when 1 => raise Status_Error;

when 2 => raise Mode_Error;

when 3 => raise Name_Error;

when 4 => raise Use_Error;

when -1 => raise Date_Error;

when others => raise Unknown_Error;

end case;

end Raise_On_Class;


 

Since these errors will not appear during compilation, this will allow for them to appear within the code once the program is being run. The number of values can be quite vast; however, you may never grab every error. For this reason, it is not uncommon for there to be a "Catch all" value and Return Code. This way, these errors are not assumed as part of a successful termination, but rather an abnormal termination that is outside of the scope of what is already known.

Program 12 - Program Test Data, Debugging and Termination: Program Errors


 

For this project, I have decided to compare the three programming languages, Java, C++, C#.

Design errors are errors that usually occur due to bad logic within the program, or due to making a program too fragile. Bad Logic usually appears when running a program, as it will either complete the task with an incorrect output, or the program will crash. Fragility tends to be due to the programmer not taking the time to protect the program from user made errors, such as entering alphabetic characters where numeric characters should be entered. Programs that address this are considered Bulletproof (or fool proof).

Each programming language (Java, C++, and C#) uses the same option for debugging a program. These are called Debuggers. While one can attempt to locate all bugs themselves, debuggers go through each line of code and display errors that they come across. Some debuggers will even attempt to correct the error for you.

Syntax Compilation errors are errors in a program are human errors around wording. This means that they occur due to the use of the incorrect spelling, wrong idiom, structure, or function. This can also occur if invalid equations are entered into a calculator, such as multiple decimal (.) points within a single number (Ex. $100.00.0).

Syntax errors only occur during compile-time and will halt the compilation of a program.

When Java experiences a Syntax Error during compilation, the compilation will halt and an error message will be displayed.

  1. /**
  2. * This is the Hello World program that is part of Lesson 2.
  3. */

  4. import com.otherwise.jurtle.*;

  5. public class HelloWorld extends Turtle
  6. {

  7. public void runTurtle()
  8. {
  9. // Print the message to the console.
  10. Console.println("Hello world!")
  11. }

  12. }

In this example, the semicolon was left off of the Console.println command (on line 13). Because of this, the compiler displayed the following Syntax Error:

HelloWorld.Java:13: ';' expected

Console.println("Hello world")

This shows where the error occurred within the code, and what was expected.

C++ and C# both work very much in the same fashion as Java in regards to this.

A Semantic error is also known as a logic error. This is a bug that causes one's program to behave incorrectly and producing inaccurate outputs. These types of errors usually don't cause the program to crash. These can be hard to find as most logic based programs have multiple paths to test. Somewhere along these paths, there is usually an incorrect formula, an error in the algorithm, or an incorrect algorithm.

Semantic Run-Time Errors are thrown when running a program, so they will not appear when compiling the program.

In C++, C#, and Java, these are handled in the same way, as Run-Time Errors will throw an Exception.

An example in C# is:

intResult = 10 / intSomeOtherVariable;

If a user were to enter 0 as the value, it would cause an infinite loop (as 0 can go into another number an infinite amount of times).

When the exception is thrown, it will stop the execution of the program.

References:

Jurtle Lessons: (http://www.otherwise.com/Lessons/index.html).

http://www.informit.com/library/content.aspx?b=STY_Csharp_24hours&seqNum=156


 

Tuesday, December 14, 2010

Project 5 - Interpreters and compilers

It's important to find the right interpreter and/or the right compiler for the job. In order to accomplish this there are five important questions you must ask yourself. First, in what language will you be working? Second, in what platform will you be working? Third, how much time do you have? Fourth, what level of quality do you want? Fifth, how much you are willing to pay?

First things first, what are interpreters and compliers? Interpreters are a form of software that translates source code, more commonly as a language, into a file or program that can immediately be executed and evaluated. Compliers are a form of software that translates languages into binary code. Binary code is required to allow computer hardware to process or execute the language.

A language has particular set of rules one must follow in order for the code to properly function. BASIC, PASCAL, C and C++ are each a language with detailed rules.

In what language will you be working?

There is a multitude of compilers available for each programming language. Depending on the language in which you are programming, there are some compilers of which you may have heard before.

For example, some commonly referenced Basic compilers include Visual Basic and Quick Basic (not to be confused with QBasic), which are both developed by Microsoft. Liberty Basic is used within SAMS Teach Yourself Basic book, within the rather popular series of books.

In what platform will you be working?

Just like some languages, compilers come compatible with only certain operating systems (OSs). When searching for a compiler, it is important to reference whether they are designed in support of your intended operating system. This is especially important of compilers that you may purchase. There is nothing is worse than buying a round peg, only to realize you are dealing with a square hole.

How much time do you have?

Interpreters are not a bad option for quickly translating a file; however, the code tends to run much slower, as an interpreter must look at each line of code and then run it. This is to say that interpreters have their place. They are a great way to test code and debug it, rather than waiting for a compiler to compile the code and run it before being able to debug it.

Compilers will take more time to translate the code, but once done, you have a faster moving program.

How much you are willing to pay?

The great thing about the internet is that you can get almost anything for free, if you are willing to look for it. Why would anyone choose to pay for something that they can get for free? Well, when something is free, it tends not to be of the same quality of something for which one must pay.

A user can choose to purchase a proprietary compiler, but this usually means adhering to restrictions place on the compiler via a EULA (End User License Agreement). Often, this means that there are limits how the product can be used. The user can opt for open source compilers. These tend to be your free compilers, and do not have any real restrictions on how they are used. This is different than freeware. While freeware is free (as its name states), it can still have restrictions on how it is being used.

Side Note: If you wish to learn the difference between freeware and open source software, you can go to http://en.wikipedia.org/wiki/Open-source_software.

When it comes down to it, the option that best addresses those 5 questions should be the choice with which you proceed.

Sunday, December 12, 2010

Project 11 - Problems Solving Techniques: Solving Simple Problems Using Algorithms and a Program Design Language

Solving Simple Problems Using Algorithms and a Program Design Language

An algorithm is sequence of steps used to accomplish a task, such as solving a problem). The idea around algorithms is that a problem will be addressed based on a series of calculations or logic based tests. In their visual representation, known as Flow Charts, they are usually a series of "Yes or No" or "True or False" questions.

Algorithms are an especially handy tool for problem solving as they tend to map out all possible paths or answers to a solution; especially if there is not a single solution.

Since algorithms tend to be mathematical equations, they do not lend code to be easily read by human eyes. If at all possible, nobody would want to look through a bunch of if-else statements to determine how a program came to the output that was provided, nor would they want to constantly have to re-read the code as they are building the program to remember where they were and of what the next step in the sequence would consist. This is where Program Design Language comes into place. If you consider what a Flow Chart represents, you can determine that it, in essence is the Program Design Language's representation of the programming language.

As I mentioned earlier, a flow chart is nothing more than a display of the algorithm in an easily understood language (with the added bonus of pictures).

Solving Simple Problems Using Algorithms and a Program Design Language

Making things both visually and textually easier one to understand is always a plus.

With both the concepts of using algorithms in the form of flow charts is something that is very common to things such as technical support for things from dealing with lost cable connection to troubleshooting car issues. They can even be in ruling the cause of a rash.

In the aspect of technical support, this in combination with Program Design Language helps users to better support their own issues. I think the best example of this is pertaining to a specific error message that occurs when QuickBooks users attempt to access a data file across a network. If they receive an error message of H202, they have no idea what the program is trying to tell them, nor do they understand what is necessary to fix it.

To explain this in terms that a user could understand, a flow chart was created to help them address the exact cause of the issue, and therefore access a solution. This flowchart can be found here.

Side Note: What is quite interesting about that flow chart is that it was created by one of my peers, who then used this chart to create an algorithm that he then coded into a program. Now, this flow chart is a representation of what the "Network Diagnostic Tool" at the bottom of the article actually performs.

Project 11 - Problems Solving Techniques: Translating PDL – Program Design Language into QBASIC Code

Translating PDL – Program Design Language into QBASIC Code in programming

Program Design Language is not really a language at all. It is a method of working out the concept of a program in order to ensure that the program meets the expectation of the developer(s).

The basis of the Program Design Language is that it is fake code that most closely resembles English. The programming languages that best represent Human Language are considered Higher Languages. This is because they are easier to program without requiring much interpretation of the code.

While QBasic (or QuickBasic) is not the most commercially used language for programming, it is a great tool for learning programming, as it is a higher language than other languages. QBasic, however, is not a higher language than Program Design Language (as mentioned, it is basically Human Language). Of course, moving from Program Design Language to QBasic will be much simpler than trying to move to JAVA or even C++.

Why is PDL necessary?

Well, based on a well written article (with the novice in mind), Program Design Language is a great way of mapping out the code in an easily evaluated language. This means that the programmer of his boss can review the code quickly to ensure that what will be coded is, in fact, relevant and on par with the desired goal of the program.

To review my reference, you can go to: http://www.gamedev.net/reference/articles/article1384.asp

Translating PDL – Program Design Language into QBASIC Code Outside of Programming:

Okay. Let's be frank. Outside of programming, I will not be attempting to convert anything to QBasic, or any other programming language for that matter. This doesn't mean that the basic concept of program Design Language has no place in the outside world.

Again, I go back to technical support, because it is something to which I can relate.

One of the hard parts of technical support is explaining, or walking a customer through a process. Most of the time, it is not that the person is stubborn or isn't listening (while that does happen), but rather that they don't understand "Techy Speak".

Take for example the simple process of navigating a customer to the System Properties window or asking them to provide you the amount of Random Access Memory that with which their system is running.

First of all, I locate the System Properties window with the Shortcut keys: Win + Page Break.

I have tried to explain this to customers, and they tend to ask, "What (or where) is a Windows key?"

If on the other hand, I ask them to locate their Start button, within the Windows Task Bar, and right-click on the My Computer icon, they tend to get that far. From there I can explain that they will select Properties.

That is just navigating. I usually have to explain RAM. I can't just call it Random Access Memory and leave it at that. I have to put it in a language easy enough for them to understand. In essence, PDL is the equivalent of Laymen's terms.

If I provide the customer with instructions in these terms, they tend to be able to accomplish the task that I have requested.

Project 11 - Problems Solving Techniques: Elementary Program Design Structure Model

The Elementary Program Design Structure Model in programming:

The Elementary Program Design Structure Model consists of a 3 step process of which a program accomplishes its task(s). The Elementary Program Design Structure Model is an end to end process of:

  1. Setup
  2. Process
  3. Wrap Up

To understand the Elementary Design Structure Model is to understand each parts role within the process.

Setup

Setup is the initial one time process at the beginning of the program. This process declares the variables in Random Access Memory (RAM), as well as opening the necessary files with which the program will perform its function(s). Once this process is complete, the program moves to the next step…

Process

The Process is the step in which the program accomplishes its desired tasks. The process is the step in which the open files are read and (as it name states) processed or in which the other functions, with the contained fields, are performed. The process is often looped (repeated); each iteration progressing the program towards generating the desired outputs. Once this is completed, the program moves to the next step.

Wrap-Up

The Wrap-Up is the one time step that is ran to end the program. One can think of the clean-up section as the step at the end to program that returns (closes) the files and releases the Random Access Memory (RAM) that was used.

In the end, it is these steps, run back-to-back, that encompasses the makings of the program.

The Elementary Program Design Structure Model outside of programming:

Now, I tend to be wrong about many things, but much of what revolves around applying troubleshooting structures to real life is the interpretation of the information, and its application to life.

To explain how this problem solving technique applies to life, I will have to relate it to my very own job. Much of what I have attempted to portray in these blog posts applies to what I do on a daily basis; although it is not related to programming per se.

I have been working as a technical support specialist for over 5 years, for Intuit (the makers of QuickBooks, Quicken, and Turbo Tax). The overall purpose of my job is to solve problems that customers experience while working with our products.

One of the 2 most important aspects of our job is preparing our customers of what we are about to do, BEFORE we do it. We refer to this concept as setting customer expectations, and it is a crucial part of Setup. Along with "Setting Expectations", we also gather the information necessary to begin solving the problem

The actions performed within troubleshooting are our process portion. This is where we run tests, research options, and use logic to correct the issues.

The final step is the Wrap-Up. This may be the most important step of technical support, as this is all about cleaning up your footsteps. Whenever a technical support agent is working with a customer (whether it be over the phone or using a remote access tool), we must ensure that we leave the customer's system as we found it. Technically, we want to leave them better than when we found them, but we don't want to leave the tools we used to get them there sitting on their system taking up room.

This end to end process ensures that we have accomplished our interaction (program).