Chapter 22. Designing Your Own Programs

Every program starts off with a problem. Typically the best problems for computers to solve involve something that humans find tedious, tiresome, or error-prone to do themselves. For example, people used to calculate formulas by hand. If they made one mistake, any formulas relying on the flawed data would calculate incorrect answers. To make calculating multiple formulas faster and more accurate, programmers invented the spreadsheet.

The invention of the spreadsheet provided a general-purpose tool that a wide variety of people could use, from business executives calculating financial results to engineers calculating scientific results. However, programs can also solve more specific types of problems.

A lottery-number prediction program might store all previously drawn numbers and calculate which numbers appear most often. Based on this information, the program could show only those numbers with the highest chance of getting picked, theoretically giving you a greater chance of winning the lottery.

Whether you want to create a general-purpose tool like a spreadsheet or a more specialized tool like a lottery number predictor, the goal of any program is always the same. Identify a problem, define how to solve this problem, and then write step-by-step instructions to create a program.

When creating a program, the most important work isn't the actual writing of commands in a specific programming language like Objective-C. Instead, the most important work involves identifying the problem to solve, identifying the best way to solve this problem in a way that's easiest for the user, and identifying how to turn this design into an actual working program.

Note

One major reason why programs fail is because the programmers never identified a clear problem to solve. If a program can't solve a problem, then there's no use for that program.

Identifying the Right Problem

The best person to identify the problem you need to solve is the person who will be using your program. If you identify a problem and rush out to write a program to solve that problem, you may later find out that you've solved a problem that isn't that important after all.

For example, suppose you wrote a program that stored data on a racehorse. Based on this horse's past six races and the racing history of all the other horses in the same race, your program might calculate which horse seems mostly likely to win.

However, what the user might really want is a program that uses the current odds to determine the type of bet with the highest probability of winning and returning the highest payoff possible. Betting on the winning horse might be pointless if the payoff is low. However, betting on a horse to come in second or third might pay far more if that horse had high odds.

Therefore, the real problem isn't picking the winning horse but in choosing the horse most likely to return the highest payoff, which may not always be the winning horse. The real goal is to make the most money with the highest probability of success. If you fail to identify the real problem your users want solved, you'll fail to meet the needs of your customers.

The key to identifying the real problem your program should solve is to simply ask the potential users of your program what they really need.

If you fail to ask the users what they need, chances are good that you'll create a program that solves the wrong problem. As a result, users won't find your program useful, nobody will want it, and you'll have wasted your time creating it.

Since users may not be clear on exactly what they want, always ask what's the most painful problem that annoys people the most and causes the most frustration and agony. Once you can identify this single, most pressing problem, the next step is deciding whether this problem can be solved with a program and, if so, how to solve this problem in a way that provides the most relief to the user.

What Programs Do Well

Every problem is also an opportunity, but not every problem can be solved with a computer program. If you own a bar and your problem is that underage people keep trying to sneak into your building, a computer program probably won't be as helpful as hiring extra doormen and bouncers to guard all the doors and check the IDs of everyone who wants to get in.

Any problem that involves a physical presence (like a security guard) is probably best left for real people. However, any problem that requires mental activities that need speed and accuracy are perfect problems for a computer program to solve.

For example, how do you calculate the best time to buy a particular stock during the hectic commotion of the stock market? For a human, trying to capture rapidly changing data and make sense of it means taking too long with a high risk of inaccuracy. For a computer, making sense of rapidly changing data and calculating a result is simple and easy.

The two keys of most programs are speed and accuracy. A program designed to navigate an airplane must be accurate and fast. Even the most accurate airplane computer is worthless if it can't calculate an alternate path around a mountain in time.

Computers excel at speed and accuracy, which makes them perfect for any tedious jobs that humans would rather not do. Before spreadsheets, people had to use adding machines to calculate long lists of figures. Before word processors, people had to use typewriters and physical blocks of letters to create text and print newspapers. Before databases, people had to use filing cabinets stuffed with drawers full of files that were nearly impossible to search quickly and accurately.

