Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Jackson structured programming
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Motivation for the method == At the time that JSP was developed, most programs were batch COBOL programs that processed sequential files stored on tape. A typical program read through its input file as a sequence of records, so that all programs had the same structure— a single main loop that processed all of the records in the file, one at a time. Jackson asserted that this program structure was almost always wrong, and encouraged programmers to look for more complex data structures. In Chapter 3 of ''Principles of Program Design''<ref name="PoPD"/> Jackson presents two versions of a program, one designed using JSP, the other using the traditional single-loop structure. Here is his example, translated from COBOL into Java. The purpose of these two programs is to recognize groups of repeated records (lines) in a sorted file, and to produce an output file listing each record and the number of times that it occurs in the file. Here is the traditional, single-loop version of the program. <syntaxhighlight lang="java"> String line; int count = 0; String firstLineOfGroup = null; // begin single main loop while ((line = in.readLine()) != null) { if (firstLineOfGroup == null || !line.equals(firstLineOfGroup)) { if (firstLineOfGroup != null) { System.out.println(firstLineOfGroup + " " + count); } count = 0; firstLineOfGroup = line; } count++; } if (firstLineOfGroup != null) { System.out.println(firstLineOfGroup + " " + count); } </syntaxhighlight> Here is a JSP-style version of the same program. Note that (unlike the traditional program) it has two loops, one nested inside the other. The outer loop processes groups of repeating records, while the inner loop processes the individual records in a group. <syntaxhighlight lang="java"> String line; int numberOfLinesInGroup; line = in.readLine(); // begin outer loop: process 1 group while (line != null) { numberOfLinesInGroup = 0; String firstLineOfGroup = line; // begin inner loop: process 1 record in the group while (line != null && line.equals(firstLineOfGroup)) { numberOfLinesInGroup++; line = in.readLine(); } System.out.println(firstLineOfGroup + " " + numberOfLinesInGroup); } </syntaxhighlight> Jackson criticises the traditional single-loop version for failing to process the structure of the input file (repeating groups of records containing repeating individual records) in a natural way. One sign of its unnatural design is that, in order to work properly, it is forced to include special code for handling the first and last record of the file.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Jackson structured programming
(section)
Add topic