Ch.10.3 Helpdesk: Understanding Software Programming
Fifth-generation languages (5GLs)
Fifth-generation languages (5GLs) are considered the most "natural" of languages. With 5GLs, problems are presented as a series of facts or constraints instead of as a specific algorithm. The system of facts can then be queried, or asked questions. PROLOG (PROgramming LOGic) is an example of a 5GL. A PROLOG program could be a list of family relationships and rules such as "Mike is Sally's brother. A brother and a sister have the same mother and father.". After a huge collection of facts and rules has been collected, a user could ask for a list of all Mike's cousins, for example. PROLOG would find the answers by repeatedly applying the principles of logic.
First-generation languages (1GLs)
First-generation languages (1GLs) are the actual machine languages of a CPU, the sequence of bits (1s and 0s) that the CPU understands. While the first computer programmers had to be experts at machine language, it is uncommon today for a programmer to program directly in machine language. However, no matter what programming language developers use, at some point it must be translated into machine language so that the computer can understand it.
Algorithm Tools
Flowcharts are one tool programmers use to document the decision points and flow of their algorithm. A flowchart provides a visual representation of the algorithm. Specific shapes indicate different actions in a flowchart. Diamonds indicate that a binary decision/branching action will be performed, and rectangles indicate a program instruction. A number of software packages are on the market, making it easy for programmers to create and modify flowcharts.
Fourth-generation languages (4GLs)
Fourth-generation languages (4GLs) make the commands that a programmer uses even closer to the language that we speak to each other. Many database query languages and report generators are 4GLs. Structured Query Language is a database programming language that is an example of a 4GL.
The Debugger
Most IDEs include a tool called a debugger that helps programmers locate runtime (or logical) errors. These errors are different from syntax errors in that they are errors in the program's logic and are caught only when the program executes. Runtime errors can happen in many different ways. For example, programmers may accidentally write code for a loop that loops one time too many or one time too few. The debugger allows programmers to run the program in slow motion. They can then isolate the exact place in which a runtime error occurs, correct the error, and recompile the program.
Formatting the Problem Statement
Most companies and instructors have their own format for documenting a problem statement. However, all problem statements include the same basic components. Here you see a sample problem statement for a program designed to calculate the total pay for someone working at a parking garage.
Once compilation is done, is the program finished?
No, programmers still need to test the code to see whether the program behaves as it should.
Debugging
Once a program compiles without syntax errors, it has met all of the syntax rules of the language. However, this doesn't mean that the program behaves in a logical way or that it appropriately addresses the task it was supposed to do. If programmers made errors in the algorithm or in how they translated the algorithm to code, problems will occur. The process of running the program over and over to find errors and to make sure the program behaves in the way it should is called debugging.
Testing
Once debugging has detected all of the runtime errors, users test the program. In internal testing, people within the software company make sure the program behaves as it should. Any problems are reported to the programming team, which makes revisions. The next round of testing is external testing, in which intended users test the software to determine whether it matches their needs.
Programming: Step 3: Coding
Once programmers create an algorithm, the next step in the programming process is to select a programming language and translate the algorithm into that language. Translating an algorithm into a programming language is the act of coding. Code is more friendly to humans than the binary code that the CPU speaks but is still very structured. By coding the algorithm, programmers must think in terms of the operations that a CPU can perform.
Step 2: The Algorithm
Once programmers understand exactly what the program must do and have created the final problem statement, they can begin developing a detailed an algorithm, a set of specific, sequential steps that describe in natural language exactly what the computer program must do to complete its task.
Documentation
Once testing is completed, the work of documentation still exists, including creating internal program documentation and user manuals. User training begins once the software is distributed. Often, users find problems in a program after its commercial release. These problems are addressed with software updates or service packs. Users can download these small software modules to repair errors in the program.
After programmers finish coding, what do they do next?
Once the algorithm has been coded into a programming language, the programmers have to run it through a compiler.
Creating the Problem Statement
Problem statements include the following items: 1. The data (input) that will be entered. This is the data users will have at the start of the job. 2. The information (output) that the program will produce. This is the information users require at the end of the job. 3. The exact method (processing) that converts these inputs to outputs. Programmers must determine how to transform the input into the correct output. 4. A description of what the program should do if the input data is nonsense. This part of the problem statement is referred to as error handling. 5. A testing plan that lists specific input numbers the program would typically expect the user to enter and the output values that a perfect program will return for those input values.
Step 1: The Problem Statement
Programming is the process of translating a task into a series of commands a computer will use to perform that task. Programming projects follow a number of stages from conception to final deployment, sometimes referred to as the program development life cycle (PDLC). The problem statement is the starting point of programming work. It is a clear description of what tasks the computer program must accomplish and how the program will execute these tasks and respond to unusual situations. Programmers develop problem statements so that they can better understand the goals of their programming efforts.
Pseudocode
Pseudocode is a text-based approach to documenting an algorithm. In pseudocode, words describe the actions that the algorithm will take. Pseudocode is organized like an outline, with differing levels of indentation to indicate the flow of actions within the program. There is no standard set of vocabulary for pseudocode. Programmers use a combination of common words in their natural language and special words they know are commands in programming language.
Second-generation languages (2GLs)
Second-generation languages (2GLs) are also known as assembly languages. They allow programmers to write programs using a set of short, English-like commands that speak directly to the CPU. Using a 2GL, a programmer can use a command like "ADD" to stand for addition or "Register 4" to stand for the fourth register (or storage area) on the CPU. Thus, the statement "ADD Register 4, 5" would instruct the CPU to add 5 to the fourth register on the CPU. In machine language, the programmer would need to know that the bit pattern 1110 0000 1100 1101 tells the CPU to add 5 to the fourth register. As you can see, it's clear why 2GLs are easier for programmers to work with.
Interpreter
Some programming languages use an interpreter instead of a compiler. An interpreter translates the source code line by line and executes each line as it is translated. After compilation, programmers have an executable program, the binary sequence that instructs the CPU to run the code.
Code Editing
The IDE includes tools that support programmers at every step of the coding process. Code editing is the step in which programmers type the code into the computer. IDEs include an editor, a tool that highlights keywords and points out typos. When the program has been keyed into the editor, the programmer clicks on a button in the IDE and the compilation process begins. A pop-up window shows the compilation progress and how many warnings and syntax errors the IDE has detected. A warning is a suggestion from the compiler that the code might not work correctly. Once the compilation is finished, the IDE presents all of the syntax errors in a list on the screen. The programmer can then click on any item to see an explanation of the error and quickly repair it.
What's the first step in programming?
The first step in programming is to define the problem statement.
Loop Features
There are three features in a loop: 1. A beginning point (or initial value). Here, the Total Pay for the week starts at an initial value of $0.00. 2. A set of actions that will be performed. Here, the algorithm computes the daily pay each time it passes through the loop. 3. A check to see whether the loop is completed (or a test condition). Here, the algorithm should run the loop exactly seven times.
Types of Decision Points: Binary Decisions
There are two main types of decisions that change the flow of an algorithm. One decision point that appears often in algorithms is like a "fork in the road" or a branch. Such decision points are called binary decisions because they can only be answered in one of only two ways: yes (true) or no (false). For example, in this algorithm, the answer to the question, "Is the number of hours worked <= 8 hours?" is a binary decision because the answer can only be yes or no. The result of the decision determines which of the paths the algorithm will follow.
Decision Points in an Algorithm
When programmers develop an algorithm they create a list of actions the program will take. For simple problems, this list is straightforward—the program completes this action first, this action second, this action third, and so on. More complex problems involve decision points, points at which the program must choose from different actions based on the value of its current inputs. As you see in this example, decision points force the program to travel down one branch of the algorithm or another.
Third-generation languages (3GLs)
With third-generation languages (3GLs), programmers are relieved of the burden of having to understand everything about the hardware of the computer to give it directions. 3GLs use symbols and commands to help programmers tell the computer what to do, making 3GLs easier to read and remember. In addition, 3GLs allow programmers to name storage locations with their own names so they are more meaningful to them. Most programming languages today are 3GLs, including BASIC, FORTRAN, COBOL, C/C++, and Java to name a few.
Tools to Make Coding and Compilation Easier
A number of tools make the writing and testing of software easier. Compiler products feature an integrated development environment (IDE), a developmental tool that helps programmers write, compile, and test their programs. Every language has its own specific IDE. Here you see the IDE for Microsoft Visual Studio using C++.
Categories of Programming Languages
A programming language is a kind of "code" for the set of instructions the CPU knows how to perform. Programming languages use special words and rules to enable programmers to control the CPU without having to know all of its hardware details. Programming languages are classified in several major groupings, sometimes referred to as generations. With each generation in language development, programmers have been relieved of more of the burden of keeping track of what the hardware requires. Programming is therefore becoming easier as languages become more closely matched to how humans think about problems.
Once debugging is done, can the created software program be released?
Actually, after debugging, the last step is to test and document the program.
Once I've defined my problem statement, can I start coding?
Actually, after defining the problem statement, the next step in a programming project is for programmers to translate the programs into an algorithm.
What happens after programmers create an algorithm?
After programmers create an algorithm, they select a programming language and translate the algorithm into that language.
What is an IDE?
An integrated development environment (IDE) is a development tool that helps programmers write, compile, and test their programs.
Loops
Another type of decision point is a repeating loop. In a loop, a question is asked. If the answer is yes, a set of actions is performed. The question is then asked again. As long as the answer is yes, the algorithm continues to loop, repeating the actions. If the answer to the question is no, the algorithm moves on to the first step that follows the loop, as shown here.
Compilation
Compilation is the process by which code is converted into machine language—the language the CPU can understand. A compiler is a program that can "read" the source code—the code programmers have written in the higher-level language—and translate it into machine language. Using a compiler, all of the lines of source code are translated into machine language before any lines are executed.
What are decision points?
Decision points are points at which the program must choose from different actions, based on the value of its current inputs.