Once you've identified a mental problem solvable by a computer, the next step is to determine how to solve it as a computer program.

Designing the Program Structure

In the past, once programmers identified a problem, they would rush off and start writing a program to solve that problem, often without the feedback of the people who would use that program. The end result would be a lot of wasted effort creating a program that didn't quite do what anyone wanted.

To avoid this trap, it's best to design your program on paper because it's easier and less time-consuming to scribble something on a sheet of paper than it is to write a program on your computer, only to throw away all your work afterward because you did it wrong.

There is no one best way to design a program, but there are general principles for designing a program. One common way to design a program involves breaking it into three parts called model-view-controller.

  • The model portion does all the calculations that make your program create some useful result.

  • The view portion displays your user interface that accepts input from the user and displays information back to the user.

  • The controller portion acts as the bridge between the view and the model. The controller takes data from the user interface (the view) and sends it to the model to calculate a new result. The model returns its calculation to the controller, which passes the data back to the user interface (the view).

By dividing a program into a model, view, and controller, you can focus on different parts of your program at a time.

The Model

The model portion of your program typically includes one or more Objective-C class files that do all the necessary calculations so your program can solve a specific problem. The purpose of the model is to isolate the calculation portion of your program so it operates completely independently of the user interface. This gives you the flexibility to change the user interface without worrying about making any changes to the model portion of your program.

The Controller

The controller portion of your program consists of one or more Objective-C class files, which act as a middleman in between your model and your view portion of your program. The idea is to isolate your model portion of your program from the view portion of your program (the user interface). Whenever the model needs to interact with the user interface, it sends data or requests information through the controller.

The only way the model ever communicates with the view is through a controller. This lets you replace or modify the view at any time without worrying about its effect on the model. Likewise, this also lets you modify the model at any time without worrying about its effects on the view. Any time you make a change to either the model or the view, you just have to worry about making the appropriate changes to the controller.

Essentially, the controller keeps the model and the view separate so they act more like building blocks that can be easily swapped in and out of your program.

The View

The view portion of your program typically includes one or more .xib files that contain your user interface. In many cases, you can create a mock-up of your program's user interface and show this mock-up to potential users to get their feedback, as shown in Figure 22-1.

Designing a mock-up of a user interface can be as simple as drawing it on a piece of paper or on the computer.

Figure 22-1. Designing a mock-up of a user interface can be as simple as drawing it on a piece of paper or on the computer.

A mock-up of your program's user interface lets you create a rough draft of your program without expending any effort writing an actual program. Instead, you just draw pictures, show users what the program could look like, and get their feedback on what's missing, what should be rearranged, and what should be eliminated altogether.

After potential users have examined your user interface and determined what and how it should work, you can take the next step and create that actual user interface as a .xib file using Interface Builder, as shown in Figure 22-2.

Turning a rough draft of a user interface into an actual .xib file

Figure 22-2. Turning a rough draft of a user interface into an actual .xib file

Although your program at this point will showonly what your program might look like, it won't actually do anything. With a mock-up of your program, you can focus on the main features of your program and how they should work.

Remember, designing your user interface can be one of the hardest parts to creating your program because if your program works perfectly but nobody likes or can understand your program's user interface, nobody will want to use your program. Since there is no scientific measurement for what makes a good user interface, consider the following tips for creating your program's user interface.

Be Conventional

When designing a program, follow the basic conventions that users expect from a Mac program. That includes pull-down menus with familiar menu titles in the expected order (such as the File menu first followed by Edit, View, Window, and Help) along with windows and user interface elements that behave identically to other Mac programs.

Using the elements of a typical Mac user interface offers two huge benefits. First, users can immediately become familiar with the basic ways of controlling your program. As a result, they'll be more receptive to using it and will know how to find and choose commands to control your program.

Second, creating your user interface out of common Mac user interface elements also makes your job, as a programmer, much easier since Apple has already written the code needed to create common user interface elements such as windows and pull-down menus. All you have to do is connect these existing user interface elements to your program, and you can create a working program with little or no additional coding whatsoever.

