Page 93 - Introduction to Programming with Java: A Problem Solving Approach
P. 93

                /*
The following code displays the androids in a high-speed chase,
wreaking havoc on nearby vehicles.
*/
The compiler ignores everything between the first slash and the last slash.
Prologue
A prologue is a special example of a block comment. You should put a prologue at the top of every one of your programs. It provides information about the program so that a programmer can quickly glance at it and get an idea of what the program is all about. To make is stand out, it’s common to enclose the prologue in a box of asterisks. Here’s the Dream program’s prologue:
   t
lo
t
h
he
es
st
ta
ar
rt
to
of
ft
t
h
he
eb
b
l
oc
ck
kc
c
o
om
mm
****************************************
* Dream.java
*****************************************
Note that the opening /* and the closing */ blend in with the other asterisks. That’s OK. The compiler still recognizes the /* and */ as the start and end points of the block comment.
Include these items inAyopuraprgogroam’sPproDloFgue sEectnionh: ancer
• alineof*’s
• filename
• programmer’sname
• a line with a single * at its left
• program description
• alineof*’s
Readability and Blank Lines
We say that a program is readable if a programmer can easily understand what the program does. Comments are one way to improve a program’s readability. Another way to improve a program’s readability is to use blank lines. How are blank lines helpful? Isn’t it easier to understand several short, simple recipes rather than a single long, complicated recipe? Likewise, it’s easier to understand small chunks of code rather than one large chunk of code. Using blank lines allows you to split up large chunks of code into smaller chunks of code. In a prologue, we insert a blank line to separate the filename-author section from the de- scription section. Also, we insert a blank line below the prologue to separate it from the rest of the program.
By the way, computers don’t care about readability; they just care about whether a program works. More specifically, computers skip all comments, blank lines, and contiguous space characters. Since computers don’t care about readability, your computer would be perfectly happy to compile and execute this Dream program:
public class Dream{public static void
main(String[]args){System.out.println("I have a dream!");}}
But a person trying to read the program would probably be annoyed because of the program’s poor readability.
3.3 Comments and Readability 59
   * Dean & Dean
*
* This program prints "I have a dream."
me
en
n
t
t
 /**
   t
lo
t
h
he
ee
e
n
nd
d
o
o
f
f
t
t
h
he
eb
b
l
oc
ck
kc
c
o
om
mm
me
en
n
t
t
 */





   91   92   93   94   95