Be Imitative

Look at some of your own favorite programs and ask yourself what makes them so useful. Chances are good that for each program you like, there are probably a handful of rival programs offering the same, or maybe even more, features, so what is it about the program you use that makes it stand out?

You might like the way the program looks on the screen because the information and commands you need are thoughtfully laid out. Maybe you like the way the program guides you from one task to another, making the transition effortlessly while showing you relationships between diverse information that you may never have spotted on your own. Perhaps you like the way a program provides power features for advanced users yet remains accessible to novices.

Whatever you find useful in other programs, see whether you can adapt those designs in your own program. By doing so, you can take the best features from multiple programs and use them to create a great program that other users will rave about.

Besides looking at other programs to imitate, look at physical, real-world objects that represent tools that users might already be familiar using. For example, the Stickies program on the Mac mimics those familiar sticky notes that people use to jot down notes and stick them on desks, monitors, and chairs to remind them of something. If you're creating a program that lets users jot down ideas and notes, modeling your program after physical sticky notes can make your program easier for users to understand and use, as shown in Figure 22-3.

The Stickies program mimics sticky notes that people use in an office.

Figure 22-3. The Stickies program mimics sticky notes that people use in an office.

By studying existing programs and real-world tools that your program may be mimicking, you may be able to discover the optimum appearance for displaying information and allowing input for your program.

Be Unusual

Closely adhering to conventional user interface designs like pull-down menus and resizable windows can make your program more comfortable and easier to use. However, take a moment to think how your program might need to behave in unconventional ways that actually might make your program easier and more intuitive to use.

For example, suppose your program displayed a 3D image of a piece of equipment such as a tractor or a missile. You could display pull-down menu commands that would let you rotate that image, you might display a horizontal and vertical slider that would let you rotate that image by dragging the mouse, or you could throw all conventional user interface ideas away and design your own user interface that lets the user directly manipulate the item by dragging the mouse or by tracking finger gestures on a trackpad.

By offering a specialized way of interacting with the 3D image, your program might not look and work like anything the user might have ever used before, but it could make your program more intuitive and simpler to use.

As a general rule, use standard user interface elements whenever possible, but don't be afraid to create custom interface elements. Creating such custom user interface elements will take time to design, write, and test, but the end result can be a user interface uniquely customized for your users and program.

Thinking in Objects

With object-oriented programming languages like Objective-C, you need to think of how to divide your program into objects. Ideally, each object should represent a distinct part of your program.

For example, if you were creating a program to create and manipulate outlines, each outline heading might be an object. If you were creating a video game, each displayed item, such as a character or an obstacle, could also be an object.

Don't worry about designing your program into objects perfectly at this point. Just identify the most likely parts of your program that can be represented by objects and then decide what type of properties and methods those objects might need.

An object representing an outline heading might need properties that define the text to display and its position in that outline on the screen. Such an outline heading object might also need a method for moving the heading and a second method for changing the formatting of the text.

An object representing a video game monster might need a property that represents its health and a method for moving and attacking another item on the screen.

The goal isn't to define every method and property for each object in your program, but to slowly flesh out the design of your program so you know how the different parts of your program might interact with each other.

There is no one best way to divide a program into objects. However, you should always strive to write as little code as possible to make your program easier to write. The easier a program is to write, the easier it will be to fix and modify, improving its reliability.

To achieve this goal, find the commonalities of the different parts of your program. For example, the common parts of a video game might be an object that represents a monster and an object that represents the player. Both the player and the monster need to move and fight, so it's natural to create a single class that contains a health property and a move method, as shown in Figure 22-4.

By identifying objects with common features, you can design a single class to represent those objects.

Figure 22-4. By identifying objects with common features, you can design a single class to represent those objects.

Searching for common features among objects means you can write less duplicate code. After you've identified the main types of objects in your program, you can go to the next step of actually writing Objective-C code to create your class files.

Picking a Data Structure

With a rough design of your program and a clear idea what problem your program needs to solve, another step to completing your program is deciding how your program will work. First you must consider what type of data your programwill accept and manipulate to create a useful result for the user.

The type of data your program needs to store and the way it manipulates that data can determine the type of data structure you use. Choose the right data structure, and your program can be easy to write. Choose the wrong data structure, and you could wind up writing a lot of extra (and unnecessary) code to make your program work.

For example, suppose you created a simple database program for storing names. One option might be to store each name as a separate variable. Unfortunately, you may not know how many possible names someone might want to store, so you would have to create a large number of variables to store a fixed number of possible names, or you could choose a more flexible data structure such as an array, which can grow as the user adds more data.

By choosing the right data structure, you can greatly simplify the way your program works by writing less code and creating a more reliable program in the process.

Creating an Algorithm

Besides choosing the best data structure for your program, you must also know how to solve a particular problem step-by-step. (If you don't know how to do this, then you need to find someone who does because if no one knows how to solve a particular problem, the computer will never know how to do it either.)

The step-by-step instructions you need to solve a problem are called an algorithm. Since there might be a million different ways to solve the same problem, your goal is to find an algorithm that starts with the data a user might input into your program and then manipulates that data to achieve a specific result.

First, identify the end result. Next, identify the data that your program will start with. Now your goal is to find all the missing steps in between.

The type of algorithm you create depends on the type of data structures your program uses, so part of your algorithm will need to know how to accept data from the user, how to store data in a data structure, and how to send a new calculated result back to the user again.

One way to create an algorithm is to pick typical data that your program might accept, determine the result your program would calculate from this initial data, and then write out the steps you would need to solve that problem using a pencil and paper.

For example, suppose you wanted to implement a simple encryption algorithm known as the Caesar Cipher. The basic idea behind this cipher is to shift one letter a fixed number of places. So if you shifted all letters to the right by three places, the letter D would actually represent the letter A, the letter E would represent the letter B, and so on. Shifting all letters three places to the right would create a coded message "EDG" that would represent the actual message "BAD."

To implement such a simple letter substitution algorithm, we could start by assigning each letter a number. The number 0 would represent the letter A, the number 1 would represent the letter B, and so on. This could easily be implemented by creating an array, storing each letter in that array, and using the array index to represent each letter where the letter A would appear in the first array element, which has an index of 0, the letter B would appear in the second array element, which has an index of 1, and so on, as shown in Figure 22-5.

The index position of an array can represent each stored letter.

Figure 22-5. The index position of an array can represent each stored letter.

To encrypt a message, you need to define how many letters to shift to the right, which can be any value ranging from 1 to 25. (Shifting 0 places or 26 places essentially means that each letter represents itself, which would obviously not hide the actual message.)

To encrypt a message, the program needs two pieces of data:

  • How many places to shift a letter to the right

  • Which letter to shift

To encrypt a letter, you can use this simple encryption formula:

Encryptionn (x) = (x + n) mod 26

With this formula, the variable x represents the letter to shift (where 0 represents the letter A, 1 represents the letter B, and so on), and n represents the number of places to shift.

Defining an Algorithm

When you know what problem you want to solve and how you can solve it, you should write out those steps to look for any flaws in your logic. Essentially the steps to solve the problem of encrypting a text string might look like this:

  1. Count the number of characters in a string, and store this string length in a variable.

  2. Identify how many places to shift to the right, and store this numeric value in the n variable.

  3. Strip away the first letter of the string, and save the remaining text in separate variables.

  4. Associate the stripped character with its associated number representation, such as 0 for the letter A, 1 for the letter B, and so on. Store this numeric value into a variable.

  5. Use the encryption formula to determine which letter to replace the current letter. So if the computer is encrypting the letter C, it would first store the value of 2 (representing the letter C). Next, it would store the number of places to shift in the n variable. If the value of n were equal to 4, the encryption formula would look like this:

    Encryption4 (2) = (2 + 4) mod 26
      = 6

    So, the encryption formula would replace the letter C with the letter represented by the number 6. Take this number and replace it with the letter associated with that number, such as replacing the number 6 with the letter G.

  6. Repeat steps 3–5 using the string length as a counting variable.

  7. Print out the final result:

Encoded text = GEX

Once you've created an algorithm, go through the steps manually to verify that they work. You may know how to solve a problem, but you may not have clearly stated all of the steps needed to solve that particular problem. By forcing yourself to follow the exact steps a computer would follow, you can see if you're missing a step or if a particular step isn't working right.

Ideally, have someone else go through the steps because that person won't have all the assumptions and knowledge about the algorithm beforehand, so they'll be more likely to follow your instructions literally, which is exactly how the computer will do it too.

Writing Pseudocode

When you're satisfied that your instructions are both accurate and complete, the next step is to translate your algorithm into a simplified programming language called pseudocode. The purpose of pseudocode is to write instructions like a programming language but without worrying about proper syntax or commands.

Examining the previous algorithm, you could break this down into pseudocode like this:

inputText = String to encrypt.
n = number of characters to shift
lengthString = length (inputText)
for I = 1 to lengthString)
        strippedText = first letter of inputText
        remainderText = remaining characters of inputText
        letterValue = numeric equivalent (strippedText)
        encryptedText = (letterValue + n) mod 26
        cipherText = letter equivalent (encryptedText)
        encodedText = encodedText + cipherText
Print encodedText.

The goal of translating your algorithm from a wordy description into shorter, more computer-like pseudocode is to gradually translate your algorithm from English to actual Objective-C code.

Writing Actual Code

When you've defined the steps to solving a problem using pseudocode, you can convert your defined steps and turn them into actual commands in any programming language. For Mac programming using Xcode, you'll be using Objective-C code. If you create a new Mac OS X Cocoa application, you can edit the AppDelegate.m file's applicationDidFinishLaunching method with the following Objective-C code:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    NSString *object1 = @"A";
    NSString *object2 = @"B";
    NSString *object3 = @"C";
    NSString *object4 = @"D";
    NSString *object5 = @"E";
    NSString *object6 = @"F";
    NSString *object7 = @"G";
NSString *object8 = @"H";
    NSString *object9 = @"I";
    NSString *object10 = @"J";
    NSString *object11 = @"K";
    NSString *object12 = @"L";
    NSString *object13 = @"M";
    NSString *object14 = @"N";
    NSString *object15 = @"O";
    NSString *object16 = @"P";
    NSString *object17 = @"Q";
    NSString *object18 = @"R";
    NSString *object19 = @"S";
    NSString *object20 = @"T";
    NSString *object21 = @"U";
    NSString *object22 = @"V";
    NSString *object23 = @"W";
    NSString *object24 = @"X";
    NSString *object25 = @"Y";
    NSString *object26 = @"Z";

    NSArray *letterArray;
    letterArray = [NSArray arrayWithObjects: object1, object2, object3, object4,
object5, object6, object7, object8, object9, object10, object11, object12, object13,
object14, object15, object16, object17, object18, object19, object20, object21,
object22, object23, object24, object25, object26, nil];

    NSString *inputText;
    inputText = @"CAT";
    int lengthString = [inputText length];

    NSMutableString *plainText; // = [[NSMutableString alloc] init];
    plainText = [NSMutableString stringWithString: inputText];

    NSMutableString *encodedText; // = [[NSMutableString alloc] init];
    encodedText = [NSMutableString stringWithString: @""];

    NSString *remainderText;
    NSString *strippedText;
    NSInteger letterValue;
    NSInteger encryptedText;
    NSString *cipherText;
    NSInteger n; //Shift
    n = 4;

    //Loop -- Strip away first character and leave remaining characters behind
    int i;
    for (i = 1; i <= lengthString; i++)
    {
        remainderText = [plainText substringFromIndex:1];
        strippedText = [plainText substringToIndex:1];

        NSLog (@"Stripped character = %@", strippedText);
        plainText = [NSMutableString stringWithString: remainderText];
        NSLog (@"Plaintext left = %@", plainText);

        letterValue = [letterArray indexOfObject: strippedText];
encryptedText = (letterValue + n) % 26;

        cipherText = [letterArray objectAtIndex: encryptedText];
        [encodedText appendString: cipherText];
        NSLog (@"Encoded text = %@", encodedText);
        NSLog (@"**********");
    }
    // End loop
}

This Objective-C code stores the letters of the alphabet into an array where the index position of each character represents its numeric value, so the letter A is located at index position 0, the letter B is located at index position 1, and so on.

This code also uses a fixed value for the input text (CAT) and the number of places to shift the characters (4). Ideally, you'll want to allow the user to input different values for the text and the number of places to shift. If you ran this code, the NSLog commands would print the following to show you how the program strips away each character of the input text and creates a new coded version of that text, converting the string CAT to GEX:

2010-12-12 16:08:33.418 Cipher[27523:a0f] Stripped character = C
2010-12-12 16:08:33.420 Cipher[27523:a0f] Plaintext left = AT
2010-12-12 16:08:33.421 Cipher[27523:a0f] Encoded text = G
2010-12-12 16:08:33.421 Cipher[27523:a0f] **********
2010-12-12 16:08:33.422 Cipher[27523:a0f] Stripped character = A
2010-12-12 16:08:33.423 Cipher[27523:a0f] Plaintext left = T
2010-12-12 16:08:33.424 Cipher[27523:a0f] Encoded text = GE
2010-12-12 16:08:33.424 Cipher[27523:a0f] **********
2010-12-12 16:08:33.425 Cipher[27523:a0f] Stripped character = T
2010-12-12 16:08:33.425 Cipher[27523:a0f] Plaintext left =
2010-12-12 16:08:33.426 Cipher[27523:a0f] Encoded text = GEX
2010-12-12 16:08:33.426 Cipher[27523:a0f] **********

Prototyping Your Program

For small projects, you can start creating a simple version of your program right away. However, for a large project, you may want to take one additional step and create a prototype of your program.

Just as architects often build miniature skyscrapers out of cardboard or plastic to help them visualize the final appearance of a project, so do computer programmers create a prototype of their program using a variety of tools. When you create a prototype of a program, your prototype simply shows what the program will look like and how it will behave, but your prototype isn't an actual program.

For example, you might create a rough design of your program using a presentation program like PowerPoint or Keynote where each slide represents a different part of your user interface. Clicking various commands or buttons displays a different slide, depending on how your program works.

Prototyping lets potential users see and use your program so they can provide feedback on the user interface, what features the program needs, and what features may need to be changed or eliminated altogether.

Other prototyping tools might include simple drawing and paint programs or web page–designing programs that let you create a series of web pages that represent different appearances of your working program. You could even create a prototype of your program by simply drawing pictures on different sheets of paper.

The goal of a prototype is to create the appearance and behavior of your program without forcing you to spend a lot of time creating that prototype so it doesn't matter how you create your prototype. This lets you freely modify and change the prototype until it behaves and looks exactly the way you want. After you've finalized the design of your program by creating a prototype, then you'll be ready to create your actual program.

Writing and Testing Your Program

You're not going to write your entire program in one try. Instead, you'll gradually create a program and add more features one by one until you finally create the program you initially envisioned. Think of creating a program like shaping a clay sculpture. You would never take a chunk of clay, throw it on a table, and expect it to be perfect right away. Instead, you'd take that lump of clay and gradually shape it into the form you want. You might add a little extra clay here, remove a chunk of clay there, and move clay to one spot and slap it on a different spot.

In the same way that you'd create a work of art by starting with a lump of clay and gradually shaping it into your final design, so will you gradually create your program a little bit at a time. Testing your program doesn't mean waiting until the whole thing is complete. Instead, testing means you create a little bit of your program, test to make sure that the little bit you added works as expected, and then add another little bit to your program and test how that newly added portion of your program works.

Each time you add a new portion to your program, you'll need to test that new portion to make sure it works correctly and then test how that new portion interacts with the rest of your program.

When writing your program, divide your program into specialized parts and reusable parts. A specialized part of your program might perform unique calculations, such as a stock market prediction program that uses an algorithm to analyze stock price data and calculate which stocks will likely rise in the near future.

A reusable part of your program might be the part of your program that retrieves data from the Internet, such as stock market data. Retrieving data from the Internet might be handy to use in another program, such as one that needs to retrieve updated weather reports from the Internet. By clearly dividing your program into specialized and reusable, general portions, you can gradually create a library of your general-purpose code so you can plug each bit into future programs, allowing you to create new programs quickly, easily, and reliably.

By building your program slowly and testing each newly added feature along the way, you can catch problems as they occur and fix them before you rush ahead and create the entire program and wind up spending all your time tracking down and fixing bugs in your software.

The first goal of your program is to get it to work. Once you've gotten one part of your program to work, you can see what needs to be fixed or modified. Maybe your program doesn't look the way you wanted, so you might need to change the user interface. Maybe the program runs too slowly. Then you might need to use a different data structure or create a better algorithm.

The more testing you can do, the better, so you can spot problems with your program before releasing it to your customers and users. (Fixing a bug-ridden program after you've sold or distributed it to people is rarely the quickest way to make others happy or look favorably at your programming abilities.)

When you've created a workable program with the majority of its features available, you might start testing your program with other people so they can give you feedback on what they like, what they didn't like, and what changes you should make. At this point, you can choose to make those changes (or ignore them if you have a good reason for doing so), and then after you modify your program, you can repeat the whole testing cycle all over again.

Repeat several times, and you'll gradually create a working program that you can give away or sell to others. The whole process of designing, creating, and testing a program can be frustrating, fun, tiresome, and challenging all at the same time.

The more programs you create, the more confident you'll get and the more experience you'll have to avoid problems and take shortcuts to simplify your program. Like any skill, designing, writing, and testing a program may seem hard and confusing at first, but after enough practice, you'll soon find that it's not as difficult as you might have initially thought.

Summary

The most important task of writing a program is identifying the most important problem to solve. Once you've identified an important problem, you need to determine if it's even possible for a computer program to solve it. If so, then you'll be ready to start designing your program.

Designing your program is more than just designing a pretty user interface. The design of your program includes its structure, the data structures you use, the way you divide it into multiple objects, and the algorithm you use to solve a particular problem. None of these structural designs of your program may be readily seen by the user, but if they're missing or faulty, the user will know it through a slow, unresponsive, flawed program that doesn't work correctly.

Writing your program should be the last task you tackle. Before you write even one line of code, it's best to plan ahead how your program will work, how it will solve a particular problem, and, more importantly, what problem your program will solve in the first place.

Your program's user interface is all that people will see of your program, so it's important to design one that's easy to understand and use. Most of the time, designing a user interface involves using common interface elements such as dialog boxes, buttons, pull-down menus, and windows. However, you may want to customize your program's user interface to mimic a feature found in another program or to mimic a physical object that your program mimics such as sticky notes or a notepad.

Once you know the type of data your program needs to accept and manipulate, you can choose the best data structure to hold that data. By choosing the correct data structure, you can simplify the way your program works.

Besides choosing the right data structure, you also need to define the algorithm that your program will use to solve a problem, step-by-step. There is no one perfect algorithm for any program, so you just need to worry about creating a simple algorithm that works.

After you've decided on the rough design of your program, you may need to create a simple prototype to give potential users a chance to see what your program can do and how it might look and behave. A prototype can be as simple as drawings on a piece of paper or as sophisticated as a simplified version of your program running on a computer.

Prototyping helps users determine whether your program might be useful and what changes (if any) you might need to make before actually writing your program. After examining your prototype and making any final changes to your design or user interface, you can start writing the actual code to make your program work.

When creating a program, do it a little at a time, and test each new feature as you go along. In general, the more you plan ahead, the less time you'll need to rewrite your code or redesign your user interface. Instead, you'll be able to go from a working prototype to a working program relatively quickly, and the final result will be a working program that you can sell or give away to others.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.110.145